| // 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 WasmTrustedInstanceData extends ExposedTrustedObject; | |
| extern class WasmInstanceObject extends JSObject { | |
| @if(V8_ENABLE_SANDBOX) trusted_data: | |
| IndirectPointer<WasmTrustedInstanceData>; | |
| @ifnot(V8_ENABLE_SANDBOX) trusted_data: WasmTrustedInstanceData; | |
| module_object: WasmModuleObject; | |
| shared_part: WasmInstanceObject; | |
| exports_object: 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. | |
| extern class WasmApiFunctionRef extends ExposedTrustedObject { | |
| native_context: NativeContext; | |
| callable: JSReceiver|Undefined; | |
| // Present when compiling JSFastApiCall wrappers, needed | |
| // to load memory start/size fields. | |
| instance: WasmInstanceObject|Undefined; | |
| suspend: Smi; // Boolean. | |
| wrapper_budget: Smi; | |
| call_origin: Smi|WasmFuncRef|Tuple2; | |
| // The signature is needed for the generic wasm-to-js wrapper. | |
| sig: PodArrayOfWasmValueType; | |
| // This field is used by the WasmToOnHeapWasmToJSTrampoline. | |
| @if(V8_ENABLE_SANDBOX) code: IndirectPointer<Code>; | |
| @ifnot(V8_ENABLE_SANDBOX) code: Code; | |
| } | |
| class WasmFastApiCallData extends HeapObject { | |
| signature: HeapObject; | |
| cached_map: Weak<Map>|Null; | |
| } | |
| // This is the representation that is used internally by wasm to represent | |
| // function references. | |
| extern class WasmInternalFunction extends ExposedTrustedObject { | |
| // 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 | |
| // data (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. | |
| // Torque code should use the '.ref' macro to access the value. | |
| protected_ref: ProtectedPointer<WasmTrustedInstanceData|WasmApiFunctionRef>; | |
| // The external (JS) representation of this function reference. | |
| external: JSFunction|Undefined; | |
| // The function index if ref is a WasmInstanceObject, -1 otherwise. | |
| function_index: Smi; | |
| // The call target, stored as raw pointer in this trusted object. | |
| call_target: RawPtr; | |
| } | |
| extern operator '.ref' macro LoadRefFromWasmInternalFunction( | |
| WasmInternalFunction): WasmTrustedInstanceData|WasmApiFunctionRef; | |
| // WasmFuncRef is the type of function references. They are stored on-heap and | |
| // link to a WasmInternalFunction which contains the actual information. | |
| extern class WasmFuncRef extends HeapObject { | |
| // Note: Torque code uses the '.internal' macro below to access the reference. | |
| @if(V8_ENABLE_SANDBOX) trusted_internal: | |
| IndirectPointer<WasmInternalFunction>; | |
| @ifnot(V8_ENABLE_SANDBOX) trusted_internal: WasmInternalFunction; | |
| } | |
| extern operator '.internal' macro LoadWasmInternalFunctionFromFuncRef( | |
| WasmFuncRef): WasmInternalFunction; | |
| extern class WasmFunctionData extends HeapObject { | |
| // Used for calling this function from JavaScript. | |
| @if(V8_ENABLE_SANDBOX) wrapper_code: IndirectPointer<Code>; | |
| @ifnot(V8_ENABLE_SANDBOX) wrapper_code: Code; | |
| // The function reference for this function object. This is used when | |
| // converting a JS function back to the wasm-side func ref, and for loading | |
| // the call target in js-to-wasm wrappers. | |
| // We could save one indirection there by storing either the | |
| // WasmInternalFunction or the call target (via CPT) directly here. | |
| func_ref: WasmFuncRef; | |
| // 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. | |
| packed_args_size: Smi; | |
| canonical_type_index: Smi; | |
| @if(V8_ENABLE_SANDBOX) c_wrapper_code: IndirectPointer<Code>; | |
| @ifnot(V8_ENABLE_SANDBOX) c_wrapper_code: Code; | |
| sig: ExternalPointer; // wasm::FunctionSig* | |
| } | |
| extern operator '.sig_ptr' macro LoadWasmExportedFunctionDataSigPtr( | |
| WasmExportedFunctionData): RawPtr; | |
| extern class WasmJSFunctionData extends WasmFunctionData { | |
| 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 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; | |
| promise: JSPromise; | |
| resume: JSObject|Undefined; | |
| reject: JSObject|Undefined; | |
| state: Smi; // 0: Inactive, 1: Active, 2: Suspended. | |
| // Number of Wasm-to-JS frames in this suspender's stack. | |
| // If the value is non-zero, this means that there are JS frames on the stack | |
| // and trying to suspend should trap. | |
| has_js_frames: Smi; // Boolean. | |
| } | |
| 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 WasmDispatchTable extends TrustedObject; | |
| extern class WasmTableObject extends JSObject { | |
| // The instance in which this WasmTableObject is defined. | |
| // This field is undefined if the table is defined outside any Wasm module, | |
| // i.e., through the JS API (WebAssembly.Table). | |
| instance: WasmInstanceObject|Undefined; | |
| // The entries array is at least as big as {current_length()}, but might be | |
| // bigger to make future growth more efficient. | |
| // Each element is either | |
| // - a WasmFuncRef (Wasm function added from Wasm), | |
| // - a WasmExportedFunction (exported Wasm function added from JS), | |
| // - a WasmJSFunction (WebAssembly.Function created from JS), or | |
| // - a Tuple2 (placeholder for lazy initialization), holding a | |
| // WasmInstanceObject and Smi for the function index. | |
| entries: FixedArray; | |
| current_length: Smi; | |
| maximum_length: Smi|HeapNumber|Undefined; | |
| // The uses field stores an array of <WasmInstanceObject, index> pairs so we | |
| // can update the instance's dispatch table when the table grows. | |
| uses: FixedArray; | |
| raw_type: Smi; | |
| } | |
| extern class WasmMemoryObject extends JSObject { | |
| array_buffer: JSArrayBuffer; | |
| maximum_pages: Smi; | |
| is_memory64: Smi; // Boolean | |
| instances: WeakArrayList; | |
| } | |
| 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(14034): 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; | |
| // Is undefined for WasmExternalFunctions referring to WasmJSFunctions. | |
| instance: WasmInstanceObject|Undefined; | |
| 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(); | |
| extern class WasmSuspendingObject extends JSObject { | |
| callable: JSReceiver; | |
| } |