diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-31 16:57:30 +0200 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-31 18:20:37 +0200 |
commit | f19512bf556816e784c9ec7ee3e0a83deff32f51 (patch) | |
tree | 6622e85c0d93149b262142d003bf50ab0e93cad6 /Userland/Libraries/LibWeb/WebAssembly | |
parent | c7c914800c67754e4187f4ae0b848a1afd16ac63 (diff) | |
download | serenity-f19512bf556816e784c9ec7ee3e0a83deff32f51.zip |
LibWeb: Convert WebAssemblyMemoryPrototype funcs to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibWeb/WebAssembly')
-rw-r--r-- | Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp | 32 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h | 4 |
2 files changed, 15 insertions, 21 deletions
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp index 29141bca4c..71783240f1 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp @@ -13,18 +13,16 @@ namespace Web::Bindings { void WebAssemblyMemoryPrototype::initialize(JS::GlobalObject& global_object) { Object::initialize(global_object); - define_old_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_accessor("buffer", buffer_getter, {}, 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* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object)); - if (!is<WebAssemblyMemoryObject>(this_object)) { - vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory"); - return {}; - } + auto page_count = TRY(vm.argument(0).to_u32(global_object)); + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is<WebAssemblyMemoryObject>(this_object)) + return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory"); auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object); auto address = memory_object->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(); auto previous_size = memory->size() / 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 {}; - } + if (!memory->grow(page_count * Wasm::Constants::page_size)) + return vm.throw_completion<JS::TypeError>(global_object, "Memory.grow() grows past the stated limit of the memory instance"); 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)); - if (!is<WebAssemblyMemoryObject>(this_object)) { - vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is<WebAssemblyMemoryObject>(this_object)) + return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory"); auto* memory_object = static_cast<WebAssemblyMemoryObject*>(this_object); auto address = memory_object->address(); auto* memory = WebAssemblyObject::s_abstract_machine.store().get(address); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h index 00f54c8692..74fd7b0322 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h @@ -27,8 +27,8 @@ public: virtual void initialize(JS::GlobalObject&) override; private: - JS_DECLARE_OLD_NATIVE_FUNCTION(grow); - JS_DECLARE_OLD_NATIVE_FUNCTION(buffer_getter); + JS_DECLARE_NATIVE_FUNCTION(grow); + JS_DECLARE_NATIVE_FUNCTION(buffer_getter); }; } |