diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-17 23:43:29 +0300 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-18 08:01:38 +0300 |
commit | cc94bba5c0461eebeb13a063c844330b0234e0bd (patch) | |
tree | ef837c94a8d60e7a04d65cf1e52ea54c3799afb4 /Userland/Libraries/LibWeb | |
parent | f6a5ff7b003930a1994c0f4c4a1c4b1da7c7123d (diff) | |
download | serenity-cc94bba5c0461eebeb13a063c844330b0234e0bd.zip |
LibJS: Convert to_u32() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibWeb')
5 files changed, 13 insertions, 34 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp index 46ec3ffaeb..3260bba7cc 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -47,16 +47,12 @@ JS::Value ImageConstructor::construct(FunctionObject&) auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML); if (vm().argument_count() > 0) { - u32 width = vm().argument(0).to_u32(global_object()); - if (vm().exception()) - return {}; + u32 width = TRY_OR_DISCARD(vm().argument(0).to_u32(global_object())); image_element->set_attribute(HTML::AttributeNames::width, String::formatted("{}", width)); } if (vm().argument_count() > 1) { - u32 height = vm().argument(1).to_u32(global_object()); - if (vm().exception()) - return {}; + u32 height = TRY_OR_DISCARD(vm().argument(1).to_u32(global_object())); image_element->set_attribute(HTML::AttributeNames::height, String::formatted("{}", height)); } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp index 6546d01860..25bf3cbc5a 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp @@ -41,17 +41,12 @@ JS::Value WebAssemblyMemoryConstructor::construct(FunctionObject&) return {}; } - auto initial = initial_value.to_u32(global_object); - if (vm.exception()) - return {}; + auto initial = TRY_OR_DISCARD(initial_value.to_u32(global_object)); Optional<u32> maximum; - if (!maximum_value.is_empty()) { - maximum = maximum_value.to_u32(global_object); - if (vm.exception()) - return {}; - } + if (!maximum_value.is_empty()) + maximum = TRY_OR_DISCARD(maximum_value.to_u32(global_object)); auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::MemoryType { Wasm::Limits { initial, maximum } }); if (!address.has_value()) { diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp index e16abbf0b0..bc4020ce7a 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp @@ -19,9 +19,7 @@ void WebAssemblyMemoryPrototype::initialize(JS::GlobalObject& global_object) JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow) { - auto page_count = vm.argument(0).to_u32(global_object); - if (vm.exception()) - return {}; + 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"); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp index dc58bf4b42..6399af78f9 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp @@ -56,17 +56,12 @@ JS::Value WebAssemblyTableConstructor::construct(FunctionObject&) auto initial_value = TRY_OR_DISCARD(descriptor->get("initial")); auto maximum_value = TRY_OR_DISCARD(descriptor->get("maximum")); - auto initial = initial_value.to_u32(global_object); - if (vm.exception()) - return {}; + auto initial = TRY_OR_DISCARD(initial_value.to_u32(global_object)); Optional<u32> maximum; - if (!maximum_value.is_undefined()) { - maximum = maximum_value.to_u32(global_object); - if (vm.exception()) - return {}; - } + if (!maximum_value.is_undefined()) + maximum = TRY_OR_DISCARD(maximum_value.to_u32(global_object)); if (maximum.has_value() && maximum.value() < initial) { vm.throw_exception<JS::RangeError>(global_object, "maximum should be larger than or equal to initial"); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp index f8d2381007..7493579e2e 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp @@ -21,9 +21,8 @@ void WebAssemblyTablePrototype::initialize(JS::GlobalObject& global_object) JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow) { - auto delta = vm.argument(0).to_u32(global_object); - if (vm.exception()) - return {}; + auto delta = 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<WebAssemblyTableObject>(this_object)) { vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table"); @@ -59,9 +58,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow) JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get) { - auto index = vm.argument(0).to_u32(global_object); - if (vm.exception()) - return {}; + auto index = 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<WebAssemblyTableObject>(this_object)) { @@ -89,9 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get) JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set) { - auto index = vm.argument(0).to_u32(global_object); - if (vm.exception()) - return {}; + auto index = 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<WebAssemblyTableObject>(this_object)) { |