mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
LibWeb: Convert WebAssemblyMemoryPrototype funcs to ThrowCompletionOr
This commit is contained in:
parent
c7c914800c
commit
f19512bf55
2 changed files with 15 additions and 21 deletions
|
@ -13,18 +13,16 @@ namespace Web::Bindings {
|
||||||
void WebAssemblyMemoryPrototype::initialize(JS::GlobalObject& global_object)
|
void WebAssemblyMemoryPrototype::initialize(JS::GlobalObject& global_object)
|
||||||
{
|
{
|
||||||
Object::initialize(global_object);
|
Object::initialize(global_object);
|
||||||
define_old_native_accessor("buffer", buffer_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
define_native_accessor("buffer", buffer_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||||
define_old_native_function("grow", grow, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
define_native_function("grow", grow, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
|
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
|
||||||
{
|
{
|
||||||
auto page_count = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object));
|
auto page_count = TRY(vm.argument(0).to_u32(global_object));
|
||||||
auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
|
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
|
||||||
if (!is<WebAssemblyMemoryObject>(this_object)) {
|
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||||
return {};
|
|
||||||
}
|
|
||||||
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
||||||
auto address = memory_object->address();
|
auto address = memory_object->address();
|
||||||
auto* memory = WebAssemblyObject::s_abstract_machine.store().get(address);
|
auto* memory = WebAssemblyObject::s_abstract_machine.store().get(address);
|
||||||
|
@ -32,21 +30,17 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
|
|
||||||
auto previous_size = memory->size() / Wasm::Constants::page_size;
|
auto previous_size = memory->size() / Wasm::Constants::page_size;
|
||||||
if (!memory->grow(page_count * Wasm::Constants::page_size)) {
|
if (!memory->grow(page_count * Wasm::Constants::page_size))
|
||||||
vm.throw_exception<JS::TypeError>(global_object, "Memory.grow() grows past the stated limit of the memory instance");
|
return vm.throw_completion<JS::TypeError>(global_object, "Memory.grow() grows past the stated limit of the memory instance");
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return JS::Value(static_cast<u32>(previous_size));
|
return JS::Value(static_cast<u32>(previous_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
|
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
|
||||||
{
|
{
|
||||||
auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
|
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
|
||||||
if (!is<WebAssemblyMemoryObject>(this_object)) {
|
if (!is<WebAssemblyMemoryObject>(this_object))
|
||||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
|
||||||
return {};
|
|
||||||
}
|
|
||||||
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object);
|
||||||
auto address = memory_object->address();
|
auto address = memory_object->address();
|
||||||
auto* memory = WebAssemblyObject::s_abstract_machine.store().get(address);
|
auto* memory = WebAssemblyObject::s_abstract_machine.store().get(address);
|
||||||
|
|
|
@ -27,8 +27,8 @@ public:
|
||||||
virtual void initialize(JS::GlobalObject&) override;
|
virtual void initialize(JS::GlobalObject&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(grow);
|
JS_DECLARE_NATIVE_FUNCTION(grow);
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(buffer_getter);
|
JS_DECLARE_NATIVE_FUNCTION(buffer_getter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue