1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:57:44 +00:00

LibJS+LibWeb: Replace GlobalObject with Realm in object constructors

No functional changes - we can still very easily get to the global
object via `Realm::global_object()`. This is in preparation of moving
the intrinsics to the realm and no longer having to pass a global
object when allocating any object.
In a few (now, and many more in subsequent commits) places we get a
realm using `GlobalObject::associated_realm()`, this is intended to be
temporary. For example, create() functions will later receive the same
treatment and are passed a realm instead of a global object.
This commit is contained in:
Linus Groh 2022-08-16 00:20:49 +01:00
parent 4c300cc5e8
commit ecd163bdf1
315 changed files with 592 additions and 554 deletions

View file

@ -14,8 +14,8 @@
namespace Web::Bindings {
AudioConstructor::AudioConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
AudioConstructor::AudioConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}

View file

@ -13,7 +13,7 @@ namespace Web::Bindings {
class AudioConstructor final : public JS::NativeFunction {
public:
explicit AudioConstructor(JS::GlobalObject&);
explicit AudioConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~AudioConstructor() override = default;

View file

@ -13,8 +13,8 @@
namespace Web::Bindings {
CSSNamespace::CSSNamespace(JS::GlobalObject& global_object)
: JS::Object(*global_object.object_prototype())
CSSNamespace::CSSNamespace(JS::Realm& realm)
: JS::Object(*realm.global_object().object_prototype())
{
}

View file

@ -16,7 +16,7 @@ class CSSNamespace final : public JS::Object {
JS_OBJECT(CSSNamespace, JS::Object)
public:
explicit CSSNamespace(JS::GlobalObject&);
explicit CSSNamespace(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~CSSNamespace() override = default;

View file

@ -12,8 +12,8 @@
namespace Web {
namespace Bindings {
EventListenerWrapper::EventListenerWrapper(JS::GlobalObject& global_object, DOM::IDLEventListener& impl)
: Wrapper(*global_object.object_prototype())
EventListenerWrapper::EventListenerWrapper(JS::Realm& realm, DOM::IDLEventListener& impl)
: Wrapper(*realm.global_object().object_prototype())
, m_impl(impl)
{
}

View file

@ -15,7 +15,7 @@ class EventListenerWrapper final : public Wrapper {
JS_OBJECT(EventListenerWrapper, Wrapper);
public:
EventListenerWrapper(JS::GlobalObject&, DOM::IDLEventListener&);
EventListenerWrapper(JS::Realm& realm, DOM::IDLEventListener&);
virtual ~EventListenerWrapper() override = default;
DOM::IDLEventListener& impl() { return *m_impl; }

View file

@ -14,8 +14,8 @@
namespace Web::Bindings {
ImageConstructor::ImageConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
ImageConstructor::ImageConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}

View file

@ -13,7 +13,7 @@ namespace Web::Bindings {
class ImageConstructor final : public JS::NativeFunction {
public:
explicit ImageConstructor(JS::GlobalObject&);
explicit ImageConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~ImageConstructor() override = default;

View file

@ -11,8 +11,8 @@
namespace Web::Bindings {
LocationConstructor::LocationConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
LocationConstructor::LocationConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class LocationConstructor : public JS::NativeFunction {
JS_OBJECT(LocationConstructor, JS::NativeFunction);
public:
explicit LocationConstructor(JS::GlobalObject&);
explicit LocationConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~LocationConstructor() override;

View file

@ -23,8 +23,8 @@
namespace Web::Bindings {
// https://html.spec.whatwg.org/multipage/history.html#the-location-interface
LocationObject::LocationObject(JS::GlobalObject& global_object)
: Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<LocationPrototype>("Location"))
LocationObject::LocationObject(JS::Realm& realm)
: Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<LocationPrototype>("Location"))
, m_default_properties(heap())
{
}

View file

@ -21,7 +21,7 @@ class LocationObject final : public JS::Object {
JS_OBJECT(LocationObject, JS::Object);
public:
explicit LocationObject(JS::GlobalObject&);
explicit LocationObject(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~LocationObject() override = default;

View file

@ -18,8 +18,8 @@ class LocationPrototype final : public JS::Object {
JS_OBJECT(LocationPrototype, JS::Object);
public:
explicit LocationPrototype(JS::GlobalObject& global_object)
: JS::Object(*global_object.object_prototype())
explicit LocationPrototype(JS::Realm& realm)
: JS::Object(*realm.global_object().object_prototype())
{
}
};

View file

@ -11,8 +11,8 @@
namespace Web::Bindings {
NavigatorConstructor::NavigatorConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
NavigatorConstructor::NavigatorConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class NavigatorConstructor : public JS::NativeFunction {
JS_OBJECT(NavigatorConstructor, JS::NativeFunction);
public:
explicit NavigatorConstructor(JS::GlobalObject&);
explicit NavigatorConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~NavigatorConstructor() override;

View file

@ -13,8 +13,8 @@
namespace Web {
namespace Bindings {
NavigatorObject::NavigatorObject(JS::GlobalObject& global_object)
: Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<NavigatorPrototype>("Navigator"))
NavigatorObject::NavigatorObject(JS::Realm& realm)
: Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<NavigatorPrototype>("Navigator"))
{
}

View file

@ -16,7 +16,7 @@ class NavigatorObject final : public JS::Object {
JS_OBJECT(NavigatorObject, JS::Object);
public:
NavigatorObject(JS::GlobalObject&);
NavigatorObject(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~NavigatorObject() override = default;

View file

@ -18,8 +18,8 @@ class NavigatorPrototype final : public JS::Object {
JS_OBJECT(NavigatorPrototype, JS::Object);
public:
explicit NavigatorPrototype(JS::GlobalObject& global_object)
: JS::Object(*global_object.object_prototype())
explicit NavigatorPrototype(JS::Realm& realm)
: JS::Object(*realm.global_object().object_prototype())
{
}
};

View file

@ -15,8 +15,8 @@
namespace Web::Bindings {
OptionConstructor::OptionConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
OptionConstructor::OptionConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}

View file

@ -13,7 +13,7 @@ namespace Web::Bindings {
class OptionConstructor final : public JS::NativeFunction {
public:
explicit OptionConstructor(JS::GlobalObject&);
explicit OptionConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~OptionConstructor() override = default;

View file

@ -11,8 +11,8 @@
namespace Web::Bindings {
WindowConstructor::WindowConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
WindowConstructor::WindowConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}

View file

@ -14,7 +14,7 @@ class WindowConstructor : public JS::NativeFunction {
JS_OBJECT(WindowConstructor, JS::NativeFunction);
public:
explicit WindowConstructor(JS::GlobalObject&);
explicit WindowConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~WindowConstructor() override;

View file

@ -63,6 +63,8 @@ void WindowObject::initialize_global_object()
Object::set_prototype(&ensure_web_prototype<WindowPrototype>("Window"));
auto& realm = *associated_realm();
// FIXME: These should be native accessors, not properties
define_direct_property("window", this, JS::Attribute::Enumerable);
define_direct_property("frames", this, JS::Attribute::Enumerable);
@ -117,7 +119,7 @@ void WindowObject::initialize_global_object()
define_native_accessor("screenLeft", screen_left_getter, {}, attr);
define_native_accessor("screenTop", screen_top_getter, {}, attr);
define_direct_property("CSS", heap().allocate<CSSNamespace>(*this, *this), 0);
define_direct_property("CSS", heap().allocate<CSSNamespace>(*this, realm), 0);
define_native_accessor("localStorage", local_storage_getter, {}, attr);
define_native_accessor("sessionStorage", session_storage_getter, {}, attr);
@ -126,9 +128,9 @@ void WindowObject::initialize_global_object()
// Legacy
define_native_accessor("event", event_getter, event_setter, JS::Attribute::Enumerable);
m_location_object = heap().allocate<LocationObject>(*this, *this);
m_location_object = heap().allocate<LocationObject>(*this, realm);
auto* m_navigator_object = heap().allocate<NavigatorObject>(*this, *this);
auto* m_navigator_object = heap().allocate<NavigatorObject>(*this, realm);
define_direct_property("navigator", m_navigator_object, JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_direct_property("clientInformation", m_navigator_object, JS::Attribute::Enumerable | JS::Attribute::Configurable);
@ -136,7 +138,7 @@ void WindowObject::initialize_global_object()
define_native_accessor("location", location_getter, location_setter, JS::Attribute::Enumerable);
// WebAssembly "namespace"
define_direct_property("WebAssembly", heap().allocate<WebAssemblyObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_direct_property("WebAssembly", heap().allocate<WebAssemblyObject>(*this, realm), JS::Attribute::Enumerable | JS::Attribute::Configurable);
// HTML::GlobalEventHandlers and HTML::WindowEventHandlers
#define __ENUMERATE(attribute, event_name) \

View file

@ -53,7 +53,8 @@ public:
auto it = m_prototypes.find(class_name);
if (it != m_prototypes.end())
return *it->value;
auto* prototype = heap().allocate<T>(*this, *this);
auto& realm = *associated_realm();
auto* prototype = heap().allocate<T>(*this, realm);
m_prototypes.set(class_name, prototype);
return *prototype;
}
@ -64,7 +65,8 @@ public:
auto it = m_constructors.find(class_name);
if (it != m_constructors.end())
return *it->value;
auto* constructor = heap().allocate<T>(*this, *this);
auto& realm = *associated_realm();
auto* constructor = heap().allocate<T>(*this, realm);
m_constructors.set(class_name, constructor);
define_direct_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable);
return *constructor;

View file

@ -19,8 +19,8 @@ class WindowPrototype final : public JS::Object {
JS_OBJECT(WindowPrototype, JS::Object);
public:
explicit WindowPrototype(JS::GlobalObject& global_object)
: JS::Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<EventTargetPrototype>("EventTarget"))
explicit WindowPrototype(JS::Realm& realm)
: JS::Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<EventTargetPrototype>("EventTarget"))
{
}
};

View file

@ -22,8 +22,8 @@
namespace Web::Bindings {
// 7.4 The WindowProxy exotic object, https://html.spec.whatwg.org/multipage/window-object.html#the-windowproxy-exotic-object
WindowProxy::WindowProxy(JS::GlobalObject& global_object, WindowObject& window)
: JS::Object(global_object, nullptr)
WindowProxy::WindowProxy(JS::Realm& realm, WindowObject& window)
: JS::Object(realm, nullptr)
, m_window(&window)
{
}

View file

@ -17,7 +17,7 @@ class WindowProxy final : public JS::Object {
JS_OBJECT(WindowProxy, JS::Object);
public:
WindowProxy(JS::GlobalObject&, WindowObject&);
WindowProxy(JS::Realm&, WindowObject&);
virtual ~WindowProxy() override = default;
virtual JS::ThrowCompletionOr<JS::Object*> internal_get_prototype_of() const override;

View file

@ -28,8 +28,9 @@ private:
template<class NativeObject>
inline Wrapper* wrap_impl(JS::GlobalObject& global_object, NativeObject& native_object)
{
auto& realm = *global_object.associated_realm();
if (!native_object.wrapper()) {
native_object.set_wrapper(*global_object.heap().allocate<typename NativeObject::WrapperType>(global_object, global_object, native_object));
native_object.set_wrapper(*global_object.heap().allocate<typename NativeObject::WrapperType>(global_object, realm, native_object));
}
return native_object.wrapper();
}

View file

@ -14,8 +14,8 @@
namespace Web::Bindings {
WebAssemblyInstanceConstructor::WebAssemblyInstanceConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
WebAssemblyInstanceConstructor::WebAssemblyInstanceConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}
@ -30,12 +30,14 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyInstanceConstructor::construct(Fun
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto* module_argument = TRY(vm.argument(0).to_object(global_object));
if (!is<WebAssemblyModuleObject>(module_argument))
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
auto& module_object = static_cast<WebAssemblyModuleObject&>(*module_argument);
auto result = TRY(WebAssemblyObject::instantiate_module(module_object.module(), vm, global_object));
return heap().allocate<WebAssemblyInstanceObject>(global_object, global_object, result);
return heap().allocate<WebAssemblyInstanceObject>(global_object, realm, result);
}
void WebAssemblyInstanceConstructor::initialize(JS::GlobalObject& global_object)

View file

@ -14,7 +14,7 @@ class WebAssemblyInstanceConstructor : public JS::NativeFunction {
JS_OBJECT(WebAssemblyInstanceConstructor, JS::NativeFunction);
public:
explicit WebAssemblyInstanceConstructor(JS::GlobalObject&);
explicit WebAssemblyInstanceConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~WebAssemblyInstanceConstructor() override;

View file

@ -17,8 +17,8 @@
namespace Web::Bindings {
WebAssemblyInstanceObject::WebAssemblyInstanceObject(JS::GlobalObject& global_object, size_t index)
: Object(static_cast<Web::Bindings::WindowObject&>(global_object).ensure_web_prototype<WebAssemblyInstancePrototype>("WebAssemblyInstancePrototype"))
WebAssemblyInstanceObject::WebAssemblyInstanceObject(JS::Realm& realm, size_t index)
: Object(static_cast<Web::Bindings::WindowObject&>(realm.global_object()).ensure_web_prototype<WebAssemblyInstancePrototype>("WebAssemblyInstancePrototype"))
, m_index(index)
{
}
@ -27,6 +27,8 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object)
{
Object::initialize(global_object);
auto& realm = *global_object.associated_realm();
VERIFY(!m_exports_object);
m_exports_object = create(global_object, nullptr);
auto& instance = this->instance();
@ -44,7 +46,7 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object)
[&](Wasm::MemoryAddress const& address) {
Optional<WebAssemblyMemoryObject*> object = cache.memory_instances.get(address);
if (!object.has_value()) {
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(global_object, global_object, address);
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(global_object, realm, address);
cache.memory_instances.set(address, *object);
}
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);

View file

@ -19,7 +19,7 @@ class WebAssemblyInstanceObject final : public JS::Object {
JS_OBJECT(WebAssemblyInstanceObject, Object);
public:
explicit WebAssemblyInstanceObject(JS::GlobalObject&, size_t index);
explicit WebAssemblyInstanceObject(JS::Realm&, size_t index);
virtual void initialize(JS::GlobalObject&) override;
virtual ~WebAssemblyInstanceObject() override = default;

View file

@ -17,8 +17,8 @@ class WebAssemblyInstancePrototype final : public JS::Object {
JS_OBJECT(WebAssemblyInstancePrototype, Object);
public:
explicit WebAssemblyInstancePrototype(JS::GlobalObject& global_object)
: JS::Object(*global_object.object_prototype())
explicit WebAssemblyInstancePrototype(JS::Realm& realm)
: JS::Object(*realm.global_object().object_prototype())
{
}

View file

@ -12,8 +12,8 @@
namespace Web::Bindings {
WebAssemblyMemoryConstructor::WebAssemblyMemoryConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
WebAssemblyMemoryConstructor::WebAssemblyMemoryConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}
@ -28,6 +28,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto descriptor = TRY(vm.argument(0).to_object(global_object));
auto initial_value = TRY(descriptor->get("initial"));
@ -50,7 +51,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
if (!WebAssemblyObject::s_abstract_machine.store().get(*address)->grow(initial))
return vm.throw_completion<JS::TypeError>(global_object, String::formatted("Wasm Memory grow failed: {}", initial));
return vm.heap().allocate<WebAssemblyMemoryObject>(global_object, global_object, *address);
return vm.heap().allocate<WebAssemblyMemoryObject>(global_object, realm, *address);
}
void WebAssemblyMemoryConstructor::initialize(JS::GlobalObject& global_object)

View file

@ -14,7 +14,7 @@ class WebAssemblyMemoryConstructor : public JS::NativeFunction {
JS_OBJECT(WebAssemblyMemoryConstructor, JS::NativeFunction);
public:
explicit WebAssemblyMemoryConstructor(JS::GlobalObject&);
explicit WebAssemblyMemoryConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~WebAssemblyMemoryConstructor() override;

View file

@ -19,8 +19,8 @@ class WebAssemblyMemoryPrototype final : public JS::Object {
JS_OBJECT(WebAssemblyMemoryPrototype, JS::Object);
public:
explicit WebAssemblyMemoryPrototype(JS::GlobalObject& global_object)
: JS::Object(*global_object.object_prototype())
explicit WebAssemblyMemoryPrototype(JS::Realm& realm)
: JS::Object(*realm.global_object().object_prototype())
{
}

View file

@ -14,8 +14,8 @@
namespace Web::Bindings {
WebAssemblyModuleConstructor::WebAssemblyModuleConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
WebAssemblyModuleConstructor::WebAssemblyModuleConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}
@ -30,11 +30,12 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyModuleConstructor::construct(Funct
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto* buffer_object = TRY(vm.argument(0).to_object(global_object));
auto result = TRY(parse_module(global_object, buffer_object));
return heap().allocate<WebAssemblyModuleObject>(global_object, global_object, result);
return heap().allocate<WebAssemblyModuleObject>(global_object, realm, result);
}
void WebAssemblyModuleConstructor::initialize(JS::GlobalObject& global_object)

View file

@ -14,7 +14,7 @@ class WebAssemblyModuleConstructor : public JS::NativeFunction {
JS_OBJECT(WebAssemblyModuleConstructor, JS::NativeFunction);
public:
explicit WebAssemblyModuleConstructor(JS::GlobalObject&);
explicit WebAssemblyModuleConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~WebAssemblyModuleConstructor() override;

View file

@ -9,8 +9,8 @@
namespace Web::Bindings {
WebAssemblyModuleObject::WebAssemblyModuleObject(JS::GlobalObject& global_object, size_t index)
: Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<WebAssemblyModulePrototype>("WebAssemblyModulePrototype"))
WebAssemblyModuleObject::WebAssemblyModuleObject(JS::Realm& realm, size_t index)
: Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<WebAssemblyModulePrototype>("WebAssemblyModulePrototype"))
, m_index(index)
{
}

View file

@ -18,7 +18,7 @@ class WebAssemblyModuleObject final : public JS::Object {
JS_OBJECT(WebAssemblyModuleObject, Object);
public:
explicit WebAssemblyModuleObject(JS::GlobalObject&, size_t index);
explicit WebAssemblyModuleObject(JS::Realm&, size_t index);
virtual ~WebAssemblyModuleObject() override = default;
size_t index() const { return m_index; }

View file

@ -19,8 +19,8 @@ class WebAssemblyModulePrototype final : public JS::Object {
JS_OBJECT(WebAssemblyModulePrototype, JS::Object);
public:
explicit WebAssemblyModulePrototype(JS::GlobalObject& global_object)
: JS::Object(*global_object.object_prototype())
explicit WebAssemblyModulePrototype(JS::Realm& realm)
: JS::Object(*realm.global_object().object_prototype())
{
}
};

View file

@ -25,8 +25,8 @@
namespace Web::Bindings {
WebAssemblyObject::WebAssemblyObject(JS::GlobalObject& global_object)
: Object(*global_object.object_prototype())
WebAssemblyObject::WebAssemblyObject(JS::Realm& realm)
: Object(*realm.global_object().object_prototype())
{
s_abstract_machine.enable_instruction_count_limit();
}
@ -156,6 +156,8 @@ JS::ThrowCompletionOr<size_t> parse_module(JS::GlobalObject& global_object, JS::
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
{
auto& realm = *global_object.associated_realm();
// FIXME: This shouldn't block!
auto buffer_or_error = vm.argument(0).to_object(global_object);
JS::Value rejection_value;
@ -172,7 +174,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
if (result.is_error())
promise->reject(*result.release_error().value());
else
promise->fulfill(vm.heap().allocate<WebAssemblyModuleObject>(global_object, global_object, result.release_value()));
promise->fulfill(vm.heap().allocate<WebAssemblyModuleObject>(global_object, realm, result.release_value()));
return promise;
}
@ -317,6 +319,8 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
{
auto& realm = *global_object.associated_realm();
// FIXME: This shouldn't block!
auto buffer_or_error = vm.argument(0).to_object(global_object);
auto promise = JS::Promise::create(global_object);
@ -350,10 +354,10 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
if (result.is_error()) {
promise->reject(*result.release_error().value());
} else {
auto instance_object = vm.heap().allocate<WebAssemblyInstanceObject>(global_object, global_object, result.release_value());
auto instance_object = vm.heap().allocate<WebAssemblyInstanceObject>(global_object, realm, result.release_value());
if (should_return_module) {
auto object = JS::Object::create(global_object, nullptr);
object->define_direct_property("module", vm.heap().allocate<WebAssemblyModuleObject>(global_object, global_object, s_compiled_modules.size() - 1), JS::default_attributes);
object->define_direct_property("module", vm.heap().allocate<WebAssemblyModuleObject>(global_object, realm, s_compiled_modules.size() - 1), JS::default_attributes);
object->define_direct_property("instance", instance_object, JS::default_attributes);
promise->fulfill(object);
} else {
@ -477,8 +481,8 @@ JS::NativeFunction* create_native_function(JS::GlobalObject& global_object, Wasm
return function;
}
WebAssemblyMemoryObject::WebAssemblyMemoryObject(JS::GlobalObject& global_object, Wasm::MemoryAddress address)
: Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<WebAssemblyMemoryPrototype>("WebAssemblyMemoryPrototype"))
WebAssemblyMemoryObject::WebAssemblyMemoryObject(JS::Realm& realm, Wasm::MemoryAddress address)
: Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<WebAssemblyMemoryPrototype>("WebAssemblyMemoryPrototype"))
, m_address(address)
{
}

View file

@ -23,7 +23,7 @@ class WebAssemblyObject final : public JS::Object {
JS_OBJECT(WebAssemblyObject, JS::Object);
public:
explicit WebAssemblyObject(JS::GlobalObject&);
explicit WebAssemblyObject(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~WebAssemblyObject() override = default;
@ -69,7 +69,7 @@ class WebAssemblyMemoryObject final : public JS::Object {
JS_OBJECT(WebAssemblyMemoryObject, JS::Object);
public:
explicit WebAssemblyMemoryObject(JS::GlobalObject&, Wasm::MemoryAddress);
WebAssemblyMemoryObject(JS::Realm&, Wasm::MemoryAddress);
virtual ~WebAssemblyMemoryObject() override = default;
auto address() const { return m_address; }

View file

@ -14,8 +14,8 @@
namespace Web::Bindings {
WebAssemblyTableConstructor::WebAssemblyTableConstructor(JS::GlobalObject& global_object)
: NativeFunction(*global_object.function_prototype())
WebAssemblyTableConstructor::WebAssemblyTableConstructor(JS::Realm& realm)
: NativeFunction(*realm.global_object().function_prototype())
{
}
@ -30,6 +30,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto descriptor = TRY(vm.argument(0).to_object(global_object));
auto element_value = TRY(descriptor->get("element"));
@ -77,7 +78,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
for (auto& element : table.elements())
element = reference;
return vm.heap().allocate<WebAssemblyTableObject>(global_object, global_object, *address);
return vm.heap().allocate<WebAssemblyTableObject>(global_object, realm, *address);
}
void WebAssemblyTableConstructor::initialize(JS::GlobalObject& global_object)

View file

@ -14,7 +14,7 @@ class WebAssemblyTableConstructor : public JS::NativeFunction {
JS_OBJECT(WebAssemblyTableConstructor, JS::NativeFunction);
public:
explicit WebAssemblyTableConstructor(JS::GlobalObject&);
explicit WebAssemblyTableConstructor(JS::Realm&);
virtual void initialize(JS::GlobalObject&) override;
virtual ~WebAssemblyTableConstructor() override;

View file

@ -9,8 +9,8 @@
namespace Web::Bindings {
WebAssemblyTableObject::WebAssemblyTableObject(JS::GlobalObject& global_object, Wasm::TableAddress address)
: Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<WebAssemblyTablePrototype>("WebAssemblyTablePrototype"))
WebAssemblyTableObject::WebAssemblyTableObject(JS::Realm& realm, Wasm::TableAddress address)
: Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<WebAssemblyTablePrototype>("WebAssemblyTablePrototype"))
, m_address(address)
{
}

View file

@ -18,7 +18,7 @@ class WebAssemblyTableObject final : public JS::Object {
JS_OBJECT(WebAssemblyTableObject, Object);
public:
explicit WebAssemblyTableObject(JS::GlobalObject&, Wasm::TableAddress);
WebAssemblyTableObject(JS::Realm&, Wasm::TableAddress);
virtual ~WebAssemblyTableObject() override = default;
Wasm::TableAddress address() const { return m_address; }

View file

@ -19,8 +19,8 @@ class WebAssemblyTablePrototype final : public JS::Object {
JS_OBJECT(WebAssemblyTablePrototype, JS::Object);
public:
explicit WebAssemblyTablePrototype(JS::GlobalObject& global_object)
: JS::Object(*global_object.object_prototype())
explicit WebAssemblyTablePrototype(JS::Realm& realm)
: JS::Object(*realm.global_object().object_prototype())
{
}