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#if !V8_ENABLE_WEBASSEMBLY
6#error This header should only be included if WebAssembly is enabled.
7#endif  // !V8_ENABLE_WEBASSEMBLY
8
9#ifndef V8_WASM_OBJECT_ACCESS_H_
10#define V8_WASM_OBJECT_ACCESS_H_
11
12#include "src/common/globals.h"
13#include "src/objects/fixed-array.h"
14#include "src/objects/js-function.h"
15#include "src/objects/js-objects.h"
16#include "src/objects/shared-function-info.h"
17
18namespace v8 {
19namespace internal {
20namespace wasm {
21
22class ObjectAccess : public AllStatic {
23 public:
24  // Convert an offset into an object to an offset into a tagged object.
25  static constexpr int ToTagged(int offset) { return offset - kHeapObjectTag; }
26
27  // Get the offset into a fixed array for a given {index}.
28  static constexpr int ElementOffsetInTaggedFixedArray(int index) {
29    return ToTagged(FixedArray::OffsetOfElementAt(index));
30  }
31
32  // Get the offset of the context stored in a {JSFunction} object.
33  static constexpr int ContextOffsetInTaggedJSFunction() {
34    return ToTagged(JSFunction::kContextOffset);
35  }
36
37  // Get the offset of the shared function info in a {JSFunction} object.
38  static constexpr int SharedFunctionInfoOffsetInTaggedJSFunction() {
39    return ToTagged(JSFunction::kSharedFunctionInfoOffset);
40  }
41
42  // Get the offset of the formal parameter count in a {SharedFunctionInfo}
43  // object.
44  static constexpr int FormalParameterCountOffsetInSharedFunctionInfo() {
45    return ToTagged(SharedFunctionInfo::kFormalParameterCountOffset);
46  }
47
48  // Get the offset of the flags in a {SharedFunctionInfo} object.
49  static constexpr int FlagsOffsetInSharedFunctionInfo() {
50    return ToTagged(SharedFunctionInfo::kFlagsOffset);
51  }
52};
53
54}  // namespace wasm
55}  // namespace internal
56}  // namespace v8
57
58#endif  // V8_WASM_OBJECT_ACCESS_H_
59