// 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. #ifndef V8_WASM_WASM_OBJECTS_H_ #define V8_WASM_WASM_OBJECTS_H_ #include #include "src/base/bit-field.h" #include "src/base/bits.h" #include "src/codegen/signature.h" #include "src/debug/debug.h" #include "src/heap/heap.h" #include "src/objects/objects.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 { struct CompilationEnv; class InterpretedFrame; struct InterpretedFrameDeleter; class NativeModule; class SignatureMap; class WasmCode; struct WasmException; class WasmFeatures; struct WasmGlobal; class WasmInterpreter; struct WasmModule; class WasmValue; class WireBytesRef; } // namespace wasm class BreakPoint; class JSArrayBuffer; class SeqOneByteString; class WasmCapiFunction; class WasmDebugInfo; class WasmExceptionTag; class WasmExportedFunction; class WasmExternalFunction; class WasmInstanceObject; class WasmJSFunction; class WasmModuleObject; class WasmIndirectFunctionTable; enum class SharedFlag : uint8_t; template class Managed; #define DECL_OPTIONAL_ACCESSORS(name, type) \ DECL_GETTER(has_##name, bool) \ DECL_ACCESSORS(name, type) // A helper for an entry in an indirect function table (IFT). // The underlying storage in the instance is used by generated code to // call functions indirectly at runtime. // Each entry has the following fields: // - object = target instance, if a Wasm function, tuple if imported // - sig_id = signature id of function // - target = entrypoint to Wasm code or import wrapper code class IndirectFunctionTableEntry { public: inline IndirectFunctionTableEntry(Handle, int table_index, int entry_index); inline IndirectFunctionTableEntry(Handle table, int entry_index); void clear(); V8_EXPORT_PRIVATE void Set(int sig_id, Handle target_instance, int target_func_index); void Set(int sig_id, Address call_target, Object ref); Object object_ref() const; int sig_id() const; Address target() const; private: Handle const instance_; Handle const table_; int const index_; }; // 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 Tuple2 of the importing instance and the callable // - 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); // Initialize this entry as a WASM to WASM call. void SetWasmToWasm(WasmInstanceObject target_instance, Address call_target); WasmInstanceObject instance(); JSReceiver 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 JSObject { public: DECL_CAST(WasmModuleObject) DECL_ACCESSORS(managed_native_module, Managed) DECL_ACCESSORS(export_wrappers, FixedArray) DECL_ACCESSORS(script, Script) 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) DECL_VERIFIER(WasmModuleObject) DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, TORQUE_GENERATED_WASM_MODULE_OBJECT_FIELDS) // 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