From d0efc7734aba153934a565fad240e3a586de5afb Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 25 Sep 2022 18:05:03 -0600 Subject: [PATCH] LibWeb: Remove unecessary dependence on Window from WebAssembly classes These classes only needed Window to get at its realm. Pass a realm directly to construct WebAssembly classes. --- .../WebAssemblyInstanceConstructor.cpp | 5 ++--- .../WebAssembly/WebAssemblyInstanceObject.cpp | 4 ++-- .../WebAssemblyMemoryConstructor.cpp | 6 ++---- .../WebAssemblyModuleConstructor.cpp | 6 ++---- .../WebAssembly/WebAssemblyModuleObject.cpp | 2 +- .../LibWeb/WebAssembly/WebAssemblyObject.cpp | 21 +++++++++---------- .../WebAssemblyTableConstructor.cpp | 5 ++--- .../WebAssembly/WebAssemblyTableObject.cpp | 2 +- 8 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp index 6cce454127..0f40dd5429 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include @@ -42,10 +42,9 @@ JS::ThrowCompletionOr WebAssemblyInstanceConstructor::construct(Fun void WebAssemblyInstanceConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.ensure_web_prototype("WebAssemblyInstancePrototype"), 0); + define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype(realm, "WebAssemblyInstancePrototype"), 0); define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp index 821fe58480..7d937fe963 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -18,7 +18,7 @@ namespace Web::Bindings { WebAssemblyInstanceObject::WebAssemblyInstanceObject(JS::Realm& realm, size_t index) - : Object(static_cast(realm.global_object()).ensure_web_prototype("WebAssemblyInstancePrototype")) + : Object(Bindings::ensure_web_prototype(realm, "WebAssemblyInstancePrototype")) , m_index(index) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp index 78068af3e4..1cde4c1994 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp @@ -4,8 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include -#include +#include #include #include #include @@ -53,10 +52,9 @@ JS::ThrowCompletionOr WebAssemblyMemoryConstructor::construct(Funct void WebAssemblyMemoryConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.ensure_web_prototype("WebAssemblyMemoryPrototype"), 0); + define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype(realm, "WebAssemblyMemoryPrototype"), 0); define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp index 217d22a2ea..17c985ff3c 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp @@ -4,9 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include -#include +#include #include #include #include @@ -40,10 +39,9 @@ JS::ThrowCompletionOr WebAssemblyModuleConstructor::construct(Funct void WebAssemblyModuleConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.ensure_web_prototype("WebAssemblyModulePrototype"), 0); + define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype(realm, "WebAssemblyModulePrototype"), 0); define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleObject.cpp index 8613837f0f..1b3f480e8e 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleObject.cpp @@ -10,7 +10,7 @@ namespace Web::Bindings { WebAssemblyModuleObject::WebAssemblyModuleObject(JS::Realm& realm, size_t index) - : Object(verify_cast(realm.global_object()).ensure_web_prototype("WebAssemblyModulePrototype")) + : Object(Bindings::ensure_web_prototype(realm, "WebAssemblyModulePrototype")) , m_index(index) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index 9a7b78a522..b19f2e104e 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include @@ -42,28 +42,27 @@ void WebAssemblyObject::initialize(JS::Realm& realm) auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); - auto& memory_constructor = window.ensure_web_constructor("WebAssembly.Memory"); + auto& memory_constructor = Bindings::ensure_web_constructor(realm, "WebAssembly.Memory"); memory_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Memory"), JS::Attribute::Configurable); - auto& memory_prototype = window.ensure_web_prototype("WebAssemblyMemoryPrototype"); + auto& memory_prototype = Bindings::ensure_web_prototype(realm, "WebAssemblyMemoryPrototype"); memory_prototype.define_direct_property(vm.names.constructor, &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); define_direct_property("Memory", &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); - auto& instance_constructor = window.ensure_web_constructor("WebAssembly.Instance"); + auto& instance_constructor = Bindings::ensure_web_constructor(realm, "WebAssembly.Instance"); instance_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Instance"), JS::Attribute::Configurable); - auto& instance_prototype = window.ensure_web_prototype("WebAssemblyInstancePrototype"); + auto& instance_prototype = Bindings::ensure_web_prototype(realm, "WebAssemblyInstancePrototype"); instance_prototype.define_direct_property(vm.names.constructor, &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); define_direct_property("Instance", &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); - auto& module_constructor = window.ensure_web_constructor("WebAssembly.Module"); + auto& module_constructor = Bindings::ensure_web_constructor(realm, "WebAssembly.Module"); module_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Module"), JS::Attribute::Configurable); - auto& module_prototype = window.ensure_web_prototype("WebAssemblyModulePrototype"); + auto& module_prototype = Bindings::ensure_web_prototype(realm, "WebAssemblyModulePrototype"); module_prototype.define_direct_property(vm.names.constructor, &module_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); define_direct_property("Module", &module_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); - auto& table_constructor = window.ensure_web_constructor("WebAssembly.Table"); + auto& table_constructor = Bindings::ensure_web_constructor(realm, "WebAssembly.Table"); table_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Table"), JS::Attribute::Configurable); - auto& table_prototype = window.ensure_web_prototype("WebAssemblyTablePrototype"); + auto& table_prototype = Bindings::ensure_web_prototype(realm, "WebAssemblyTablePrototype"); table_prototype.define_direct_property(vm.names.constructor, &table_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); define_direct_property("Table", &table_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); } @@ -482,7 +481,7 @@ JS::NativeFunction* create_native_function(JS::VM& vm, Wasm::FunctionAddress add } WebAssemblyMemoryObject::WebAssemblyMemoryObject(JS::Realm& realm, Wasm::MemoryAddress address) - : Object(verify_cast(realm.global_object()).ensure_web_prototype("WebAssemblyMemoryPrototype")) + : Object(Bindings::ensure_web_prototype(realm, "WebAssemblyMemoryPrototype")) , m_address(address) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp index e581ed01da..6b7076fbad 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -83,10 +83,9 @@ JS::ThrowCompletionOr WebAssemblyTableConstructor::construct(Functi void WebAssemblyTableConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.ensure_web_prototype("WebAssemblyTablePrototype"), 0); + define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype(realm, "WebAssemblyTablePrototype"), 0); define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.cpp index 030eed5b8d..f2c7326de9 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.cpp @@ -10,7 +10,7 @@ namespace Web::Bindings { WebAssemblyTableObject::WebAssemblyTableObject(JS::Realm& realm, Wasm::TableAddress address) - : Object(verify_cast(realm.global_object()).ensure_web_prototype("WebAssemblyTablePrototype")) + : Object(Bindings::ensure_web_prototype(realm, "WebAssemblyTablePrototype")) , m_address(address) { }