mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:47:45 +00:00
LibJS+LibWeb: Replace GlobalObject with Realm in Heap::allocate<T>()
This is a continuation of the previous three commits. Now that create() receives the allocating realm, we can simply forward that to allocate(), which accounts for the majority of these changes. Additionally, we can get rid of the realm_from_global_object() in one place, with one more remaining in VM::throw_completion().
This commit is contained in:
parent
b99cc7d050
commit
e992a9f469
82 changed files with 148 additions and 148 deletions
|
@ -37,7 +37,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyInstanceConstructor::construct(Fun
|
|||
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, realm, result);
|
||||
return heap().allocate<WebAssemblyInstanceObject>(realm, realm, result);
|
||||
}
|
||||
|
||||
void WebAssemblyInstanceConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -44,7 +44,7 @@ void WebAssemblyInstanceObject::initialize(JS::Realm& realm)
|
|||
[&](Wasm::MemoryAddress const& address) {
|
||||
Optional<WebAssemblyMemoryObject*> object = cache.memory_instances.get(address);
|
||||
if (!object.has_value()) {
|
||||
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(realm.global_object(), realm, address);
|
||||
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(realm, realm, address);
|
||||
cache.memory_instances.set(address, *object);
|
||||
}
|
||||
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
|
|
|
@ -51,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, realm, *address);
|
||||
return vm.heap().allocate<WebAssemblyMemoryObject>(realm, realm, *address);
|
||||
}
|
||||
|
||||
void WebAssemblyMemoryConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -35,7 +35,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyModuleConstructor::construct(Funct
|
|||
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, realm, result);
|
||||
return heap().allocate<WebAssemblyModuleObject>(realm, realm, result);
|
||||
}
|
||||
|
||||
void WebAssemblyModuleConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -174,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, realm, result.release_value()));
|
||||
promise->fulfill(vm.heap().allocate<WebAssemblyModuleObject>(realm, realm, result.release_value()));
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
@ -354,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, realm, result.release_value());
|
||||
auto instance_object = vm.heap().allocate<WebAssemblyInstanceObject>(realm, realm, result.release_value());
|
||||
if (should_return_module) {
|
||||
auto object = JS::Object::create(realm, nullptr);
|
||||
object->define_direct_property("module", vm.heap().allocate<WebAssemblyModuleObject>(global_object, realm, s_compiled_modules.size() - 1), JS::default_attributes);
|
||||
object->define_direct_property("module", vm.heap().allocate<WebAssemblyModuleObject>(realm, realm, s_compiled_modules.size() - 1), JS::default_attributes);
|
||||
object->define_direct_property("instance", instance_object, JS::default_attributes);
|
||||
promise->fulfill(object);
|
||||
} else {
|
||||
|
@ -369,9 +369,10 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
|
|||
|
||||
JS::Value to_js_value(JS::GlobalObject& global_object, Wasm::Value& wasm_value)
|
||||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
switch (wasm_value.type().kind()) {
|
||||
case Wasm::ValueType::I64:
|
||||
return global_object.heap().allocate<JS::BigInt>(global_object, ::Crypto::SignedBigInteger::create_from(wasm_value.to<i64>().value()));
|
||||
return realm.heap().allocate<JS::BigInt>(realm, ::Crypto::SignedBigInteger::create_from(wasm_value.to<i64>().value()));
|
||||
case Wasm::ValueType::I32:
|
||||
return JS::Value(wasm_value.to<i32>().value());
|
||||
case Wasm::ValueType::F64:
|
||||
|
|
|
@ -78,7 +78,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
for (auto& element : table.elements())
|
||||
element = reference;
|
||||
|
||||
return vm.heap().allocate<WebAssemblyTableObject>(global_object, realm, *address);
|
||||
return vm.heap().allocate<WebAssemblyTableObject>(realm, realm, *address);
|
||||
}
|
||||
|
||||
void WebAssemblyTableConstructor::initialize(JS::Realm& realm)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue