summaryrefslogtreecommitdiff
path: root/deps/v8/src/wasm/wasm-objects.tq
blob: ea72ccb95e91de73f7d9d32fa0258f831122359a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

@useParentTypeChecker
type PodArrayOfWasmValueType extends ByteArray
    constexpr 'PodArray<wasm::ValueType>';
@useParentTypeChecker
type ManagedWasmNativeModule extends Foreign
    constexpr 'Managed<wasm::NativeModule>';

extern class WasmInstanceObject extends JSObject;

// Represents the context of a function that is defined through the JS or C
// APIs. Corresponds to the WasmInstanceObject passed to a Wasm function
// reference.
// TODO(manoskouk): If V8_ENABLE_SANDBOX, we cannot encode the isolate_root as
// a sandboxed pointer, because that would require having access to the isolate
// root in the first place.
extern class WasmApiFunctionRef extends HeapObject {
  native_context: NativeContext;
  callable: JSReceiver|Undefined;
  // Present when compiling JSFastApiCall wrappers, needed
  // to load memory start/size fields.
  instance: WasmInstanceObject|Undefined;
  suspend: Smi;  // Boolean.
}

// This is the representation that is used internally by wasm to represent
// function references.
extern class WasmInternalFunction extends HeapObject {
  // This is the "reference" value that must be passed along in the "instance"
  // register when calling the given function. It is either the target instance
  // (for wasm functions), or a WasmApiFunctionRef object (for functions defined
  // through the JS or C APIs).
  // For imported functions, this value equals the respective entry in
  // the module's imported_function_refs array.
  ref: WasmInstanceObject|WasmApiFunctionRef;
  // The external (JS) representation of this function reference.
  external: JSFunction|Undefined;
  // This field is used when the call target is null.
  code: Code;
  // The call target. Tagged with the kWasmInternalFunctionCallTargetTag
  call_target: ExternalPointer;
}

extern operator '.call_target_ptr' macro LoadWasmInternalFunctionCallTargetPtr(
    WasmInternalFunction): RawPtr;

extern class WasmFunctionData extends HeapObject {
  // The wasm-internal representation of this function object.
  internal: WasmInternalFunction;
  // Used for calling this function from JavaScript.
  wrapper_code: Code;
  // Encode the {promising} and {suspending} flags in a single smi.
  js_promise_flags: Smi;
}

extern class WasmExportedFunctionData extends WasmFunctionData {
  // This is the instance that exported the function (which in case of
  // imported and re-exported functions is different from the instance
  // where the function is defined -- for the latter see WasmFunctionData::ref).
  instance: WasmInstanceObject;
  function_index: Smi;
  wrapper_budget: Smi;
  // The next two fields are for fast calling from C++. The contract is
  // that they are lazily populated, and either all will be present or none.
  c_wrapper_code: Code;
  packed_args_size: Smi;
  canonical_type_index: Smi;
  sig: ExternalPointer;  // wasm::FunctionSig*
}

extern class WasmJSFunctionData extends WasmFunctionData {
  serialized_return_count: Smi;
  serialized_parameter_count: Smi;
  serialized_signature: PodArrayOfWasmValueType;
}

extern class WasmCapiFunctionData extends WasmFunctionData {
  embedder_data: Foreign;  // Managed<wasm::FuncData>
  serialized_signature: PodArrayOfWasmValueType;
}

extern class WasmResumeData extends HeapObject {
  suspender: WasmSuspenderObject;
  on_resume: Smi;  // See wasm::OnResume enum.
}

extern class WasmIndirectFunctionTable extends Struct {
  size: uint32;
  @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
  @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
  sig_ids: RawPtr;
  targets: RawPtr;
  managed_native_allocations: Foreign|Undefined;
  refs: FixedArray;
}

extern class WasmContinuationObject extends HeapObject {
  stack: Foreign;
  parent: WasmContinuationObject|Undefined;
  jmpbuf: ExternalPointer;  // Direct access to the stack's jump buffer.
}

