From a76cd669b1ec953728b9d8352cfb73321f84268a Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sun, 31 Oct 2021 15:55:08 +0200 Subject: LibWeb: Make GlobalObject the first parameter of WebAssembly AOs Let's be consistent with the rest of LibJS (and the rest of the file). --- .../LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp | 2 +- .../LibWeb/WebAssembly/WebAssemblyObject.cpp | 20 ++++++++++---------- .../Libraries/LibWeb/WebAssembly/WebAssemblyObject.h | 6 +++--- .../WebAssembly/WebAssemblyTableConstructor.cpp | 2 +- .../LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) (limited to 'Userland/Libraries/LibWeb/WebAssembly') diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp index 48b79c3532..a6e083f6f9 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp @@ -36,7 +36,7 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object) [&](const Wasm::FunctionAddress& address) { auto object = cache.function_instances.get(address); if (!object.has_value()) { - object = create_native_function(address, export_.name(), global_object); + object = create_native_function(global_object, address, export_.name()); cache.function_instances.set(address, *object); } m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index 7a5e3ee254..995d1fc6b2 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -194,7 +194,7 @@ Result WebAssemblyObject::instantiate_module(Wasm::Module con [&](auto&, auto& arguments) -> Wasm::Result { JS::MarkedValueList argument_values { vm.heap() }; for (auto& entry : arguments) - argument_values.append(to_js_value(entry, global_object)); + argument_values.append(to_js_value(global_object, entry)); auto result_or_error = vm.call(function, JS::js_undefined(), move(argument_values)); if (result_or_error.is_error()) { @@ -205,7 +205,7 @@ Result WebAssemblyObject::instantiate_module(Wasm::Module con return Wasm::Result { Vector {} }; if (type.results().size() == 1) { - auto value = to_webassembly_value(result_or_error.release_value(), type.results().first(), global_object); + auto value = to_webassembly_value(global_object, result_or_error.release_value(), type.results().first()); if (!value.has_value()) return Wasm::Trap {}; @@ -238,7 +238,7 @@ Result WebAssemblyObject::instantiate_module(Wasm::Module con vm.throw_exception(global_object, "LinkError: Import resolution attempted to cast a BigInteger to a Number"); return; } - auto cast_value = to_webassembly_value(import_, type.type(), global_object); + auto cast_value = to_webassembly_value(global_object, import_, type.type()); if (!cast_value.has_value()) return; address = s_abstract_machine.store().allocate({ type.type(), false }, cast_value.release_value()); @@ -358,7 +358,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyObject::instantiate) return promise; } -JS::Value to_js_value(Wasm::Value& wasm_value, JS::GlobalObject& global_object) +JS::Value to_js_value(JS::GlobalObject& global_object, Wasm::Value& wasm_value) { switch (wasm_value.type().kind()) { case Wasm::ValueType::I64: @@ -371,7 +371,7 @@ JS::Value to_js_value(Wasm::Value& wasm_value, JS::GlobalObject& global_object) return JS::Value(static_cast(wasm_value.to().value())); case Wasm::ValueType::FunctionReference: // FIXME: What's the name of a function reference that isn't exported? - return create_native_function(wasm_value.to().value().address, "FIXME_IHaveNoIdeaWhatThisShouldBeCalled", global_object); + return create_native_function(global_object, wasm_value.to().value().address, "FIXME_IHaveNoIdeaWhatThisShouldBeCalled"); case Wasm::ValueType::NullFunctionReference: return JS::js_null(); case Wasm::ValueType::ExternReference: @@ -381,7 +381,7 @@ JS::Value to_js_value(Wasm::Value& wasm_value, JS::GlobalObject& global_object) VERIFY_NOT_REACHED(); } -Optional to_webassembly_value(JS::Value value, const Wasm::ValueType& type, JS::GlobalObject& global_object) +Optional to_webassembly_value(JS::GlobalObject& global_object, JS::Value value, const Wasm::ValueType& type) { static ::Crypto::SignedBigInteger two_64 = "1"_sbigint.shift_left(64); auto& vm = global_object.vm(); @@ -432,7 +432,7 @@ Optional to_webassembly_value(JS::Value value, const Wasm::ValueTyp VERIFY_NOT_REACHED(); } -JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String name, JS::GlobalObject& global_object) +JS::NativeFunction* create_native_function(JS::GlobalObject& global_object, Wasm::FunctionAddress address, String const& name) { Optional type; WebAssemblyObject::s_abstract_machine.store().get(address)->visit([&](const auto& value) { type = value.type(); }); @@ -449,7 +449,7 @@ JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String // Grab as many values as needed and convert them. size_t index = 0; for (auto& type : type.parameters()) { - auto result = to_webassembly_value(vm.argument(index++), type, global_object); + auto result = to_webassembly_value(global_object, vm.argument(index++), type); if (result.has_value()) values.append(result.release_value()); else @@ -465,11 +465,11 @@ JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String return JS::js_undefined(); if (result.values().size() == 1) - return to_js_value(result.values().first(), global_object); + return to_js_value(global_object, result.values().first()); Vector result_values; for (auto& entry : result.values()) - result_values.append(to_js_value(entry, global_object)); + result_values.append(to_js_value(global_object, entry)); return JS::Value(JS::Array::create_from(global_object, result_values)); }); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h index 4bc959472f..6f243da67b 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h @@ -15,9 +15,9 @@ namespace Web::Bindings { class WebAssemblyMemoryObject; Result parse_module(JS::GlobalObject& global_object, JS::Object* buffer); -JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String name, JS::GlobalObject& global_object); -JS::Value to_js_value(Wasm::Value& wasm_value, JS::GlobalObject& global_object); -Optional to_webassembly_value(JS::Value value, const Wasm::ValueType& type, JS::GlobalObject& global_object); +JS::NativeFunction* create_native_function(JS::GlobalObject& global_object, Wasm::FunctionAddress address, String const& name); +JS::Value to_js_value(JS::GlobalObject& global_object, Wasm::Value& wasm_value); +Optional to_webassembly_value(JS::GlobalObject& global_object, JS::Value value, const Wasm::ValueType& type); class WebAssemblyObject final : public JS::Object { JS_OBJECT(WebAssemblyObject, JS::Object); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp index 83647680c2..e5d09f8505 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp @@ -66,7 +66,7 @@ JS::ThrowCompletionOr WebAssemblyTableConstructor::construct(Functi if (value_value.is_undefined()) return Wasm::Value(*reference_type, 0ull); - return to_webassembly_value(value_value, *reference_type, global_object); + return to_webassembly_value(global_object, value_value, *reference_type); }(); if (auto* exception = vm.exception()) diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp index a51ee5bd0a..f5b66f8bf3 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp @@ -40,7 +40,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow) if (value_value.is_undefined()) return Wasm::Value(table->type().element_type(), 0ull); - return to_webassembly_value(value_value, table->type().element_type(), global_object); + return to_webassembly_value(global_object, value_value, table->type().element_type()); }(); if (!reference_value.has_value()) @@ -81,7 +81,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::get) return JS::js_undefined(); Wasm::Value wasm_value { ref.value() }; - return to_js_value(wasm_value, global_object); + return to_js_value(global_object, wasm_value); } JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::set) @@ -109,7 +109,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::set) if (value_value.is_undefined()) return Wasm::Value(table->type().element_type(), 0ull); - return to_webassembly_value(value_value, table->type().element_type(), global_object); + return to_webassembly_value(global_object, value_value, table->type().element_type()); }(); if (!reference_value.has_value()) -- cgit v1.2.3