11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved. Use of 21cb0ef41Sopenharmony_ci// this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#if !V8_ENABLE_WEBASSEMBLY 61cb0ef41Sopenharmony_ci#error This header should only be included if WebAssembly is enabled. 71cb0ef41Sopenharmony_ci#endif // !V8_ENABLE_WEBASSEMBLY 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci#ifndef V8_WASM_WASM_OBJECTS_H_ 101cb0ef41Sopenharmony_ci#define V8_WASM_WASM_OBJECTS_H_ 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci#include <memory> 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci#include "src/base/bit-field.h" 151cb0ef41Sopenharmony_ci#include "src/base/bits.h" 161cb0ef41Sopenharmony_ci#include "src/codegen/signature.h" 171cb0ef41Sopenharmony_ci#include "src/debug/debug.h" 181cb0ef41Sopenharmony_ci#include "src/heap/heap.h" 191cb0ef41Sopenharmony_ci#include "src/objects/js-function.h" 201cb0ef41Sopenharmony_ci#include "src/objects/js-objects.h" 211cb0ef41Sopenharmony_ci#include "src/objects/objects.h" 221cb0ef41Sopenharmony_ci#include "src/wasm/stacks.h" 231cb0ef41Sopenharmony_ci#include "src/wasm/struct-types.h" 241cb0ef41Sopenharmony_ci#include "src/wasm/value-type.h" 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards) 271cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h" 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cinamespace v8 { 301cb0ef41Sopenharmony_cinamespace internal { 311cb0ef41Sopenharmony_cinamespace wasm { 321cb0ef41Sopenharmony_ciclass InterpretedFrame; 331cb0ef41Sopenharmony_ciclass NativeModule; 341cb0ef41Sopenharmony_ciclass WasmCode; 351cb0ef41Sopenharmony_cistruct WasmFunction; 361cb0ef41Sopenharmony_cistruct WasmGlobal; 371cb0ef41Sopenharmony_cistruct WasmModule; 381cb0ef41Sopenharmony_cistruct WasmTag; 391cb0ef41Sopenharmony_ciclass WasmValue; 401cb0ef41Sopenharmony_ciclass WireBytesRef; 411cb0ef41Sopenharmony_ci} // namespace wasm 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciclass BreakPoint; 441cb0ef41Sopenharmony_ciclass JSArrayBuffer; 451cb0ef41Sopenharmony_ciclass SeqOneByteString; 461cb0ef41Sopenharmony_ciclass StructBodyDescriptor; 471cb0ef41Sopenharmony_ciclass WasmCapiFunction; 481cb0ef41Sopenharmony_ciclass WasmExceptionTag; 491cb0ef41Sopenharmony_ciclass WasmExportedFunction; 501cb0ef41Sopenharmony_ciclass WasmExternalFunction; 511cb0ef41Sopenharmony_ciclass WasmInstanceObject; 521cb0ef41Sopenharmony_ciclass WasmJSFunction; 531cb0ef41Sopenharmony_ciclass WasmModuleObject; 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_cienum class SharedFlag : uint8_t; 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_citemplate <class CppType> 581cb0ef41Sopenharmony_ciclass Managed; 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci#include "torque-generated/src/wasm/wasm-objects-tq.inc" 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci#define DECL_OPTIONAL_ACCESSORS(name, type) \ 631cb0ef41Sopenharmony_ci DECL_GETTER(has_##name, bool) \ 641cb0ef41Sopenharmony_ci DECL_ACCESSORS(name, type) 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE FunctionTargetAndRef { 671cb0ef41Sopenharmony_ci public: 681cb0ef41Sopenharmony_ci FunctionTargetAndRef(Handle<WasmInstanceObject> target_instance, 691cb0ef41Sopenharmony_ci int target_func_index); 701cb0ef41Sopenharmony_ci Handle<Object> ref() { return ref_; } 711cb0ef41Sopenharmony_ci Address call_target() { return call_target_; } 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci private: 741cb0ef41Sopenharmony_ci Handle<Object> ref_; 751cb0ef41Sopenharmony_ci Address call_target_; 761cb0ef41Sopenharmony_ci}; 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci// A helper for an entry for an imported function, indexed statically. 791cb0ef41Sopenharmony_ci// The underlying storage in the instance is used by generated code to 801cb0ef41Sopenharmony_ci// call imported functions at runtime. 811cb0ef41Sopenharmony_ci// Each entry is either: 821cb0ef41Sopenharmony_ci// - Wasm to JS, which has fields 831cb0ef41Sopenharmony_ci// - object = a WasmApiFunctionRef 841cb0ef41Sopenharmony_ci// - target = entrypoint to import wrapper code 851cb0ef41Sopenharmony_ci// - Wasm to Wasm, which has fields 861cb0ef41Sopenharmony_ci// - object = target instance 871cb0ef41Sopenharmony_ci// - target = entrypoint for the function 881cb0ef41Sopenharmony_ciclass ImportedFunctionEntry { 891cb0ef41Sopenharmony_ci public: 901cb0ef41Sopenharmony_ci inline ImportedFunctionEntry(Handle<WasmInstanceObject>, int index); 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci // Initialize this entry as a Wasm to JS call. This accepts the isolate as a 931cb0ef41Sopenharmony_ci // parameter, since it must allocate a tuple. 941cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE void SetWasmToJs(Isolate*, Handle<JSReceiver> callable, 951cb0ef41Sopenharmony_ci const wasm::WasmCode* wasm_to_js_wrapper, 961cb0ef41Sopenharmony_ci Handle<HeapObject> suspender); 971cb0ef41Sopenharmony_ci // Initialize this entry as a Wasm to Wasm call. 981cb0ef41Sopenharmony_ci void SetWasmToWasm(WasmInstanceObject target_instance, Address call_target); 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci JSReceiver callable(); 1011cb0ef41Sopenharmony_ci Object maybe_callable(); 1021cb0ef41Sopenharmony_ci Object object_ref(); 1031cb0ef41Sopenharmony_ci Address target(); 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ci private: 1061cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> const instance_; 1071cb0ef41Sopenharmony_ci int const index_; 1081cb0ef41Sopenharmony_ci}; 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_cienum InternalizeString : bool { kInternalize = true, kNoInternalize = false }; 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci// Representation of a WebAssembly.Module JavaScript-level object. 1131cb0ef41Sopenharmony_ciclass WasmModuleObject 1141cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmModuleObject<WasmModuleObject, JSObject> { 1151cb0ef41Sopenharmony_ci public: 1161cb0ef41Sopenharmony_ci inline wasm::NativeModule* native_module() const; 1171cb0ef41Sopenharmony_ci inline const std::shared_ptr<wasm::NativeModule>& shared_native_module() 1181cb0ef41Sopenharmony_ci const; 1191cb0ef41Sopenharmony_ci inline const wasm::WasmModule* module() const; 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci // Dispatched behavior. 1221cb0ef41Sopenharmony_ci DECL_PRINTER(WasmModuleObject) 1231cb0ef41Sopenharmony_ci 1241cb0ef41Sopenharmony_ci // Creates a new {WasmModuleObject} for an existing {NativeModule} that is 1251cb0ef41Sopenharmony_ci // reference counted and might be shared between multiple Isolates. 1261cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static Handle<WasmModuleObject> New( 1271cb0ef41Sopenharmony_ci Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module, 1281cb0ef41Sopenharmony_ci Handle<Script> script); 1291cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static Handle<WasmModuleObject> New( 1301cb0ef41Sopenharmony_ci Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module, 1311cb0ef41Sopenharmony_ci Handle<Script> script, Handle<FixedArray> export_wrappers); 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci // Check whether this module was generated from asm.js source. 1341cb0ef41Sopenharmony_ci inline bool is_asm_js(); 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ci // Get the module name, if set. Returns an empty handle otherwise. 1371cb0ef41Sopenharmony_ci static MaybeHandle<String> GetModuleNameOrNull(Isolate*, 1381cb0ef41Sopenharmony_ci Handle<WasmModuleObject>); 1391cb0ef41Sopenharmony_ci 1401cb0ef41Sopenharmony_ci // Get the function name of the function identified by the given index. 1411cb0ef41Sopenharmony_ci // Returns a null handle if the function is unnamed or the name is not a valid 1421cb0ef41Sopenharmony_ci // UTF-8 string. 1431cb0ef41Sopenharmony_ci static MaybeHandle<String> GetFunctionNameOrNull(Isolate*, 1441cb0ef41Sopenharmony_ci Handle<WasmModuleObject>, 1451cb0ef41Sopenharmony_ci uint32_t func_index); 1461cb0ef41Sopenharmony_ci 1471cb0ef41Sopenharmony_ci // Get the raw bytes of the function name of the function identified by the 1481cb0ef41Sopenharmony_ci // given index. 1491cb0ef41Sopenharmony_ci // Meant to be used for debugging or frame printing. 1501cb0ef41Sopenharmony_ci // Does not allocate, hence gc-safe. 1511cb0ef41Sopenharmony_ci base::Vector<const uint8_t> GetRawFunctionName(int func_index); 1521cb0ef41Sopenharmony_ci 1531cb0ef41Sopenharmony_ci // Extract a portion of the wire bytes as UTF-8 string, optionally 1541cb0ef41Sopenharmony_ci // internalized. (Prefer to internalize early if the string will be used for a 1551cb0ef41Sopenharmony_ci // property lookup anyway.) 1561cb0ef41Sopenharmony_ci static Handle<String> ExtractUtf8StringFromModuleBytes( 1571cb0ef41Sopenharmony_ci Isolate*, Handle<WasmModuleObject>, wasm::WireBytesRef, 1581cb0ef41Sopenharmony_ci InternalizeString); 1591cb0ef41Sopenharmony_ci static Handle<String> ExtractUtf8StringFromModuleBytes( 1601cb0ef41Sopenharmony_ci Isolate*, base::Vector<const uint8_t> wire_byte, wasm::WireBytesRef, 1611cb0ef41Sopenharmony_ci InternalizeString); 1621cb0ef41Sopenharmony_ci 1631cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmModuleObject) 1641cb0ef41Sopenharmony_ci}; 1651cb0ef41Sopenharmony_ci 1661cb0ef41Sopenharmony_ci// Representation of a WebAssembly.Table JavaScript-level object. 1671cb0ef41Sopenharmony_ciclass WasmTableObject 1681cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmTableObject<WasmTableObject, JSObject> { 1691cb0ef41Sopenharmony_ci public: 1701cb0ef41Sopenharmony_ci inline wasm::ValueType type(); 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static int Grow(Isolate* isolate, 1731cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, 1741cb0ef41Sopenharmony_ci uint32_t count, Handle<Object> init_value); 1751cb0ef41Sopenharmony_ci 1761cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static Handle<WasmTableObject> New( 1771cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmInstanceObject> instance, 1781cb0ef41Sopenharmony_ci wasm::ValueType type, uint32_t initial, bool has_maximum, 1791cb0ef41Sopenharmony_ci uint32_t maximum, Handle<FixedArray>* entries, 1801cb0ef41Sopenharmony_ci Handle<Object> initial_value); 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static void AddDispatchTable( 1831cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmTableObject> table, 1841cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> instance, int table_index); 1851cb0ef41Sopenharmony_ci 1861cb0ef41Sopenharmony_ci static bool IsInBounds(Isolate* isolate, Handle<WasmTableObject> table, 1871cb0ef41Sopenharmony_ci uint32_t entry_index); 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_ci static bool IsValidElement(Isolate* isolate, Handle<WasmTableObject> table, 1901cb0ef41Sopenharmony_ci Handle<Object> entry); 1911cb0ef41Sopenharmony_ci 1921cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static void Set(Isolate* isolate, 1931cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, 1941cb0ef41Sopenharmony_ci uint32_t index, Handle<Object> entry); 1951cb0ef41Sopenharmony_ci 1961cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static Handle<Object> Get(Isolate* isolate, 1971cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, 1981cb0ef41Sopenharmony_ci uint32_t index); 1991cb0ef41Sopenharmony_ci 2001cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static void Fill(Isolate* isolate, 2011cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, 2021cb0ef41Sopenharmony_ci uint32_t start, Handle<Object> entry, 2031cb0ef41Sopenharmony_ci uint32_t count); 2041cb0ef41Sopenharmony_ci 2051cb0ef41Sopenharmony_ci // TODO(wasm): Unify these three methods into one. 2061cb0ef41Sopenharmony_ci static void UpdateDispatchTables(Isolate* isolate, WasmTableObject table, 2071cb0ef41Sopenharmony_ci int entry_index, 2081cb0ef41Sopenharmony_ci const wasm::WasmFunction* func, 2091cb0ef41Sopenharmony_ci WasmInstanceObject target_instance); 2101cb0ef41Sopenharmony_ci static void UpdateDispatchTables(Isolate* isolate, 2111cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, 2121cb0ef41Sopenharmony_ci int entry_index, 2131cb0ef41Sopenharmony_ci Handle<WasmJSFunction> function); 2141cb0ef41Sopenharmony_ci static void UpdateDispatchTables(Isolate* isolate, 2151cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, 2161cb0ef41Sopenharmony_ci int entry_index, 2171cb0ef41Sopenharmony_ci Handle<WasmCapiFunction> capi_function); 2181cb0ef41Sopenharmony_ci 2191cb0ef41Sopenharmony_ci static void ClearDispatchTables(Isolate* isolate, 2201cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, int index); 2211cb0ef41Sopenharmony_ci 2221cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static void SetFunctionTablePlaceholder( 2231cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmTableObject> table, int entry_index, 2241cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> instance, int func_index); 2251cb0ef41Sopenharmony_ci 2261cb0ef41Sopenharmony_ci // This function reads the content of a function table entry and returns it 2271cb0ef41Sopenharmony_ci // through the out parameters {is_valid}, {is_null}, {instance}, 2281cb0ef41Sopenharmony_ci // {function_index}, and {maybe_js_function}. 2291cb0ef41Sopenharmony_ci static void GetFunctionTableEntry( 2301cb0ef41Sopenharmony_ci Isolate* isolate, const wasm::WasmModule* module, 2311cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, int entry_index, bool* is_valid, 2321cb0ef41Sopenharmony_ci bool* is_null, MaybeHandle<WasmInstanceObject>* instance, 2331cb0ef41Sopenharmony_ci int* function_index, MaybeHandle<WasmJSFunction>* maybe_js_function); 2341cb0ef41Sopenharmony_ci 2351cb0ef41Sopenharmony_ci private: 2361cb0ef41Sopenharmony_ci // {entry} is either {Null} or a {WasmInternalFunction}. 2371cb0ef41Sopenharmony_ci static void SetFunctionTableEntry(Isolate* isolate, 2381cb0ef41Sopenharmony_ci Handle<WasmTableObject> table, 2391cb0ef41Sopenharmony_ci Handle<FixedArray> entries, int entry_index, 2401cb0ef41Sopenharmony_ci Handle<Object> entry); 2411cb0ef41Sopenharmony_ci 2421cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmTableObject) 2431cb0ef41Sopenharmony_ci}; 2441cb0ef41Sopenharmony_ci 2451cb0ef41Sopenharmony_ci// Representation of a WebAssembly.Memory JavaScript-level object. 2461cb0ef41Sopenharmony_ciclass WasmMemoryObject 2471cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmMemoryObject<WasmMemoryObject, JSObject> { 2481cb0ef41Sopenharmony_ci public: 2491cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(instances, WeakArrayList) 2501cb0ef41Sopenharmony_ci 2511cb0ef41Sopenharmony_ci // Add an instance to the internal (weak) list. 2521cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static void AddInstance(Isolate* isolate, 2531cb0ef41Sopenharmony_ci Handle<WasmMemoryObject> memory, 2541cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> object); 2551cb0ef41Sopenharmony_ci inline bool has_maximum_pages(); 2561cb0ef41Sopenharmony_ci 2571cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static MaybeHandle<WasmMemoryObject> New( 2581cb0ef41Sopenharmony_ci Isolate* isolate, MaybeHandle<JSArrayBuffer> buffer, int maximum); 2591cb0ef41Sopenharmony_ci 2601cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static MaybeHandle<WasmMemoryObject> New(Isolate* isolate, 2611cb0ef41Sopenharmony_ci int initial, 2621cb0ef41Sopenharmony_ci int maximum, 2631cb0ef41Sopenharmony_ci SharedFlag shared); 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ci static constexpr int kNoMaximum = -1; 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ci void update_instances(Isolate* isolate, Handle<JSArrayBuffer> buffer); 2681cb0ef41Sopenharmony_ci 2691cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static int32_t Grow(Isolate*, Handle<WasmMemoryObject>, 2701cb0ef41Sopenharmony_ci uint32_t pages); 2711cb0ef41Sopenharmony_ci 2721cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmMemoryObject) 2731cb0ef41Sopenharmony_ci}; 2741cb0ef41Sopenharmony_ci 2751cb0ef41Sopenharmony_ci// Representation of a WebAssembly.Global JavaScript-level object. 2761cb0ef41Sopenharmony_ciclass WasmGlobalObject 2771cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmGlobalObject<WasmGlobalObject, JSObject> { 2781cb0ef41Sopenharmony_ci public: 2791cb0ef41Sopenharmony_ci DECL_ACCESSORS(untagged_buffer, JSArrayBuffer) 2801cb0ef41Sopenharmony_ci DECL_ACCESSORS(tagged_buffer, FixedArray) 2811cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(type, wasm::ValueType) 2821cb0ef41Sopenharmony_ci 2831cb0ef41Sopenharmony_ci // Dispatched behavior. 2841cb0ef41Sopenharmony_ci DECL_PRINTER(WasmGlobalObject) 2851cb0ef41Sopenharmony_ci 2861cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static MaybeHandle<WasmGlobalObject> New( 2871cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmInstanceObject> instance, 2881cb0ef41Sopenharmony_ci MaybeHandle<JSArrayBuffer> maybe_untagged_buffer, 2891cb0ef41Sopenharmony_ci MaybeHandle<FixedArray> maybe_tagged_buffer, wasm::ValueType type, 2901cb0ef41Sopenharmony_ci int32_t offset, bool is_mutable); 2911cb0ef41Sopenharmony_ci 2921cb0ef41Sopenharmony_ci inline int type_size() const; 2931cb0ef41Sopenharmony_ci 2941cb0ef41Sopenharmony_ci inline int32_t GetI32(); 2951cb0ef41Sopenharmony_ci inline int64_t GetI64(); 2961cb0ef41Sopenharmony_ci inline float GetF32(); 2971cb0ef41Sopenharmony_ci inline double GetF64(); 2981cb0ef41Sopenharmony_ci inline Handle<Object> GetRef(); 2991cb0ef41Sopenharmony_ci 3001cb0ef41Sopenharmony_ci inline void SetI32(int32_t value); 3011cb0ef41Sopenharmony_ci inline void SetI64(int64_t value); 3021cb0ef41Sopenharmony_ci inline void SetF32(float value); 3031cb0ef41Sopenharmony_ci inline void SetF64(double value); 3041cb0ef41Sopenharmony_ci inline void SetExternRef(Handle<Object> value); 3051cb0ef41Sopenharmony_ci inline bool SetFuncRef(Isolate* isolate, Handle<Object> value); 3061cb0ef41Sopenharmony_ci 3071cb0ef41Sopenharmony_ci private: 3081cb0ef41Sopenharmony_ci // This function returns the address of the global's data in the 3091cb0ef41Sopenharmony_ci // JSArrayBuffer. This buffer may be allocated on-heap, in which case it may 3101cb0ef41Sopenharmony_ci // not have a fixed address. 3111cb0ef41Sopenharmony_ci inline Address address() const; 3121cb0ef41Sopenharmony_ci 3131cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmGlobalObject) 3141cb0ef41Sopenharmony_ci}; 3151cb0ef41Sopenharmony_ci 3161cb0ef41Sopenharmony_ci// Representation of a WebAssembly.Instance JavaScript-level object. 3171cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE WasmInstanceObject : public JSObject { 3181cb0ef41Sopenharmony_ci public: 3191cb0ef41Sopenharmony_ci DECL_CAST(WasmInstanceObject) 3201cb0ef41Sopenharmony_ci 3211cb0ef41Sopenharmony_ci DECL_ACCESSORS(module_object, WasmModuleObject) 3221cb0ef41Sopenharmony_ci DECL_ACCESSORS(exports_object, JSObject) 3231cb0ef41Sopenharmony_ci DECL_ACCESSORS(native_context, Context) 3241cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject) 3251cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(untagged_globals_buffer, JSArrayBuffer) 3261cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(tagged_globals_buffer, FixedArray) 3271cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(imported_mutable_globals_buffers, FixedArray) 3281cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(tables, FixedArray) 3291cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(indirect_function_tables, FixedArray) 3301cb0ef41Sopenharmony_ci DECL_ACCESSORS(imported_function_refs, FixedArray) 3311cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(indirect_function_table_refs, FixedArray) 3321cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(managed_native_allocations, Foreign) 3331cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(tags_table, FixedArray) 3341cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(wasm_internal_functions, FixedArray) 3351cb0ef41Sopenharmony_ci DECL_ACCESSORS(managed_object_maps, FixedArray) 3361cb0ef41Sopenharmony_ci DECL_ACCESSORS(feedback_vectors, FixedArray) 3371cb0ef41Sopenharmony_ci DECL_SANDBOXED_POINTER_ACCESSORS(memory_start, byte*) 3381cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(memory_size, size_t) 3391cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(isolate_root, Address) 3401cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(stack_limit_address, Address) 3411cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(real_stack_limit_address, Address) 3421cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(new_allocation_limit_address, Address*) 3431cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(new_allocation_top_address, Address*) 3441cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(old_allocation_limit_address, Address*) 3451cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(old_allocation_top_address, Address*) 3461cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(imported_function_targets, Address*) 3471cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(globals_start, byte*) 3481cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(imported_mutable_globals, Address*) 3491cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(indirect_function_table_size, uint32_t) 3501cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(indirect_function_table_sig_ids, uint32_t*) 3511cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(indirect_function_table_targets, Address*) 3521cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(jump_table_start, Address) 3531cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(data_segment_starts, Address*) 3541cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(data_segment_sizes, uint32_t*) 3551cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(dropped_elem_segments, byte*) 3561cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(hook_on_function_call_address, Address) 3571cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(tiering_budget_array, uint32_t*) 3581cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(break_on_entry, uint8_t) 3591cb0ef41Sopenharmony_ci 3601cb0ef41Sopenharmony_ci // Clear uninitialized padding space. This ensures that the snapshot content 3611cb0ef41Sopenharmony_ci // is deterministic. Depending on the V8 build mode there could be no padding. 3621cb0ef41Sopenharmony_ci V8_INLINE void clear_padding(); 3631cb0ef41Sopenharmony_ci 3641cb0ef41Sopenharmony_ci // Dispatched behavior. 3651cb0ef41Sopenharmony_ci DECL_PRINTER(WasmInstanceObject) 3661cb0ef41Sopenharmony_ci DECL_VERIFIER(WasmInstanceObject) 3671cb0ef41Sopenharmony_ci 3681cb0ef41Sopenharmony_ci// Layout description. 3691cb0ef41Sopenharmony_ci#define WASM_INSTANCE_OBJECT_FIELDS(V) \ 3701cb0ef41Sopenharmony_ci /* Often-accessed fields go first to minimize generated code size. */ \ 3711cb0ef41Sopenharmony_ci /* Less than system pointer sized fields come first. */ \ 3721cb0ef41Sopenharmony_ci V(kImportedFunctionRefsOffset, kTaggedSize) \ 3731cb0ef41Sopenharmony_ci V(kIndirectFunctionTableRefsOffset, kTaggedSize) \ 3741cb0ef41Sopenharmony_ci V(kIndirectFunctionTableSizeOffset, kUInt32Size) \ 3751cb0ef41Sopenharmony_ci /* Optional padding to align system pointer size fields */ \ 3761cb0ef41Sopenharmony_ci V(kOptionalPaddingOffset, POINTER_SIZE_PADDING(kOptionalPaddingOffset)) \ 3771cb0ef41Sopenharmony_ci V(kMemoryStartOffset, kSystemPointerSize) \ 3781cb0ef41Sopenharmony_ci V(kMemorySizeOffset, kSizetSize) \ 3791cb0ef41Sopenharmony_ci V(kStackLimitAddressOffset, kSystemPointerSize) \ 3801cb0ef41Sopenharmony_ci V(kImportedFunctionTargetsOffset, kSystemPointerSize) \ 3811cb0ef41Sopenharmony_ci V(kIndirectFunctionTableTargetsOffset, kSystemPointerSize) \ 3821cb0ef41Sopenharmony_ci V(kIndirectFunctionTableSigIdsOffset, kSystemPointerSize) \ 3831cb0ef41Sopenharmony_ci V(kGlobalsStartOffset, kSystemPointerSize) \ 3841cb0ef41Sopenharmony_ci V(kImportedMutableGlobalsOffset, kSystemPointerSize) \ 3851cb0ef41Sopenharmony_ci V(kIsolateRootOffset, kSystemPointerSize) \ 3861cb0ef41Sopenharmony_ci V(kJumpTableStartOffset, kSystemPointerSize) \ 3871cb0ef41Sopenharmony_ci /* End of often-accessed fields. */ \ 3881cb0ef41Sopenharmony_ci /* Continue with system pointer size fields to maintain alignment. */ \ 3891cb0ef41Sopenharmony_ci V(kNewAllocationLimitAddressOffset, kSystemPointerSize) \ 3901cb0ef41Sopenharmony_ci V(kNewAllocationTopAddressOffset, kSystemPointerSize) \ 3911cb0ef41Sopenharmony_ci V(kOldAllocationLimitAddressOffset, kSystemPointerSize) \ 3921cb0ef41Sopenharmony_ci V(kOldAllocationTopAddressOffset, kSystemPointerSize) \ 3931cb0ef41Sopenharmony_ci V(kRealStackLimitAddressOffset, kSystemPointerSize) \ 3941cb0ef41Sopenharmony_ci V(kDataSegmentStartsOffset, kSystemPointerSize) \ 3951cb0ef41Sopenharmony_ci V(kDataSegmentSizesOffset, kSystemPointerSize) \ 3961cb0ef41Sopenharmony_ci V(kDroppedElemSegmentsOffset, kSystemPointerSize) \ 3971cb0ef41Sopenharmony_ci V(kHookOnFunctionCallAddressOffset, kSystemPointerSize) \ 3981cb0ef41Sopenharmony_ci V(kTieringBudgetArrayOffset, kSystemPointerSize) \ 3991cb0ef41Sopenharmony_ci /* Less than system pointer size aligned fields are below. */ \ 4001cb0ef41Sopenharmony_ci V(kModuleObjectOffset, kTaggedSize) \ 4011cb0ef41Sopenharmony_ci V(kExportsObjectOffset, kTaggedSize) \ 4021cb0ef41Sopenharmony_ci V(kNativeContextOffset, kTaggedSize) \ 4031cb0ef41Sopenharmony_ci V(kMemoryObjectOffset, kTaggedSize) \ 4041cb0ef41Sopenharmony_ci V(kUntaggedGlobalsBufferOffset, kTaggedSize) \ 4051cb0ef41Sopenharmony_ci V(kTaggedGlobalsBufferOffset, kTaggedSize) \ 4061cb0ef41Sopenharmony_ci V(kImportedMutableGlobalsBuffersOffset, kTaggedSize) \ 4071cb0ef41Sopenharmony_ci V(kTablesOffset, kTaggedSize) \ 4081cb0ef41Sopenharmony_ci V(kIndirectFunctionTablesOffset, kTaggedSize) \ 4091cb0ef41Sopenharmony_ci V(kManagedNativeAllocationsOffset, kTaggedSize) \ 4101cb0ef41Sopenharmony_ci V(kTagsTableOffset, kTaggedSize) \ 4111cb0ef41Sopenharmony_ci V(kWasmInternalFunctionsOffset, kTaggedSize) \ 4121cb0ef41Sopenharmony_ci V(kManagedObjectMapsOffset, kTaggedSize) \ 4131cb0ef41Sopenharmony_ci V(kFeedbackVectorsOffset, kTaggedSize) \ 4141cb0ef41Sopenharmony_ci V(kBreakOnEntryOffset, kUInt8Size) \ 4151cb0ef41Sopenharmony_ci /* More padding to make the header pointer-size aligned */ \ 4161cb0ef41Sopenharmony_ci V(kHeaderPaddingOffset, POINTER_SIZE_PADDING(kHeaderPaddingOffset)) \ 4171cb0ef41Sopenharmony_ci V(kHeaderSize, 0) 4181cb0ef41Sopenharmony_ci 4191cb0ef41Sopenharmony_ci DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, 4201cb0ef41Sopenharmony_ci WASM_INSTANCE_OBJECT_FIELDS) 4211cb0ef41Sopenharmony_ci STATIC_ASSERT(IsAligned(kHeaderSize, kTaggedSize)); 4221cb0ef41Sopenharmony_ci // TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size 4231cb0ef41Sopenharmony_ci // fields (external pointers, doubles and BigInt data) are only kTaggedSize 4241cb0ef41Sopenharmony_ci // aligned so checking for alignments of fields bigger than kTaggedSize 4251cb0ef41Sopenharmony_ci // doesn't make sense until v8:8875 is fixed. 4261cb0ef41Sopenharmony_ci#define ASSERT_FIELD_ALIGNED(offset, size) \ 4271cb0ef41Sopenharmony_ci STATIC_ASSERT(size == 0 || IsAligned(offset, size) || \ 4281cb0ef41Sopenharmony_ci (COMPRESS_POINTERS_BOOL && (size == kSystemPointerSize) && \ 4291cb0ef41Sopenharmony_ci IsAligned(offset, kTaggedSize))); 4301cb0ef41Sopenharmony_ci WASM_INSTANCE_OBJECT_FIELDS(ASSERT_FIELD_ALIGNED) 4311cb0ef41Sopenharmony_ci#undef ASSERT_FIELD_ALIGNED 4321cb0ef41Sopenharmony_ci#undef WASM_INSTANCE_OBJECT_FIELDS 4331cb0ef41Sopenharmony_ci 4341cb0ef41Sopenharmony_ci static constexpr uint16_t kTaggedFieldOffsets[] = { 4351cb0ef41Sopenharmony_ci kImportedFunctionRefsOffset, 4361cb0ef41Sopenharmony_ci kIndirectFunctionTableRefsOffset, 4371cb0ef41Sopenharmony_ci kModuleObjectOffset, 4381cb0ef41Sopenharmony_ci kExportsObjectOffset, 4391cb0ef41Sopenharmony_ci kNativeContextOffset, 4401cb0ef41Sopenharmony_ci kMemoryObjectOffset, 4411cb0ef41Sopenharmony_ci kUntaggedGlobalsBufferOffset, 4421cb0ef41Sopenharmony_ci kTaggedGlobalsBufferOffset, 4431cb0ef41Sopenharmony_ci kImportedMutableGlobalsBuffersOffset, 4441cb0ef41Sopenharmony_ci kTablesOffset, 4451cb0ef41Sopenharmony_ci kIndirectFunctionTablesOffset, 4461cb0ef41Sopenharmony_ci kManagedNativeAllocationsOffset, 4471cb0ef41Sopenharmony_ci kTagsTableOffset, 4481cb0ef41Sopenharmony_ci kWasmInternalFunctionsOffset, 4491cb0ef41Sopenharmony_ci kManagedObjectMapsOffset, 4501cb0ef41Sopenharmony_ci kFeedbackVectorsOffset}; 4511cb0ef41Sopenharmony_ci 4521cb0ef41Sopenharmony_ci const wasm::WasmModule* module(); 4531cb0ef41Sopenharmony_ci 4541cb0ef41Sopenharmony_ci static bool EnsureIndirectFunctionTableWithMinimumSize( 4551cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> instance, int table_index, 4561cb0ef41Sopenharmony_ci uint32_t minimum_size); 4571cb0ef41Sopenharmony_ci 4581cb0ef41Sopenharmony_ci void SetRawMemory(byte* mem_start, size_t mem_size); 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ci static Handle<WasmInstanceObject> New(Isolate*, Handle<WasmModuleObject>); 4611cb0ef41Sopenharmony_ci 4621cb0ef41Sopenharmony_ci Address GetCallTarget(uint32_t func_index); 4631cb0ef41Sopenharmony_ci 4641cb0ef41Sopenharmony_ci Handle<WasmIndirectFunctionTable> GetIndirectFunctionTable( 4651cb0ef41Sopenharmony_ci Isolate*, uint32_t table_index); 4661cb0ef41Sopenharmony_ci 4671cb0ef41Sopenharmony_ci void SetIndirectFunctionTableShortcuts(Isolate* isolate); 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_ci // Copies table entries. Returns {false} if the ranges are out-of-bounds. 4701cb0ef41Sopenharmony_ci static bool CopyTableEntries(Isolate* isolate, 4711cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> instance, 4721cb0ef41Sopenharmony_ci uint32_t table_dst_index, 4731cb0ef41Sopenharmony_ci uint32_t table_src_index, uint32_t dst, 4741cb0ef41Sopenharmony_ci uint32_t src, 4751cb0ef41Sopenharmony_ci uint32_t count) V8_WARN_UNUSED_RESULT; 4761cb0ef41Sopenharmony_ci 4771cb0ef41Sopenharmony_ci // Copy table entries from an element segment. Returns {false} if the ranges 4781cb0ef41Sopenharmony_ci // are out-of-bounds. 4791cb0ef41Sopenharmony_ci static bool InitTableEntries(Isolate* isolate, 4801cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> instance, 4811cb0ef41Sopenharmony_ci uint32_t table_index, uint32_t segment_index, 4821cb0ef41Sopenharmony_ci uint32_t dst, uint32_t src, 4831cb0ef41Sopenharmony_ci uint32_t count) V8_WARN_UNUSED_RESULT; 4841cb0ef41Sopenharmony_ci 4851cb0ef41Sopenharmony_ci // Iterates all fields in the object except the untagged fields. 4861cb0ef41Sopenharmony_ci class BodyDescriptor; 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_ci static MaybeHandle<WasmInternalFunction> GetWasmInternalFunction( 4891cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmInstanceObject> instance, int index); 4901cb0ef41Sopenharmony_ci 4911cb0ef41Sopenharmony_ci // Acquires the {WasmInternalFunction} for a given {function_index} from the 4921cb0ef41Sopenharmony_ci // cache of the given {instance}, or creates a new {WasmInternalFunction} if 4931cb0ef41Sopenharmony_ci // it does not exist yet. The new {WasmInternalFunction} is added to the 4941cb0ef41Sopenharmony_ci // cache of the {instance} immediately. 4951cb0ef41Sopenharmony_ci static Handle<WasmInternalFunction> GetOrCreateWasmInternalFunction( 4961cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmInstanceObject> instance, 4971cb0ef41Sopenharmony_ci int function_index); 4981cb0ef41Sopenharmony_ci 4991cb0ef41Sopenharmony_ci static void SetWasmInternalFunction(Isolate* isolate, 5001cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> instance, 5011cb0ef41Sopenharmony_ci int index, 5021cb0ef41Sopenharmony_ci Handle<WasmInternalFunction> val); 5031cb0ef41Sopenharmony_ci 5041cb0ef41Sopenharmony_ci // Imports a constructed {WasmJSFunction} into the indirect function table of 5051cb0ef41Sopenharmony_ci // this instance. Note that this might trigger wrapper compilation, since a 5061cb0ef41Sopenharmony_ci // {WasmJSFunction} is instance-independent and just wraps a JS callable. 5071cb0ef41Sopenharmony_ci static void ImportWasmJSFunctionIntoTable(Isolate* isolate, 5081cb0ef41Sopenharmony_ci Handle<WasmInstanceObject> instance, 5091cb0ef41Sopenharmony_ci int table_index, int entry_index, 5101cb0ef41Sopenharmony_ci Handle<WasmJSFunction> js_function); 5111cb0ef41Sopenharmony_ci 5121cb0ef41Sopenharmony_ci // Get a raw pointer to the location where the given global is stored. 5131cb0ef41Sopenharmony_ci // {global} must not be a reference type. 5141cb0ef41Sopenharmony_ci static uint8_t* GetGlobalStorage(Handle<WasmInstanceObject>, 5151cb0ef41Sopenharmony_ci const wasm::WasmGlobal&); 5161cb0ef41Sopenharmony_ci 5171cb0ef41Sopenharmony_ci // Get the FixedArray and the index in that FixedArray for the given global, 5181cb0ef41Sopenharmony_ci // which must be a reference type. 5191cb0ef41Sopenharmony_ci static std::pair<Handle<FixedArray>, uint32_t> GetGlobalBufferAndIndex( 5201cb0ef41Sopenharmony_ci Handle<WasmInstanceObject>, const wasm::WasmGlobal&); 5211cb0ef41Sopenharmony_ci 5221cb0ef41Sopenharmony_ci // Get the value of a global in the given instance. 5231cb0ef41Sopenharmony_ci static wasm::WasmValue GetGlobalValue(Handle<WasmInstanceObject>, 5241cb0ef41Sopenharmony_ci const wasm::WasmGlobal&); 5251cb0ef41Sopenharmony_ci 5261cb0ef41Sopenharmony_ci OBJECT_CONSTRUCTORS(WasmInstanceObject, JSObject); 5271cb0ef41Sopenharmony_ci 5281cb0ef41Sopenharmony_ci private: 5291cb0ef41Sopenharmony_ci static void InitDataSegmentArrays(Handle<WasmInstanceObject>, 5301cb0ef41Sopenharmony_ci Handle<WasmModuleObject>); 5311cb0ef41Sopenharmony_ci static void InitElemSegmentArrays(Handle<WasmInstanceObject>, 5321cb0ef41Sopenharmony_ci Handle<WasmModuleObject>); 5331cb0ef41Sopenharmony_ci}; 5341cb0ef41Sopenharmony_ci 5351cb0ef41Sopenharmony_ci// Representation of WebAssembly.Exception JavaScript-level object. 5361cb0ef41Sopenharmony_ciclass WasmTagObject 5371cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmTagObject<WasmTagObject, JSObject> { 5381cb0ef41Sopenharmony_ci public: 5391cb0ef41Sopenharmony_ci // Checks whether the given {sig} has the same parameter types as the 5401cb0ef41Sopenharmony_ci // serialized signature stored within this tag object. 5411cb0ef41Sopenharmony_ci bool MatchesSignature(const wasm::FunctionSig* sig); 5421cb0ef41Sopenharmony_ci 5431cb0ef41Sopenharmony_ci static Handle<WasmTagObject> New(Isolate* isolate, 5441cb0ef41Sopenharmony_ci const wasm::FunctionSig* sig, 5451cb0ef41Sopenharmony_ci Handle<HeapObject> tag); 5461cb0ef41Sopenharmony_ci 5471cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmTagObject) 5481cb0ef41Sopenharmony_ci}; 5491cb0ef41Sopenharmony_ci 5501cb0ef41Sopenharmony_ci// A Wasm exception that has been thrown out of Wasm code. 5511cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE WasmExceptionPackage : public JSObject { 5521cb0ef41Sopenharmony_ci public: 5531cb0ef41Sopenharmony_ci static Handle<WasmExceptionPackage> New( 5541cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmExceptionTag> exception_tag, 5551cb0ef41Sopenharmony_ci int encoded_size); 5561cb0ef41Sopenharmony_ci 5571cb0ef41Sopenharmony_ci static Handle<WasmExceptionPackage> New( 5581cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmExceptionTag> exception_tag, 5591cb0ef41Sopenharmony_ci Handle<FixedArray> values); 5601cb0ef41Sopenharmony_ci 5611cb0ef41Sopenharmony_ci // The below getters return {undefined} in case the given exception package 5621cb0ef41Sopenharmony_ci // does not carry the requested values (i.e. is of a different type). 5631cb0ef41Sopenharmony_ci static Handle<Object> GetExceptionTag( 5641cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmExceptionPackage> exception_package); 5651cb0ef41Sopenharmony_ci static Handle<Object> GetExceptionValues( 5661cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmExceptionPackage> exception_package); 5671cb0ef41Sopenharmony_ci 5681cb0ef41Sopenharmony_ci // Determines the size of the array holding all encoded exception values. 5691cb0ef41Sopenharmony_ci static uint32_t GetEncodedSize(const wasm::WasmTag* tag); 5701cb0ef41Sopenharmony_ci 5711cb0ef41Sopenharmony_ci DECL_CAST(WasmExceptionPackage) 5721cb0ef41Sopenharmony_ci OBJECT_CONSTRUCTORS(WasmExceptionPackage, JSObject); 5731cb0ef41Sopenharmony_ci}; 5741cb0ef41Sopenharmony_ci 5751cb0ef41Sopenharmony_civoid V8_EXPORT_PRIVATE EncodeI32ExceptionValue( 5761cb0ef41Sopenharmony_ci Handle<FixedArray> encoded_values, uint32_t* encoded_index, uint32_t value); 5771cb0ef41Sopenharmony_ci 5781cb0ef41Sopenharmony_civoid V8_EXPORT_PRIVATE EncodeI64ExceptionValue( 5791cb0ef41Sopenharmony_ci Handle<FixedArray> encoded_values, uint32_t* encoded_index, uint64_t value); 5801cb0ef41Sopenharmony_ci 5811cb0ef41Sopenharmony_civoid V8_EXPORT_PRIVATE 5821cb0ef41Sopenharmony_ciDecodeI32ExceptionValue(Handle<FixedArray> encoded_values, 5831cb0ef41Sopenharmony_ci uint32_t* encoded_index, uint32_t* value); 5841cb0ef41Sopenharmony_ci 5851cb0ef41Sopenharmony_civoid V8_EXPORT_PRIVATE 5861cb0ef41Sopenharmony_ciDecodeI64ExceptionValue(Handle<FixedArray> encoded_values, 5871cb0ef41Sopenharmony_ci uint32_t* encoded_index, uint64_t* value); 5881cb0ef41Sopenharmony_ci 5891cb0ef41Sopenharmony_ci// A Wasm function that is wrapped and exported to JavaScript. 5901cb0ef41Sopenharmony_ci// Representation of WebAssembly.Function JavaScript-level object. 5911cb0ef41Sopenharmony_ciclass WasmExportedFunction : public JSFunction { 5921cb0ef41Sopenharmony_ci public: 5931cb0ef41Sopenharmony_ci WasmInstanceObject instance(); 5941cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE int function_index(); 5951cb0ef41Sopenharmony_ci 5961cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static bool IsWasmExportedFunction(Object object); 5971cb0ef41Sopenharmony_ci 5981cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static Handle<WasmExportedFunction> New( 5991cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmInstanceObject> instance, int func_index, 6001cb0ef41Sopenharmony_ci int arity, Handle<CodeT> export_wrapper); 6011cb0ef41Sopenharmony_ci 6021cb0ef41Sopenharmony_ci Address GetWasmCallTarget(); 6031cb0ef41Sopenharmony_ci 6041cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE const wasm::FunctionSig* sig(); 6051cb0ef41Sopenharmony_ci 6061cb0ef41Sopenharmony_ci bool MatchesSignature(const wasm::WasmModule* other_module, 6071cb0ef41Sopenharmony_ci const wasm::FunctionSig* other_sig); 6081cb0ef41Sopenharmony_ci 6091cb0ef41Sopenharmony_ci // Return a null-terminated string with the debug name in the form 6101cb0ef41Sopenharmony_ci // 'js-to-wasm:<sig>'. 6111cb0ef41Sopenharmony_ci static std::unique_ptr<char[]> GetDebugName(const wasm::FunctionSig* sig); 6121cb0ef41Sopenharmony_ci 6131cb0ef41Sopenharmony_ci DECL_CAST(WasmExportedFunction) 6141cb0ef41Sopenharmony_ci OBJECT_CONSTRUCTORS(WasmExportedFunction, JSFunction); 6151cb0ef41Sopenharmony_ci}; 6161cb0ef41Sopenharmony_ci 6171cb0ef41Sopenharmony_ci// A Wasm function that was created by wrapping a JavaScript callable. 6181cb0ef41Sopenharmony_ci// Representation of WebAssembly.Function JavaScript-level object. 6191cb0ef41Sopenharmony_ciclass WasmJSFunction : public JSFunction { 6201cb0ef41Sopenharmony_ci public: 6211cb0ef41Sopenharmony_ci static bool IsWasmJSFunction(Object object); 6221cb0ef41Sopenharmony_ci 6231cb0ef41Sopenharmony_ci static Handle<WasmJSFunction> New(Isolate* isolate, 6241cb0ef41Sopenharmony_ci const wasm::FunctionSig* sig, 6251cb0ef41Sopenharmony_ci Handle<JSReceiver> callable, 6261cb0ef41Sopenharmony_ci Handle<HeapObject> suspender); 6271cb0ef41Sopenharmony_ci 6281cb0ef41Sopenharmony_ci JSReceiver GetCallable() const; 6291cb0ef41Sopenharmony_ci HeapObject GetSuspender() const; 6301cb0ef41Sopenharmony_ci // Deserializes the signature of this function using the provided zone. Note 6311cb0ef41Sopenharmony_ci // that lifetime of the signature is hence directly coupled to the zone. 6321cb0ef41Sopenharmony_ci const wasm::FunctionSig* GetSignature(Zone* zone); 6331cb0ef41Sopenharmony_ci bool MatchesSignature(const wasm::FunctionSig* sig); 6341cb0ef41Sopenharmony_ci // Special typing rule for imports wrapped by a Suspender. 6351cb0ef41Sopenharmony_ci bool MatchesSignatureForSuspend(const wasm::FunctionSig* sig); 6361cb0ef41Sopenharmony_ci 6371cb0ef41Sopenharmony_ci DECL_CAST(WasmJSFunction) 6381cb0ef41Sopenharmony_ci OBJECT_CONSTRUCTORS(WasmJSFunction, JSFunction); 6391cb0ef41Sopenharmony_ci}; 6401cb0ef41Sopenharmony_ci 6411cb0ef41Sopenharmony_ci// An external function exposed to Wasm via the C/C++ API. 6421cb0ef41Sopenharmony_ciclass WasmCapiFunction : public JSFunction { 6431cb0ef41Sopenharmony_ci public: 6441cb0ef41Sopenharmony_ci static bool IsWasmCapiFunction(Object object); 6451cb0ef41Sopenharmony_ci 6461cb0ef41Sopenharmony_ci static Handle<WasmCapiFunction> New( 6471cb0ef41Sopenharmony_ci Isolate* isolate, Address call_target, Handle<Foreign> embedder_data, 6481cb0ef41Sopenharmony_ci Handle<PodArray<wasm::ValueType>> serialized_signature); 6491cb0ef41Sopenharmony_ci 6501cb0ef41Sopenharmony_ci PodArray<wasm::ValueType> GetSerializedSignature() const; 6511cb0ef41Sopenharmony_ci // Checks whether the given {sig} has the same parameter types as the 6521cb0ef41Sopenharmony_ci // serialized signature stored within this C-API function object. 6531cb0ef41Sopenharmony_ci bool MatchesSignature(const wasm::FunctionSig* sig) const; 6541cb0ef41Sopenharmony_ci 6551cb0ef41Sopenharmony_ci DECL_CAST(WasmCapiFunction) 6561cb0ef41Sopenharmony_ci OBJECT_CONSTRUCTORS(WasmCapiFunction, JSFunction); 6571cb0ef41Sopenharmony_ci}; 6581cb0ef41Sopenharmony_ci 6591cb0ef41Sopenharmony_ci// Any external function that can be imported/exported in modules. This abstract 6601cb0ef41Sopenharmony_ci// class just dispatches to the following concrete classes: 6611cb0ef41Sopenharmony_ci// - {WasmExportedFunction}: A proper Wasm function exported from a module. 6621cb0ef41Sopenharmony_ci// - {WasmJSFunction}: A function constructed via WebAssembly.Function in JS. 6631cb0ef41Sopenharmony_ci// // TODO(wasm): Potentially {WasmCapiFunction} will be added here as well. 6641cb0ef41Sopenharmony_ciclass WasmExternalFunction : public JSFunction { 6651cb0ef41Sopenharmony_ci public: 6661cb0ef41Sopenharmony_ci static bool IsWasmExternalFunction(Object object); 6671cb0ef41Sopenharmony_ci 6681cb0ef41Sopenharmony_ci DECL_CAST(WasmExternalFunction) 6691cb0ef41Sopenharmony_ci OBJECT_CONSTRUCTORS(WasmExternalFunction, JSFunction); 6701cb0ef41Sopenharmony_ci}; 6711cb0ef41Sopenharmony_ci 6721cb0ef41Sopenharmony_ciclass WasmIndirectFunctionTable 6731cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmIndirectFunctionTable<WasmIndirectFunctionTable, 6741cb0ef41Sopenharmony_ci Struct> { 6751cb0ef41Sopenharmony_ci public: 6761cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(sig_ids, uint32_t*) 6771cb0ef41Sopenharmony_ci DECL_PRIMITIVE_ACCESSORS(targets, Address*) 6781cb0ef41Sopenharmony_ci DECL_OPTIONAL_ACCESSORS(managed_native_allocations, Foreign) 6791cb0ef41Sopenharmony_ci 6801cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static Handle<WasmIndirectFunctionTable> New( 6811cb0ef41Sopenharmony_ci Isolate* isolate, uint32_t size); 6821cb0ef41Sopenharmony_ci static void Resize(Isolate* isolate, Handle<WasmIndirectFunctionTable> table, 6831cb0ef41Sopenharmony_ci uint32_t new_size); 6841cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE void Set(uint32_t index, int sig_id, Address call_target, 6851cb0ef41Sopenharmony_ci Object ref); 6861cb0ef41Sopenharmony_ci void Clear(uint32_t index); 6871cb0ef41Sopenharmony_ci 6881cb0ef41Sopenharmony_ci DECL_PRINTER(WasmIndirectFunctionTable) 6891cb0ef41Sopenharmony_ci 6901cb0ef41Sopenharmony_ci STATIC_ASSERT(kStartOfStrongFieldsOffset == kManagedNativeAllocationsOffset); 6911cb0ef41Sopenharmony_ci using BodyDescriptor = FlexibleBodyDescriptor<kStartOfStrongFieldsOffset>; 6921cb0ef41Sopenharmony_ci 6931cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmIndirectFunctionTable) 6941cb0ef41Sopenharmony_ci}; 6951cb0ef41Sopenharmony_ci 6961cb0ef41Sopenharmony_ciclass WasmFunctionData 6971cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmFunctionData<WasmFunctionData, HeapObject> { 6981cb0ef41Sopenharmony_ci public: 6991cb0ef41Sopenharmony_ci DECL_ACCESSORS(internal, WasmInternalFunction) 7001cb0ef41Sopenharmony_ci 7011cb0ef41Sopenharmony_ci DECL_PRINTER(WasmFunctionData) 7021cb0ef41Sopenharmony_ci 7031cb0ef41Sopenharmony_ci using BodyDescriptor = FlexibleBodyDescriptor<kStartOfStrongFieldsOffset>; 7041cb0ef41Sopenharmony_ci 7051cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmFunctionData) 7061cb0ef41Sopenharmony_ci}; 7071cb0ef41Sopenharmony_ci 7081cb0ef41Sopenharmony_ci// Information for a WasmExportedFunction which is referenced as the function 7091cb0ef41Sopenharmony_ci// data of the SharedFunctionInfo underlying the function. For details please 7101cb0ef41Sopenharmony_ci// see the {SharedFunctionInfo::HasWasmExportedFunctionData} predicate. 7111cb0ef41Sopenharmony_ciclass WasmExportedFunctionData 7121cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmExportedFunctionData<WasmExportedFunctionData, 7131cb0ef41Sopenharmony_ci WasmFunctionData> { 7141cb0ef41Sopenharmony_ci public: 7151cb0ef41Sopenharmony_ci inline wasm::FunctionSig* sig() const; 7161cb0ef41Sopenharmony_ci 7171cb0ef41Sopenharmony_ci // Dispatched behavior. 7181cb0ef41Sopenharmony_ci DECL_PRINTER(WasmExportedFunctionData) 7191cb0ef41Sopenharmony_ci DECL_VERIFIER(WasmExportedFunctionData) 7201cb0ef41Sopenharmony_ci 7211cb0ef41Sopenharmony_ci using BodyDescriptor = 7221cb0ef41Sopenharmony_ci FlexibleBodyDescriptor<WasmFunctionData::kStartOfStrongFieldsOffset>; 7231cb0ef41Sopenharmony_ci 7241cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmExportedFunctionData) 7251cb0ef41Sopenharmony_ci}; 7261cb0ef41Sopenharmony_ci 7271cb0ef41Sopenharmony_ciclass WasmApiFunctionRef 7281cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmApiFunctionRef<WasmApiFunctionRef, HeapObject> { 7291cb0ef41Sopenharmony_ci public: 7301cb0ef41Sopenharmony_ci // Dispatched behavior. 7311cb0ef41Sopenharmony_ci DECL_PRINTER(WasmApiFunctionRef) 7321cb0ef41Sopenharmony_ci 7331cb0ef41Sopenharmony_ci class BodyDescriptor; 7341cb0ef41Sopenharmony_ci 7351cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmApiFunctionRef) 7361cb0ef41Sopenharmony_ci}; 7371cb0ef41Sopenharmony_ci 7381cb0ef41Sopenharmony_ciclass WasmInternalFunction 7391cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmInternalFunction<WasmInternalFunction, 7401cb0ef41Sopenharmony_ci Foreign> { 7411cb0ef41Sopenharmony_ci public: 7421cb0ef41Sopenharmony_ci // Returns a handle to the corresponding WasmInternalFunction if {external} is 7431cb0ef41Sopenharmony_ci // a WasmExternalFunction, or an empty handle otherwise. 7441cb0ef41Sopenharmony_ci static MaybeHandle<WasmInternalFunction> FromExternal(Handle<Object> external, 7451cb0ef41Sopenharmony_ci Isolate* isolate); 7461cb0ef41Sopenharmony_ci 7471cb0ef41Sopenharmony_ci // Dispatched behavior. 7481cb0ef41Sopenharmony_ci DECL_PRINTER(WasmInternalFunction) 7491cb0ef41Sopenharmony_ci 7501cb0ef41Sopenharmony_ci class BodyDescriptor; 7511cb0ef41Sopenharmony_ci 7521cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmInternalFunction) 7531cb0ef41Sopenharmony_ci}; 7541cb0ef41Sopenharmony_ci 7551cb0ef41Sopenharmony_ci// Information for a WasmJSFunction which is referenced as the function data of 7561cb0ef41Sopenharmony_ci// the SharedFunctionInfo underlying the function. For details please see the 7571cb0ef41Sopenharmony_ci// {SharedFunctionInfo::HasWasmJSFunctionData} predicate. 7581cb0ef41Sopenharmony_ciclass WasmJSFunctionData 7591cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmJSFunctionData<WasmJSFunctionData, 7601cb0ef41Sopenharmony_ci WasmFunctionData> { 7611cb0ef41Sopenharmony_ci public: 7621cb0ef41Sopenharmony_ci DECL_ACCESSORS(wasm_to_js_wrapper_code, CodeT) 7631cb0ef41Sopenharmony_ci 7641cb0ef41Sopenharmony_ci // Dispatched behavior. 7651cb0ef41Sopenharmony_ci DECL_PRINTER(WasmJSFunctionData) 7661cb0ef41Sopenharmony_ci 7671cb0ef41Sopenharmony_ci using BodyDescriptor = 7681cb0ef41Sopenharmony_ci FlexibleBodyDescriptor<WasmFunctionData::kStartOfStrongFieldsOffset>; 7691cb0ef41Sopenharmony_ci 7701cb0ef41Sopenharmony_ci private: 7711cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmJSFunctionData) 7721cb0ef41Sopenharmony_ci}; 7731cb0ef41Sopenharmony_ci 7741cb0ef41Sopenharmony_ciclass WasmCapiFunctionData 7751cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmCapiFunctionData<WasmCapiFunctionData, 7761cb0ef41Sopenharmony_ci WasmFunctionData> { 7771cb0ef41Sopenharmony_ci public: 7781cb0ef41Sopenharmony_ci DECL_PRINTER(WasmCapiFunctionData) 7791cb0ef41Sopenharmony_ci 7801cb0ef41Sopenharmony_ci using BodyDescriptor = 7811cb0ef41Sopenharmony_ci FlexibleBodyDescriptor<WasmFunctionData::kStartOfStrongFieldsOffset>; 7821cb0ef41Sopenharmony_ci 7831cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmCapiFunctionData) 7841cb0ef41Sopenharmony_ci}; 7851cb0ef41Sopenharmony_ci 7861cb0ef41Sopenharmony_ciclass WasmOnFulfilledData 7871cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmOnFulfilledData<WasmOnFulfilledData, 7881cb0ef41Sopenharmony_ci HeapObject> { 7891cb0ef41Sopenharmony_ci public: 7901cb0ef41Sopenharmony_ci using BodyDescriptor = 7911cb0ef41Sopenharmony_ci FlexibleBodyDescriptor<WasmOnFulfilledData::kStartOfStrongFieldsOffset>; 7921cb0ef41Sopenharmony_ci DECL_PRINTER(WasmOnFulfilledData) 7931cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmOnFulfilledData) 7941cb0ef41Sopenharmony_ci}; 7951cb0ef41Sopenharmony_ci 7961cb0ef41Sopenharmony_ciclass WasmScript : public AllStatic { 7971cb0ef41Sopenharmony_ci public: 7981cb0ef41Sopenharmony_ci // Position used for storing "on entry" breakpoints (a.k.a. instrumentation 7991cb0ef41Sopenharmony_ci // breakpoints). This would be an illegal position for any other breakpoint. 8001cb0ef41Sopenharmony_ci static constexpr int kOnEntryBreakpointPosition = -1; 8011cb0ef41Sopenharmony_ci 8021cb0ef41Sopenharmony_ci // Set a breakpoint on the given byte position inside the given module. 8031cb0ef41Sopenharmony_ci // This will affect all live and future instances of the module. 8041cb0ef41Sopenharmony_ci // The passed position might be modified to point to the next breakable 8051cb0ef41Sopenharmony_ci // location inside the same function. 8061cb0ef41Sopenharmony_ci // If it points outside a function, or behind the last breakable location, 8071cb0ef41Sopenharmony_ci // this function returns false and does not set any breakpoint. 8081cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static bool SetBreakPoint(Handle<Script>, int* position, 8091cb0ef41Sopenharmony_ci Handle<BreakPoint> break_point); 8101cb0ef41Sopenharmony_ci 8111cb0ef41Sopenharmony_ci // Set an "on entry" breakpoint (a.k.a. instrumentation breakpoint) inside 8121cb0ef41Sopenharmony_ci // the given module. This will affect all live and future instances of the 8131cb0ef41Sopenharmony_ci // module. 8141cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static void SetInstrumentationBreakpoint( 8151cb0ef41Sopenharmony_ci Handle<Script>, Handle<BreakPoint> break_point); 8161cb0ef41Sopenharmony_ci 8171cb0ef41Sopenharmony_ci // Set a breakpoint on first breakable position of the given function index 8181cb0ef41Sopenharmony_ci // inside the given module. This will affect all live and future instances of 8191cb0ef41Sopenharmony_ci // the module. 8201cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static bool SetBreakPointOnFirstBreakableForFunction( 8211cb0ef41Sopenharmony_ci Handle<Script>, int function_index, Handle<BreakPoint> break_point); 8221cb0ef41Sopenharmony_ci 8231cb0ef41Sopenharmony_ci // Set a breakpoint at the breakable offset of the given function index 8241cb0ef41Sopenharmony_ci // inside the given module. This will affect all live and future instances of 8251cb0ef41Sopenharmony_ci // the module. 8261cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static bool SetBreakPointForFunction( 8271cb0ef41Sopenharmony_ci Handle<Script>, int function_index, int breakable_offset, 8281cb0ef41Sopenharmony_ci Handle<BreakPoint> break_point); 8291cb0ef41Sopenharmony_ci 8301cb0ef41Sopenharmony_ci // Remove a previously set breakpoint at the given byte position inside the 8311cb0ef41Sopenharmony_ci // given module. If this breakpoint is not found this function returns false. 8321cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static bool ClearBreakPoint(Handle<Script>, int position, 8331cb0ef41Sopenharmony_ci Handle<BreakPoint> break_point); 8341cb0ef41Sopenharmony_ci 8351cb0ef41Sopenharmony_ci // Remove a previously set breakpoint by id. If this breakpoint is not found, 8361cb0ef41Sopenharmony_ci // returns false. 8371cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static bool ClearBreakPointById(Handle<Script>, 8381cb0ef41Sopenharmony_ci int breakpoint_id); 8391cb0ef41Sopenharmony_ci 8401cb0ef41Sopenharmony_ci // Remove all set breakpoints. 8411cb0ef41Sopenharmony_ci static void ClearAllBreakpoints(Script); 8421cb0ef41Sopenharmony_ci 8431cb0ef41Sopenharmony_ci // Get a list of all possible breakpoints within a given range of this module. 8441cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static bool GetPossibleBreakpoints( 8451cb0ef41Sopenharmony_ci wasm::NativeModule* native_module, const debug::Location& start, 8461cb0ef41Sopenharmony_ci const debug::Location& end, std::vector<debug::BreakLocation>* locations); 8471cb0ef41Sopenharmony_ci 8481cb0ef41Sopenharmony_ci // Return an empty handle if no breakpoint is hit at that location, or a 8491cb0ef41Sopenharmony_ci // FixedArray with all hit breakpoint objects. 8501cb0ef41Sopenharmony_ci static MaybeHandle<FixedArray> CheckBreakPoints(Isolate*, Handle<Script>, 8511cb0ef41Sopenharmony_ci int position, 8521cb0ef41Sopenharmony_ci StackFrameId stack_frame_id); 8531cb0ef41Sopenharmony_ci 8541cb0ef41Sopenharmony_ci private: 8551cb0ef41Sopenharmony_ci // Helper functions that update the breakpoint info list. 8561cb0ef41Sopenharmony_ci static void AddBreakpointToInfo(Handle<Script>, int position, 8571cb0ef41Sopenharmony_ci Handle<BreakPoint> break_point); 8581cb0ef41Sopenharmony_ci}; 8591cb0ef41Sopenharmony_ci 8601cb0ef41Sopenharmony_ci// Tags provide an object identity for each exception defined in a wasm module 8611cb0ef41Sopenharmony_ci// header. They are referenced by the following fields: 8621cb0ef41Sopenharmony_ci// - {WasmTagObject::tag}: The tag of the {Tag} object. 8631cb0ef41Sopenharmony_ci// - {WasmInstanceObject::tags_table}: List of tags used by an instance. 8641cb0ef41Sopenharmony_ciclass WasmExceptionTag 8651cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmExceptionTag<WasmExceptionTag, Struct> { 8661cb0ef41Sopenharmony_ci public: 8671cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE static Handle<WasmExceptionTag> New(Isolate* isolate, 8681cb0ef41Sopenharmony_ci int index); 8691cb0ef41Sopenharmony_ci 8701cb0ef41Sopenharmony_ci using BodyDescriptor = StructBodyDescriptor; 8711cb0ef41Sopenharmony_ci 8721cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmExceptionTag) 8731cb0ef41Sopenharmony_ci}; 8741cb0ef41Sopenharmony_ci 8751cb0ef41Sopenharmony_ci// Data annotated to the asm.js Module function. Used for later instantiation of 8761cb0ef41Sopenharmony_ci// that function. 8771cb0ef41Sopenharmony_ciclass AsmWasmData : public TorqueGeneratedAsmWasmData<AsmWasmData, Struct> { 8781cb0ef41Sopenharmony_ci public: 8791cb0ef41Sopenharmony_ci static Handle<AsmWasmData> New( 8801cb0ef41Sopenharmony_ci Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module, 8811cb0ef41Sopenharmony_ci Handle<FixedArray> export_wrappers, Handle<HeapNumber> uses_bitset); 8821cb0ef41Sopenharmony_ci 8831cb0ef41Sopenharmony_ci DECL_PRINTER(AsmWasmData) 8841cb0ef41Sopenharmony_ci 8851cb0ef41Sopenharmony_ci using BodyDescriptor = StructBodyDescriptor; 8861cb0ef41Sopenharmony_ci 8871cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(AsmWasmData) 8881cb0ef41Sopenharmony_ci}; 8891cb0ef41Sopenharmony_ci 8901cb0ef41Sopenharmony_ciclass WasmTypeInfo : public TorqueGeneratedWasmTypeInfo<WasmTypeInfo, Foreign> { 8911cb0ef41Sopenharmony_ci public: 8921cb0ef41Sopenharmony_ci inline void clear_foreign_address(Isolate* isolate); 8931cb0ef41Sopenharmony_ci 8941cb0ef41Sopenharmony_ci DECL_PRINTER(WasmTypeInfo) 8951cb0ef41Sopenharmony_ci 8961cb0ef41Sopenharmony_ci class BodyDescriptor; 8971cb0ef41Sopenharmony_ci 8981cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmTypeInfo) 8991cb0ef41Sopenharmony_ci}; 9001cb0ef41Sopenharmony_ci 9011cb0ef41Sopenharmony_ciclass WasmObject : public TorqueGeneratedWasmObject<WasmObject, JSReceiver> { 9021cb0ef41Sopenharmony_ci public: 9031cb0ef41Sopenharmony_ci // Prepares given value for being stored into a field of given Wasm type. 9041cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToWasmValue( 9051cb0ef41Sopenharmony_ci Isolate* isolate, wasm::ValueType type, Handle<Object> value); 9061cb0ef41Sopenharmony_ci 9071cb0ef41Sopenharmony_ci protected: 9081cb0ef41Sopenharmony_ci // Returns boxed value of the object's field/element with given type and 9091cb0ef41Sopenharmony_ci // offset. 9101cb0ef41Sopenharmony_ci static inline Handle<Object> ReadValueAt(Isolate* isolate, 9111cb0ef41Sopenharmony_ci Handle<HeapObject> obj, 9121cb0ef41Sopenharmony_ci wasm::ValueType type, 9131cb0ef41Sopenharmony_ci uint32_t offset); 9141cb0ef41Sopenharmony_ci 9151cb0ef41Sopenharmony_ci static inline void WriteValueAt(Isolate* isolate, Handle<HeapObject> obj, 9161cb0ef41Sopenharmony_ci wasm::ValueType type, uint32_t offset, 9171cb0ef41Sopenharmony_ci Handle<Object> value); 9181cb0ef41Sopenharmony_ci 9191cb0ef41Sopenharmony_ci private: 9201cb0ef41Sopenharmony_ci template <typename ElementType> 9211cb0ef41Sopenharmony_ci static ElementType FromNumber(Object value); 9221cb0ef41Sopenharmony_ci 9231cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmObject) 9241cb0ef41Sopenharmony_ci}; 9251cb0ef41Sopenharmony_ci 9261cb0ef41Sopenharmony_ciclass WasmStruct : public TorqueGeneratedWasmStruct<WasmStruct, WasmObject> { 9271cb0ef41Sopenharmony_ci public: 9281cb0ef41Sopenharmony_ci static inline wasm::StructType* type(Map map); 9291cb0ef41Sopenharmony_ci inline wasm::StructType* type() const; 9301cb0ef41Sopenharmony_ci static inline wasm::StructType* GcSafeType(Map map); 9311cb0ef41Sopenharmony_ci static inline int Size(const wasm::StructType* type); 9321cb0ef41Sopenharmony_ci static inline int GcSafeSize(Map map); 9331cb0ef41Sopenharmony_ci static inline void EncodeInstanceSizeInMap(int instance_size, Map map); 9341cb0ef41Sopenharmony_ci static inline int DecodeInstanceSizeFromMap(Map map); 9351cb0ef41Sopenharmony_ci 9361cb0ef41Sopenharmony_ci // Returns the address of the field at given offset. 9371cb0ef41Sopenharmony_ci inline Address RawFieldAddress(int raw_offset); 9381cb0ef41Sopenharmony_ci 9391cb0ef41Sopenharmony_ci // Returns the ObjectSlot for tagged value at given offset. 9401cb0ef41Sopenharmony_ci inline ObjectSlot RawField(int raw_offset); 9411cb0ef41Sopenharmony_ci 9421cb0ef41Sopenharmony_ci wasm::WasmValue GetFieldValue(uint32_t field_index); 9431cb0ef41Sopenharmony_ci 9441cb0ef41Sopenharmony_ci // Returns boxed value of the object's field. 9451cb0ef41Sopenharmony_ci static inline Handle<Object> GetField(Isolate* isolate, 9461cb0ef41Sopenharmony_ci Handle<WasmStruct> obj, 9471cb0ef41Sopenharmony_ci uint32_t field_index); 9481cb0ef41Sopenharmony_ci 9491cb0ef41Sopenharmony_ci static inline void SetField(Isolate* isolate, Handle<WasmStruct> obj, 9501cb0ef41Sopenharmony_ci uint32_t field_index, Handle<Object> value); 9511cb0ef41Sopenharmony_ci 9521cb0ef41Sopenharmony_ci DECL_PRINTER(WasmStruct) 9531cb0ef41Sopenharmony_ci 9541cb0ef41Sopenharmony_ci class BodyDescriptor; 9551cb0ef41Sopenharmony_ci 9561cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmStruct) 9571cb0ef41Sopenharmony_ci}; 9581cb0ef41Sopenharmony_ci 9591cb0ef41Sopenharmony_ciclass WasmArray : public TorqueGeneratedWasmArray<WasmArray, WasmObject> { 9601cb0ef41Sopenharmony_ci public: 9611cb0ef41Sopenharmony_ci static inline wasm::ArrayType* type(Map map); 9621cb0ef41Sopenharmony_ci inline wasm::ArrayType* type() const; 9631cb0ef41Sopenharmony_ci static inline wasm::ArrayType* GcSafeType(Map map); 9641cb0ef41Sopenharmony_ci 9651cb0ef41Sopenharmony_ci // Get the {ObjectSlot} corresponding to the element at {index}. Requires that 9661cb0ef41Sopenharmony_ci // this is a reference array. 9671cb0ef41Sopenharmony_ci inline ObjectSlot ElementSlot(uint32_t index); 9681cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE wasm::WasmValue GetElement(uint32_t index); 9691cb0ef41Sopenharmony_ci 9701cb0ef41Sopenharmony_ci static inline int SizeFor(Map map, int length); 9711cb0ef41Sopenharmony_ci 9721cb0ef41Sopenharmony_ci // Returns boxed value of the array's element. 9731cb0ef41Sopenharmony_ci static inline Handle<Object> GetElement(Isolate* isolate, 9741cb0ef41Sopenharmony_ci Handle<WasmArray> array, 9751cb0ef41Sopenharmony_ci uint32_t index); 9761cb0ef41Sopenharmony_ci 9771cb0ef41Sopenharmony_ci // Returns the offset/Address of the element at {index}. 9781cb0ef41Sopenharmony_ci inline uint32_t element_offset(uint32_t index); 9791cb0ef41Sopenharmony_ci inline Address ElementAddress(uint32_t index); 9801cb0ef41Sopenharmony_ci 9811cb0ef41Sopenharmony_ci static int MaxLength(uint32_t element_size_bytes) { 9821cb0ef41Sopenharmony_ci // The total object size must fit into a Smi, for filler objects. To make 9831cb0ef41Sopenharmony_ci // the behavior of Wasm programs independent from the Smi configuration, 9841cb0ef41Sopenharmony_ci // we hard-code the smaller of the two supported ranges. 9851cb0ef41Sopenharmony_ci return (SmiTagging<4>::kSmiMaxValue - kHeaderSize) / element_size_bytes; 9861cb0ef41Sopenharmony_ci } 9871cb0ef41Sopenharmony_ci 9881cb0ef41Sopenharmony_ci static int MaxLength(const wasm::ArrayType* type) { 9891cb0ef41Sopenharmony_ci return MaxLength(type->element_type().value_kind_size()); 9901cb0ef41Sopenharmony_ci } 9911cb0ef41Sopenharmony_ci 9921cb0ef41Sopenharmony_ci static inline void EncodeElementSizeInMap(int element_size, Map map); 9931cb0ef41Sopenharmony_ci static inline int DecodeElementSizeFromMap(Map map); 9941cb0ef41Sopenharmony_ci 9951cb0ef41Sopenharmony_ci DECL_PRINTER(WasmArray) 9961cb0ef41Sopenharmony_ci 9971cb0ef41Sopenharmony_ci class BodyDescriptor; 9981cb0ef41Sopenharmony_ci 9991cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmArray) 10001cb0ef41Sopenharmony_ci}; 10011cb0ef41Sopenharmony_ci 10021cb0ef41Sopenharmony_ci// A wasm delimited continuation. 10031cb0ef41Sopenharmony_ciclass WasmContinuationObject 10041cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmContinuationObject<WasmContinuationObject, 10051cb0ef41Sopenharmony_ci Struct> { 10061cb0ef41Sopenharmony_ci public: 10071cb0ef41Sopenharmony_ci static Handle<WasmContinuationObject> New( 10081cb0ef41Sopenharmony_ci Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack); 10091cb0ef41Sopenharmony_ci static Handle<WasmContinuationObject> New( 10101cb0ef41Sopenharmony_ci Isolate* isolate, Handle<WasmContinuationObject> parent); 10111cb0ef41Sopenharmony_ci 10121cb0ef41Sopenharmony_ci DECL_PRINTER(WasmContinuationObject) 10131cb0ef41Sopenharmony_ci 10141cb0ef41Sopenharmony_ci using BodyDescriptor = StructBodyDescriptor; 10151cb0ef41Sopenharmony_ci 10161cb0ef41Sopenharmony_ci private: 10171cb0ef41Sopenharmony_ci static Handle<WasmContinuationObject> New( 10181cb0ef41Sopenharmony_ci Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack, 10191cb0ef41Sopenharmony_ci Handle<HeapObject> parent); 10201cb0ef41Sopenharmony_ci 10211cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmContinuationObject) 10221cb0ef41Sopenharmony_ci}; 10231cb0ef41Sopenharmony_ci 10241cb0ef41Sopenharmony_ci// The suspender object provides an API to suspend and resume wasm code using 10251cb0ef41Sopenharmony_ci// promises. See: https://github.com/WebAssembly/js-promise-integration. 10261cb0ef41Sopenharmony_ciclass WasmSuspenderObject 10271cb0ef41Sopenharmony_ci : public TorqueGeneratedWasmSuspenderObject<WasmSuspenderObject, JSObject> { 10281cb0ef41Sopenharmony_ci public: 10291cb0ef41Sopenharmony_ci enum State : int { Inactive = 0, Active, Suspended }; 10301cb0ef41Sopenharmony_ci static Handle<WasmSuspenderObject> New(Isolate* isolate); 10311cb0ef41Sopenharmony_ci // TODO(thibaudm): returnPromiseOnSuspend & suspendOnReturnedPromise. 10321cb0ef41Sopenharmony_ci DECL_PRINTER(WasmSuspenderObject) 10331cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(WasmSuspenderObject) 10341cb0ef41Sopenharmony_ci}; 10351cb0ef41Sopenharmony_ci 10361cb0ef41Sopenharmony_ci#undef DECL_OPTIONAL_ACCESSORS 10371cb0ef41Sopenharmony_ci 10381cb0ef41Sopenharmony_cinamespace wasm { 10391cb0ef41Sopenharmony_cibool TypecheckJSObject(Isolate* isolate, const WasmModule* module, 10401cb0ef41Sopenharmony_ci Handle<Object> value, ValueType expected, 10411cb0ef41Sopenharmony_ci const char** error_message); 10421cb0ef41Sopenharmony_ci} // namespace wasm 10431cb0ef41Sopenharmony_ci 10441cb0ef41Sopenharmony_ci} // namespace internal 10451cb0ef41Sopenharmony_ci} // namespace v8 10461cb0ef41Sopenharmony_ci 10471cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 10481cb0ef41Sopenharmony_ci 10491cb0ef41Sopenharmony_ci#endif // V8_WASM_WASM_OBJECTS_H_ 1050