diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-31 16:59:06 +0200 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-31 18:20:37 +0200 |
commit | aa61110bdd6220d92d834b39f5856fb93d52c8a0 (patch) | |
tree | 86f0377d862c498d33c6ba5f4016594230ddd9d6 /Userland/Libraries/LibWeb | |
parent | f19512bf556816e784c9ec7ee3e0a83deff32f51 (diff) | |
download | serenity-aa61110bdd6220d92d834b39f5856fb93d52c8a0.zip |
LibWeb: Convert WebAssemblyTablePrototype funcs to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp | 76 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h | 8 |
2 files changed, 35 insertions, 49 deletions
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<WebAssemblyTableObject>(this_object)) { - vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is<WebAssemblyTableObject>(this_object)) + return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); auto* table_object = static_cast<WebAssemblyTableObject*>(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<Wasm::Value> { + auto reference_value = TRY([&]() -> JS::ThrowCompletionOr<Wasm::Value> { 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<Wasm::Reference>(); - if (!table->grow(delta, reference)) { - vm.throw_exception<JS::RangeError>(global_object, "Failed to grow table"); - return {}; - } + if (!table->grow(delta, reference)) + return vm.throw_completion<JS::RangeError>(global_object, "Failed to grow table"); return JS::Value(static_cast<u32>(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<WebAssemblyTableObject>(this_object)) { - vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is<WebAssemblyTableObject>(this_object)) + return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); auto* table_object = static_cast<WebAssemblyTableObject*>(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<JS::RangeError>(global_object, "Table element index out of range"); - return {}; - } + if (table->elements().size() <= index) + return vm.throw_completion<JS::RangeError>(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<WebAssemblyTableObject>(this_object)) { - vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is<WebAssemblyTableObject>(this_object)) + return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); auto* table_object = static_cast<WebAssemblyTableObject*>(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<JS::RangeError>(global_object, "Table element index out of range"); - return {}; - } + if (table->elements().size() <= index) + return vm.throw_completion<JS::RangeError>(global_object, "Table element index out of range"); auto value_value = vm.argument(1); - auto reference_value = TRY_OR_DISCARD([&]() -> JS::ThrowCompletionOr<Wasm::Value> { + auto reference_value = TRY([&]() -> JS::ThrowCompletionOr<Wasm::Value> { 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<WebAssemblyTableObject>(this_object)) { - vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); - return {}; - } + auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + if (!is<WebAssemblyTableObject>(this_object)) + return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); auto* table_object = static_cast<WebAssemblyTableObject*>(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); }; } |