• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 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@useParentTypeChecker
6type PodArrayOfWasmValueType extends ByteArray
7    constexpr 'PodArray<wasm::ValueType>';
8@useParentTypeChecker
9type ManagedWasmNativeModule extends Foreign
10    constexpr 'Managed<wasm::NativeModule>';
11
12extern class WasmInstanceObject extends JSObject;
13
14// Represents the context of a function that is defined through the JS or C
15// APIs. Corresponds to the WasmInstanceObject passed to a Wasm function
16// reference.
17// TODO(manoskouk): If V8_SANDBOXED_EXTERNAL_POINTERS, we cannot encode the
18// isolate_root as a sandboxed pointer, because that would require having access
19// to the isolate root in the first place.
20extern class WasmApiFunctionRef extends HeapObject {
21  isolate_root: RawPtr;
22  native_context: NativeContext;
23  callable: JSReceiver|Undefined;
24  suspender: WasmSuspenderObject|Undefined;
25}
26
27// This is the representation that is used internally by wasm to represent
28// function references.
29// The {foreign_address} field inherited from {Foreign} points to the call
30// target.
31extern class WasmInternalFunction extends Foreign {
32  // This is the "reference" value that must be passed along in the "instance"
33  // register when calling the given function. It is either the target instance
34  // (for wasm functions), or a WasmApiFunctionRef object (for functions defined
35  // through the JS or C APIs).
36  // For imported functions, this value equals the respective entry in
37  // the module's imported_function_refs array.
38  ref: WasmInstanceObject|WasmApiFunctionRef;
39  // The external (JS) representation of this function reference.
40  external: JSFunction|Undefined;
41  // This field is used when the call target is null.
42  @if(V8_EXTERNAL_CODE_SPACE) code: CodeDataContainer;
43  @ifnot(V8_EXTERNAL_CODE_SPACE) code: Code;
44}
45
46extern class WasmFunctionData extends HeapObject {
47  // The wasm-internal representation of this function object.
48  internal: WasmInternalFunction;
49  // Used for calling this function from JavaScript.
50  @if(V8_EXTERNAL_CODE_SPACE) wrapper_code: CodeDataContainer;
51  @ifnot(V8_EXTERNAL_CODE_SPACE) wrapper_code: Code;
52}
53
54extern class WasmExportedFunctionData extends WasmFunctionData {
55  // This is the instance that exported the function (which in case of
56  // imported and re-exported functions is different from the instance
57  // where the function is defined -- for the latter see WasmFunctionData::ref).
58  instance: WasmInstanceObject;
59  function_index: Smi;
60  signature: Foreign;
61  wrapper_budget: Smi;
62  // The remaining fields are for fast calling from C++. The contract is
63  // that they are lazily populated, and either all will be present or none.
64  @if(V8_EXTERNAL_CODE_SPACE) c_wrapper_code: CodeDataContainer;
65  @ifnot(V8_EXTERNAL_CODE_SPACE) c_wrapper_code: Code;
66  packed_args_size: Smi;
67  // Functions returned by suspender.returnPromiseOnSuspend() have this field
68  // set to the host suspender object.
69  suspender: WasmSuspenderObject|Undefined;
70}
71
72extern class WasmJSFunctionData extends WasmFunctionData {
73  serialized_return_count: Smi;
74  serialized_parameter_count: Smi;
75  serialized_signature: PodArrayOfWasmValueType;
76}
77
78extern class WasmCapiFunctionData extends WasmFunctionData {
79  embedder_data: Foreign;  // Managed<wasm::FuncData>
80  serialized_signature: PodArrayOfWasmValueType;
81}
82
83extern class WasmOnFulfilledData extends HeapObject {
84  suspender: WasmSuspenderObject;
85}
86
87extern class WasmIndirectFunctionTable extends Struct {
88  size: uint32;
89  @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
90  @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
91  sig_ids: RawPtr;
92  targets: RawPtr;
93  managed_native_allocations: Foreign|Undefined;
94  refs: FixedArray;
95}
96
97extern class WasmContinuationObject extends Struct {
98  stack: Foreign;
99  jmpbuf: Foreign;  // Direct access to the stack's jump buffer.
100  parent: WasmContinuationObject|Undefined;
101}
102
103extern class WasmSuspenderObject extends JSObject {
104  continuation: WasmContinuationObject|Undefined;
105  parent: WasmSuspenderObject|Undefined;
106  resume: JSObject;
107  state: Smi;  // 0: Inactive, 1: Active, 2: Suspended.
108}
109
110extern class WasmExceptionTag extends Struct {
111  // Note that this index is only useful for debugging purposes and it is not
112  // unique across modules. The GC however does not allow objects without at
113  // least one field, hence this also serves as a padding field for now.
114  index: Smi;
115}
116
117extern class WasmModuleObject extends JSObject {
118  managed_native_module: ManagedWasmNativeModule;
119  export_wrappers: FixedArray;
120  script: Script;
121}
122
123extern class WasmTableObject extends JSObject {
124  // The instance in which this WasmTableObject is defined.
125  // This field is undefined if the global is defined outside any Wasm module,
126  // i.e., through the JS API (WebAssembly.Table).
127  // Because it might be undefined, we declare it as a HeapObject.
128  instance: WasmInstanceObject|Undefined;
129  // The entries array is at least as big as {current_length()}, but might be
130  // bigger to make future growth more efficient.
131  entries: FixedArray;
132  current_length: Smi;
133  maximum_length: Smi|HeapNumber|Undefined;
134  dispatch_tables: FixedArray;
135  raw_type: Smi;
136}
137
138extern class WasmMemoryObject extends JSObject {
139  array_buffer: JSArrayBuffer;
140  maximum_pages: Smi;
141  instances: WeakArrayList|Undefined;
142}
143
144extern class WasmGlobalObject extends JSObject {
145  // The instance in which this WasmGlobalObject is defined.
146  // This field is undefined if the global is defined outside any Wasm module,
147  // i.e., through the JS API (WebAssembly.Global).
148  // Because it might be undefined, we declare it as a HeapObject.
149  instance: WasmInstanceObject|Undefined;
150  untagged_buffer: JSArrayBuffer|Undefined;
151  tagged_buffer: FixedArray|Undefined;
152  offset: Smi;
153  raw_type: Smi;
154  // TODO(7748): If we encode mutability in raw_type, turn this into a boolean
155  // accessor.
156  is_mutable: Smi;
157}
158
159extern class WasmTagObject extends JSObject {
160  serialized_signature: PodArrayOfWasmValueType;
161  tag: HeapObject;
162}
163
164type WasmExportedFunction extends JSFunction;
165
166extern class AsmWasmData extends Struct {
167  managed_native_module: ManagedWasmNativeModule;
168  export_wrappers: FixedArray;
169  uses_bitset: HeapNumber;
170}
171
172extern class WasmTypeInfo extends Foreign {
173  supertypes: FixedArray;
174  subtypes: ArrayList;
175  // In bytes, used for struct allocation.
176  instance_size: Smi;
177  // We must make sure that the StructType/ArrayType, which is allocated in
178  // the WasmModule's "signature_zone", stays around as long as there are
179  // HeapObjects referring to it. Short term, we simply keep a reference to
180  // the instance, which in turn keeps the entire WasmModule alive.
181  // TODO(jkummerow): Possible optimization: manage the "signature_zone"'s
182  // lifetime separately by having WasmModule refer to it via std::shared_ptr,
183  // and introduce a new link from here to just that zone using a Managed<...>.
184  // Details: https://bit.ly/2UxD4hW
185  instance: WasmInstanceObject;
186}
187
188// WasmObject corresponds to data ref types which are WasmStruct and WasmArray.
189@abstract
190extern class WasmObject extends JSReceiver {
191}
192
193@highestInstanceTypeWithinParentClassRange
194extern class WasmStruct extends WasmObject {
195}
196
197@lowestInstanceTypeWithinParentClassRange
198extern class WasmArray extends WasmObject {
199  length: uint32;
200
201  @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
202  @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
203}
204