1// Copyright 2021 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_DEBUG_DEBUG_WASM_OBJECTS_H_
10#define V8_DEBUG_DEBUG_WASM_OBJECTS_H_
11
12#include <memory>
13
14#include "src/objects/js-objects.h"
15
16// Has to be the last include (doesn't have include guards):
17#include "src/objects/object-macros.h"
18
19namespace v8 {
20namespace debug {
21class ScopeIterator;
22}  // namespace debug
23
24namespace internal {
25namespace wasm {
26class WasmValue;
27}  // namespace wasm
28
29#include "torque-generated/src/debug/debug-wasm-objects-tq.inc"
30
31class ArrayList;
32class WasmFrame;
33class WasmInstanceObject;
34class WasmModuleObject;
35class WasmTableObject;
36
37class WasmValueObject : public JSObject {
38 public:
39  DECL_CAST(WasmValueObject)
40
41  DECL_ACCESSORS(type, String)
42  DECL_ACCESSORS(value, Object)
43
44  // Dispatched behavior.
45  DECL_PRINTER(WasmValueObject)
46  DECL_VERIFIER(WasmValueObject)
47
48// Layout description.
49#define WASM_VALUE_FIELDS(V)   \
50  V(kTypeOffset, kTaggedSize)  \
51  V(kValueOffset, kTaggedSize) \
52  V(kSize, 0)
53  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, WASM_VALUE_FIELDS)
54#undef WASM_VALUE_FIELDS
55
56  // Indices of in-object properties.
57  static constexpr int kTypeIndex = 0;
58  static constexpr int kValueIndex = 1;
59
60  static Handle<WasmValueObject> New(Isolate* isolate, Handle<String> type,
61                                     Handle<Object> value);
62  static Handle<WasmValueObject> New(Isolate* isolate,
63                                     const wasm::WasmValue& value,
64                                     Handle<WasmModuleObject> module);
65
66  OBJECT_CONSTRUCTORS(WasmValueObject, JSObject);
67};
68
69Handle<JSObject> GetWasmDebugProxy(WasmFrame* frame);
70
71std::unique_ptr<debug::ScopeIterator> GetWasmScopeIterator(WasmFrame* frame);
72
73Handle<String> GetWasmFunctionDebugName(Isolate* isolate,
74                                        Handle<WasmInstanceObject> instance,
75                                        uint32_t func_index);
76
77Handle<ArrayList> AddWasmInstanceObjectInternalProperties(
78    Isolate* isolate, Handle<ArrayList> result,
79    Handle<WasmInstanceObject> instance);
80
81Handle<ArrayList> AddWasmModuleObjectInternalProperties(
82    Isolate* isolate, Handle<ArrayList> result,
83    Handle<WasmModuleObject> module_object);
84
85Handle<ArrayList> AddWasmTableObjectInternalProperties(
86    Isolate* isolate, Handle<ArrayList> result, Handle<WasmTableObject> table);
87
88}  // namespace internal
89}  // namespace v8
90
91#include "src/objects/object-macros-undef.h"
92
93#endif  // V8_DEBUG_DEBUG_WASM_OBJECTS_H_
94