From aa61110bdd6220d92d834b39f5856fb93d52c8a0 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sun, 31 Oct 2021 16:59:06 +0200 Subject: LibWeb: Convert WebAssemblyTablePrototype funcs to ThrowCompletionOr --- .../WebAssembly/WebAssemblyTablePrototype.cpp | 76 +++++++++------------- .../LibWeb/WebAssembly/WebAssemblyTablePrototype.h | 8 +-- 2 files changed, 35 insertions(+), 49 deletions(-) (limited to 'Userland/Libraries/LibWeb/WebAssembly') diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp index c65f959a62..ac9b8704e6 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp @@ -13,21 +13,19 @@ namespace Web::Bindings { void WebAssemblyTablePrototype::initialize(JS::GlobalObject& global_object) { Object::initialize(global_object); - define_old_native_accessor("length", length_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable); - define_old_native_function("grow", grow, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable); - define_old_native_function("get", get, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable); - define_old_native_function("set", set, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_native_accessor("length", length_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_native_function("grow", grow, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_native_function("get", get, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_native_function("set", set, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable); } -JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow) +JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow) { - auto delta = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object)); + auto delta = TRY(vm.argument(0).to_u32(global_object)); - auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object)); - if (!is(this_object)) { - vm.throw_exception(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is(this_object)) + return vm.throw_completion(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); auto* table_object = static_cast(this_object); auto address = table_object->address(); auto* table = WebAssemblyObject::s_abstract_machine.store().get(address); @@ -36,7 +34,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow) auto initial_size = table->elements().size(); auto value_value = vm.argument(1); - auto reference_value = TRY_OR_DISCARD([&]() -> JS::ThrowCompletionOr { + auto reference_value = TRY([&]() -> JS::ThrowCompletionOr { if (value_value.is_undefined()) return Wasm::Value(table->type().element_type(), 0ull); @@ -45,33 +43,27 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow) auto& reference = reference_value.value().get(); - if (!table->grow(delta, reference)) { - vm.throw_exception(global_object, "Failed to grow table"); - return {}; - } + if (!table->grow(delta, reference)) + return vm.throw_completion(global_object, "Failed to grow table"); return JS::Value(static_cast(initial_size)); } -JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::get) +JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get) { - auto index = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object)); + auto index = TRY(vm.argument(0).to_u32(global_object)); - auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object)); - if (!is(this_object)) { - vm.throw_exception(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is(this_object)) + return vm.throw_completion(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); auto* table_object = static_cast(this_object); auto address = table_object->address(); auto* table = WebAssemblyObject::s_abstract_machine.store().get(address); if (!table) return JS::js_undefined(); - if (table->elements().size() <= index) { - vm.throw_exception(global_object, "Table element index out of range"); - return {}; - } + if (table->elements().size() <= index) + return vm.throw_completion(global_object, "Table element index out of range"); auto& ref = table->elements()[index]; if (!ref.has_value()) @@ -81,28 +73,24 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::get) return to_js_value(global_object, wasm_value); } -JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::set) +JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set) { - auto index = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object)); + auto index = TRY(vm.argument(0).to_u32(global_object)); - auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object)); - if (!is(this_object)) { - vm.throw_exception(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is(this_object)) + return vm.throw_completion(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); auto* table_object = static_cast(this_object); auto address = table_object->address(); auto* table = WebAssemblyObject::s_abstract_machine.store().get(address); if (!table) return JS::js_undefined(); - if (table->elements().size() <= index) { - vm.throw_exception(global_object, "Table element index out of range"); - return {}; - } + if (table->elements().size() <= index) + return vm.throw_completion(global_object, "Table element index out of range"); auto value_value = vm.argument(1); - auto reference_value = TRY_OR_DISCARD([&]() -> JS::ThrowCompletionOr { + auto reference_value = TRY([&]() -> JS::ThrowCompletionOr { if (value_value.is_undefined()) return Wasm::Value(table->type().element_type(), 0ull); @@ -115,13 +103,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::set) return JS::js_undefined(); } -JS_DEFINE_OLD_NATIVE_FUNCTION(WebAssemblyTablePrototype::length_getter) +JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::length_getter) { - auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object)); - if (!is(this_object)) { - vm.throw_exception(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is(this_object)) + return vm.throw_completion(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); auto* table_object = static_cast(this_object); auto address = table_object->address(); auto* table = WebAssemblyObject::s_abstract_machine.store().get(address); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h index 9e034e70c0..e3075c63ae 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h @@ -27,10 +27,10 @@ public: virtual void initialize(JS::GlobalObject& global_object) override; private: - JS_DECLARE_OLD_NATIVE_FUNCTION(grow); - JS_DECLARE_OLD_NATIVE_FUNCTION(get); - JS_DECLARE_OLD_NATIVE_FUNCTION(set); - JS_DECLARE_OLD_NATIVE_FUNCTION(length_getter); + JS_DECLARE_NATIVE_FUNCTION(grow); + JS_DECLARE_NATIVE_FUNCTION(get); + JS_DECLARE_NATIVE_FUNCTION(set); + JS_DECLARE_NATIVE_FUNCTION(length_getter); }; } -- cgit v1.2.3