extern class WasmSuspenderObject extends JSObject {
  continuation: WasmContinuationObject|Undefined;
  parent: WasmSuspenderObject|Undefined;
  resume: JSObject|Undefined;
  reject: JSObject|Undefined;
  state: Smi;  // 0: Inactive, 1: Active, 2: Suspended.
}

extern class WasmExceptionTag extends Struct {
  // Note that this index is only useful for debugging purposes and it is not
  // unique across modules. The GC however does not allow objects without at
  // least one field, hence this also serves as a padding field for now.
  index: Smi;
}

extern class WasmExceptionPackage extends JSObject;

extern class WasmModuleObject extends JSObject {
  managed_native_module: ManagedWasmNativeModule;
  script: Script;
}

extern class WasmTableObject extends JSObject {
  // The instance in which this WasmTableObject is defined.
  // This field is undefined if the global is defined outside any Wasm module,
  // i.e., through the JS API (WebAssembly.Table).
  // Because it might be undefined, we declare it as a HeapObject.
  instance: WasmInstanceObject|Undefined;
  // The entries array is at least as big as {current_length()}, but might be
  // bigger to make future growth more efficient.
  entries: FixedArray;
  current_length: Smi;
  maximum_length: Smi|HeapNumber|Undefined;
  dispatch_tables: FixedArray;
  raw_type: Smi;
}

extern class WasmMemoryObject extends JSObject {
  array_buffer: JSArrayBuffer;
  maximum_pages: Smi;
  is_memory64: Smi;  // Boolean
  instances: WeakArrayList|Undefined;
}

extern class WasmGlobalObject extends JSObject {
  // The instance in which this WasmGlobalObject is defined.
  // This field is undefined if the global is defined outside any Wasm module,
  // i.e., through the JS API (WebAssembly.Global).
  // Because it might be undefined, we declare it as a HeapObject.
  instance: WasmInstanceObject|Undefined;
  untagged_buffer: JSArrayBuffer|Undefined;
  tagged_buffer: FixedArray|Undefined;
  offset: Smi;
  raw_type: Smi;
  // TODO(7748): If we encode mutability in raw_type, turn this into a boolean
  // accessor.
  is_mutable: Smi;
}

extern class WasmTagObject extends JSObject {
  serialized_signature: PodArrayOfWasmValueType;
  tag: HeapObject;
  canonical_type_index: Smi;
}

type WasmExportedFunction extends JSFunction;

extern class AsmWasmData extends Struct {
  managed_native_module: ManagedWasmNativeModule;
  uses_bitset: HeapNumber;
}

extern class WasmTypeInfo extends HeapObject {
  // We must make sure that the StructType/ArrayType, which is allocated in
  // the WasmModule's "signature_zone", stays around as long as there are
  // HeapObjects referring to it. Short term, we simply keep a reference to
  // the instance, which in turn keeps the entire WasmModule alive.
  // TODO(jkummerow): Possible optimization: manage the "signature_zone"'s
  // lifetime separately by having WasmModule refer to it via std::shared_ptr,
  // and introduce a new link from here to just that zone using a Managed<...>.
  // Details: https://bit.ly/2UxD4hW
  native_type: ExternalPointer;
  type_index: uint32;
  @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
  @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
  instance: WasmInstanceObject;
  const supertypes_length: Smi;
  supertypes[supertypes_length]: Object;
}

extern operator '.native_type_ptr' macro LoadWasmTypeInfoNativeTypePtr(
    WasmTypeInfo): RawPtr;

// WasmObject corresponds to data ref types which are WasmStruct and WasmArray.
@abstract
extern class WasmObject extends JSReceiver {
}

@highestInstanceTypeWithinParentClassRange
extern class WasmStruct extends WasmObject {
}

@lowestInstanceTypeWithinParentClassRange
extern class WasmArray extends WasmObject {
  length: uint32;

  @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
  @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
}

class WasmStringViewIter extends HeapObject {
  string: String;
  offset: uint32;  // Index into string.

  @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
  @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
}

extern class WasmNull extends HeapObject {}

extern macro WasmNullConstant(): WasmNull;
const kWasmNull: WasmNull = WasmNullConstant();