// Copyright 2016 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. #if !V8_ENABLE_WEBASSEMBLY #error This header should only be included if WebAssembly is enabled. #endif // !V8_ENABLE_WEBASSEMBLY #ifndef V8_WASM_WASM_OBJECTS_H_ #define V8_WASM_WASM_OBJECTS_H_ #include #include "src/base/bit-field.h" #include "src/debug/interface-types.h" #include "src/objects/foreign.h" #include "src/objects/js-function.h" #include "src/objects/js-objects.h" #include "src/objects/objects-body-descriptors.h" #include "src/objects/objects.h" #include "src/objects/struct.h" #include "src/wasm/module-instantiate.h" #include "src/wasm/stacks.h" #include "src/wasm/struct-types.h" #include "src/wasm/value-type.h" // Has to be the last include (doesn't have include guards) #include "src/objects/object-macros.h" namespace v8 { namespace internal { namespace wasm { class InterpretedFrame; class NativeModule; class WasmCode; struct WasmFunction; struct WasmGlobal; struct WasmModule; struct WasmTag; class WasmValue; class WireBytesRef; } // namespace wasm class BreakPoint; class JSArrayBuffer; class SeqOneByteString; class StructBodyDescriptor; class WasmCapiFunction; class WasmExceptionTag; class WasmExportedFunction; class WasmExternalFunction; class WasmInstanceObject; class WasmJSFunction; class WasmModuleObject; enum class SharedFlag : uint8_t; template class Managed; #include "torque-generated/src/wasm/wasm-objects-tq.inc" #define DECL_OPTIONAL_ACCESSORS(name, type) \ DECL_GETTER(has_##name, bool) \ DECL_ACCESSORS(name, type) class V8_EXPORT_PRIVATE FunctionTargetAndRef { public: FunctionTargetAndRef(Handle target_instance, int target_func_index); Handle ref() { return ref_; } Address call_target() { return call_target_; } private: Handle ref_; Address call_target_; }; namespace wasm { enum Suspend : bool { kSuspend = true, kNoSuspend = false }; enum Promise : bool { kPromise = true, kNoPromise = false }; enum class OnResume : int { kContinue, kThrow }; } // namespace wasm // A helper for an entry for an imported function, indexed statically. // The underlying storage in the instance is used by generated code to // call imported functions at runtime. // Each entry is either: // - Wasm to JS, which has fields // - object = a WasmApiFunctionRef // - target = entrypoint to import wrapper code // - Wasm to Wasm, which has fields // - object = target instance // - target = entrypoint for the function class ImportedFunctionEntry { public: inline ImportedFunctionEntry(Handle, int index); // Initialize this entry as a Wasm to JS call. This accepts the isolate as a // parameter, since it must allocate a tuple. V8_EXPORT_PRIVATE void SetWasmToJs(Isolate*, Handle callable, const wasm::WasmCode* wasm_to_js_wrapper, wasm::Suspend suspend); // Initialize this entry as a Wasm to Wasm call. void SetWasmToWasm(WasmInstanceObject target_instance, Address call_target); JSReceiver callable(); Object maybe_callable(); Object object_ref(); Address target(); private: Handle const instance_; int const index_; }; enum InternalizeString : bool { kInternalize = true, kNoInternalize = false }; // Representation of a WebAssembly.Module JavaScript-level object. class WasmModuleObject : public TorqueGeneratedWasmModuleObject { public: inline wasm::NativeModule* native_module() const; inline const std::shared_ptr& shared_native_module() const; inline const wasm::WasmModule* module() const; // Dispatched behavior. DECL_PRINTER(WasmModuleObject) // Creates a new {WasmModuleObject} for an existing {NativeModule} that is // reference counted and might be shared between multiple Isolates. V8_EXPORT_PRIVATE static Handle New( Isolate* isolate, std::shared_ptr native_module, Handle