1 // Copyright 2018 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_WASM_OBJECT_ACCESS_H_ 6 #define V8_WASM_OBJECT_ACCESS_H_ 7 8 #include "src/common/globals.h" 9 #include "src/objects/fixed-array.h" 10 #include "src/objects/js-function.h" 11 #include "src/objects/js-objects.h" 12 #include "src/objects/shared-function-info.h" 13 14 namespace v8 { 15 namespace internal { 16 namespace wasm { 17 18 class ObjectAccess : public AllStatic { 19 public: 20 // Convert an offset into an object to an offset into a tagged object. ToTagged(int offset)21 static constexpr int ToTagged(int offset) { return offset - kHeapObjectTag; } 22 23 // Get the offset into a fixed array for a given {index}. ElementOffsetInTaggedFixedArray(int index)24 static constexpr int ElementOffsetInTaggedFixedArray(int index) { 25 return ToTagged(FixedArray::OffsetOfElementAt(index)); 26 } 27 28 // Get the offset of the context stored in a {JSFunction} object. ContextOffsetInTaggedJSFunction()29 static constexpr int ContextOffsetInTaggedJSFunction() { 30 return ToTagged(JSFunction::kContextOffset); 31 } 32 33 // Get the offset of the shared function info in a {JSFunction} object. SharedFunctionInfoOffsetInTaggedJSFunction()34 static constexpr int SharedFunctionInfoOffsetInTaggedJSFunction() { 35 return ToTagged(JSFunction::kSharedFunctionInfoOffset); 36 } 37 38 // Get the offset of the formal parameter count in a {SharedFunctionInfo} 39 // object. FormalParameterCountOffsetInSharedFunctionInfo()40 static constexpr int FormalParameterCountOffsetInSharedFunctionInfo() { 41 return ToTagged(SharedFunctionInfo::kFormalParameterCountOffset); 42 } 43 44 // Get the offset of the flags in a {SharedFunctionInfo} object. FlagsOffsetInSharedFunctionInfo()45 static constexpr int FlagsOffsetInSharedFunctionInfo() { 46 return ToTagged(SharedFunctionInfo::kFlagsOffset); 47 } 48 }; 49 50 } // namespace wasm 51 } // namespace internal 52 } // namespace v8 53 54 #endif // V8_WASM_OBJECT_ACCESS_H_ 55