mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:17:46 +00:00
LibJS: Replace GlobalObject with VM in Value AOs [Part 4/19]
This is where the fun begins. :^)
This commit is contained in:
parent
f6c4a0f5d0
commit
a022e548b8
129 changed files with 1230 additions and 1325 deletions
|
@ -32,7 +32,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyInstanceConstructor::construct(Fun
|
|||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* module_argument = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* module_argument = TRY(vm.argument(0).to_object(vm));
|
||||
if (!is<WebAssemblyModuleObject>(module_argument))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
|
||||
auto& module_object = static_cast<WebAssemblyModuleObject&>(*module_argument);
|
||||
|
|
|
@ -19,7 +19,7 @@ void WebAssemblyInstancePrototype::initialize(JS::Realm& realm)
|
|||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyInstancePrototype::exports_getter)
|
||||
{
|
||||
auto this_value = vm.this_value();
|
||||
auto* this_object = TRY(this_value.to_object(global_object));
|
||||
auto* this_object = TRY(this_value.to_object(vm));
|
||||
if (!is<WebAssemblyInstanceObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Instance");
|
||||
auto object = static_cast<WebAssemblyInstanceObject*>(this_object);
|
||||
|
|
|
@ -30,19 +30,19 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
|
|||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto descriptor = TRY(vm.argument(0).to_object(global_object));
|
||||
auto descriptor = TRY(vm.argument(0).to_object(vm));
|
||||
auto initial_value = TRY(descriptor->get("initial"));
|
||||
auto maximum_value = TRY(descriptor->get("maximum"));
|
||||
|
||||
if (!initial_value.is_number())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Number");
|
||||
|
||||
u32 initial = TRY(initial_value.to_u32(global_object));
|
||||
u32 initial = TRY(initial_value.to_u32(vm));
|
||||
|
||||
Optional<u32> maximum;
|
||||
|
||||
if (!maximum_value.is_undefined())
|
||||
maximum = TRY(maximum_value.to_u32(global_object));
|
||||
maximum = TRY(maximum_value.to_u32(vm));
|
||||
|
||||
auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::MemoryType { Wasm::Limits { initial, maximum } });
|
||||
if (!address.has_value())
|
||||
|
|
|
@ -19,8 +19,8 @@ void WebAssemblyMemoryPrototype::initialize(JS::Realm& realm)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
|
||||
{
|
||||
auto page_count = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto page_count = TRY(vm.argument(0).to_u32(vm));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
||||
|
@ -40,7 +40,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
|
|||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
||||
|
|
|
@ -32,7 +32,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyModuleConstructor::construct(Funct
|
|||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto* buffer_object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* buffer_object = TRY(vm.argument(0).to_object(vm));
|
||||
auto result = TRY(parse_module(global_object, buffer_object));
|
||||
|
||||
return heap().allocate<WebAssemblyModuleObject>(realm, realm, result);
|
||||
|
|
|
@ -92,7 +92,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::validate)
|
|||
{
|
||||
// 1. Let stableBytes be a copy of the bytes held by the buffer bytes.
|
||||
// Note: There's no need to copy the bytes here as the buffer data cannot change while we're compiling the module.
|
||||
auto buffer = TRY(vm.argument(0).to_object(global_object));
|
||||
auto buffer = TRY(vm.argument(0).to_object(vm));
|
||||
|
||||
// 2. Compile stableBytes as a WebAssembly module and store the results as module.
|
||||
auto maybe_module = parse_module(global_object, buffer);
|
||||
|
@ -159,7 +159,7 @@ 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);
|
||||
auto buffer_or_error = vm.argument(0).to_object(vm);
|
||||
JS::Value rejection_value;
|
||||
if (buffer_or_error.is_error())
|
||||
rejection_value = *buffer_or_error.throw_completion().value();
|
||||
|
@ -184,7 +184,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
HashMap<Wasm::Linker::Name, Wasm::ExternValue> resolved_imports;
|
||||
auto import_argument = vm.argument(1);
|
||||
if (!import_argument.is_undefined()) {
|
||||
auto* import_object = TRY(import_argument.to_object(global_object));
|
||||
auto* import_object = TRY(import_argument.to_object(vm));
|
||||
dbgln("Trying to resolve stuff because import object was specified");
|
||||
for (Wasm::Linker::Name const& import_name : linker.unresolved_imports()) {
|
||||
dbgln("Trying to resolve {}::{}", import_name.module, import_name.name);
|
||||
|
@ -192,7 +192,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
if (value_or_error.is_error())
|
||||
break;
|
||||
auto value = value_or_error.release_value();
|
||||
auto object_or_error = value.to_object(global_object);
|
||||
auto object_or_error = value.to_object(vm);
|
||||
if (object_or_error.is_error())
|
||||
break;
|
||||
auto* object = object_or_error.release_value();
|
||||
|
@ -322,7 +322,7 @@ 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 buffer_or_error = vm.argument(0).to_object(vm);
|
||||
auto promise = JS::Promise::create(realm);
|
||||
bool should_return_module = false;
|
||||
if (buffer_or_error.is_error()) {
|
||||
|
@ -398,7 +398,7 @@ JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::GlobalObject& global
|
|||
|
||||
switch (type.kind()) {
|
||||
case Wasm::ValueType::I64: {
|
||||
auto bigint = TRY(value.to_bigint(global_object));
|
||||
auto bigint = TRY(value.to_bigint(vm));
|
||||
auto value = bigint->big_integer().divided_by(two_64).remainder;
|
||||
VERIFY(value.unsigned_value().trimmed_length() <= 2);
|
||||
i64 integer = static_cast<i64>(value.unsigned_value().to_u64());
|
||||
|
@ -407,15 +407,15 @@ JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::GlobalObject& global
|
|||
return Wasm::Value { integer };
|
||||
}
|
||||
case Wasm::ValueType::I32: {
|
||||
auto _i32 = TRY(value.to_i32(global_object));
|
||||
auto _i32 = TRY(value.to_i32(vm));
|
||||
return Wasm::Value { static_cast<i32>(_i32) };
|
||||
}
|
||||
case Wasm::ValueType::F64: {
|
||||
auto number = TRY(value.to_double(global_object));
|
||||
auto number = TRY(value.to_double(vm));
|
||||
return Wasm::Value { static_cast<double>(number) };
|
||||
}
|
||||
case Wasm::ValueType::F32: {
|
||||
auto number = TRY(value.to_double(global_object));
|
||||
auto number = TRY(value.to_double(vm));
|
||||
return Wasm::Value { static_cast<float>(number) };
|
||||
}
|
||||
case Wasm::ValueType::FunctionReference:
|
||||
|
|
|
@ -32,7 +32,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
auto descriptor = TRY(vm.argument(0).to_object(global_object));
|
||||
auto descriptor = TRY(vm.argument(0).to_object(vm));
|
||||
auto element_value = TRY(descriptor->get("element"));
|
||||
if (!element_value.is_string())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidHint, element_value.to_string_without_side_effects());
|
||||
|
@ -50,12 +50,12 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
|
|||
auto initial_value = TRY(descriptor->get("initial"));
|
||||
auto maximum_value = TRY(descriptor->get("maximum"));
|
||||
|
||||
auto initial = TRY(initial_value.to_u32(global_object));
|
||||
auto initial = TRY(initial_value.to_u32(vm));
|
||||
|
||||
Optional<u32> maximum;
|
||||
|
||||
if (!maximum_value.is_undefined())
|
||||
maximum = TRY(maximum_value.to_u32(global_object));
|
||||
maximum = TRY(maximum_value.to_u32(vm));
|
||||
|
||||
if (maximum.has_value() && maximum.value() < initial)
|
||||
return vm.throw_completion<JS::RangeError>("maximum should be larger than or equal to initial");
|
||||
|
|
|
@ -21,9 +21,9 @@ void WebAssemblyTablePrototype::initialize(JS::Realm& realm)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
|
||||
{
|
||||
auto delta = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto delta = TRY(vm.argument(0).to_u32(vm));
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
|
@ -51,9 +51,9 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
|
||||
{
|
||||
auto index = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto index = TRY(vm.argument(0).to_u32(vm));
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
|
@ -75,9 +75,9 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
|
||||
{
|
||||
auto index = TRY(vm.argument(0).to_u32(global_object));
|
||||
auto index = TRY(vm.argument(0).to_u32(vm));
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
|
@ -105,7 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::length_getter)
|
||||
{
|
||||
auto* this_object = TRY(vm.this_value().to_object(global_object));
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
if (!is<WebAssemblyTableObject>(this_object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
|
||||
auto* table_object = static_cast<WebAssemblyTableObject*>(this_object);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue