summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-10-02 23:52:27 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-03 20:14:03 +0100
commitb7e5f08e561696001d9b0ced8f3fe50caf186d2c (patch)
treedebbec2ad0557cc166acc7f5777b023b44db080e /Userland/Libraries/LibWeb
parent9b6c09e2c4ff79714dfecb4a98222bec9cc72b71 (diff)
downloadserenity-b7e5f08e561696001d9b0ced8f3fe50caf186d2c.zip
LibJS: Convert Object::get() to ThrowCompletionOr
To no one's surprise, this patch is pretty big - this is possibly the most used AO of all of them. Definitely worth it though.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObject.cpp24
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp4
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp10
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp19
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp4
6 files changed, 22 insertions, 41 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp
index 3b83bd69d2..057dd0000c 100644
--- a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp
@@ -28,7 +28,7 @@ void NavigatorObject::initialize(JS::GlobalObject& global_object)
define_direct_property("appCodeName", js_string(heap, "Mozilla"), attr);
define_direct_property("appName", js_string(heap, "Netscape"), attr);
define_direct_property("appVersion", js_string(heap, "4.0"), attr);
- define_direct_property("language", languages->get(0), attr);
+ define_direct_property("language", languages->get_without_side_effects(0), attr);
define_direct_property("languages", languages, attr);
define_direct_property("platform", js_string(heap, "SerenityOS"), attr);
define_direct_property("product", js_string(heap, "Gecko"), attr);
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
index b5264d8352..241b7f3320 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
@@ -609,21 +609,15 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll)
if (vm.exception())
return {};
- auto left = options->get("left");
- if (vm.exception())
- return {};
+ auto left = TRY_OR_DISCARD(options->get("left"));
if (!left.is_undefined())
x_value = left;
- auto top = options->get("top");
- if (vm.exception())
- return {};
+ auto top = TRY_OR_DISCARD(options->get("top"));
if (!top.is_undefined())
y_value = top;
- auto behavior_string_value = options->get("behavior");
- if (vm.exception())
- return {};
+ auto behavior_string_value = TRY_OR_DISCARD(options->get("behavior"));
if (!behavior_string_value.is_undefined())
behavior_string = behavior_string_value.to_string(global_object);
if (vm.exception())
@@ -684,16 +678,12 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
options->set("behavior", JS::js_string(vm, "auto"), ShouldThrowExceptions::No);
}
- auto left_value = options->get("left");
- if (vm.exception())
- return {};
+ auto left_value = TRY_OR_DISCARD(options->get("left"));
auto left = left_value.to_double(global_object);
if (vm.exception())
return {};
- auto top_value = options->get("top");
- if (vm.exception())
- return {};
+ auto top_value = TRY_OR_DISCARD(options->get("top"));
auto top = top_value.to_double(global_object);
if (vm.exception())
return {};
@@ -705,9 +695,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
left = left + current_scroll_position.x();
top = top + current_scroll_position.y();
- auto behavior_string_value = options->get("behavior");
- if (vm.exception())
- return {};
+ auto behavior_string_value = TRY_OR_DISCARD(options->get("behavior"));
auto behavior_string = behavior_string_value.is_undefined() ? "auto" : behavior_string_value.to_string(global_object);
if (vm.exception())
return {};
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp
index deb27bd3bf..703bbd47b4 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp
@@ -36,8 +36,8 @@ JS::Value WebAssemblyMemoryConstructor::construct(FunctionObject&)
if (vm.exception())
return {};
- auto initial_value = descriptor->get_without_side_effects("initial");
- auto maximum_value = descriptor->get_without_side_effects("maximum");
+ auto initial_value = TRY_OR_DISCARD(descriptor->get("initial"));
+ auto maximum_value = TRY_OR_DISCARD(descriptor->get("maximum"));
if (initial_value.is_empty()) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Number");
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index e95333b82c..bc12fc8277 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -164,16 +164,18 @@ Result<size_t, JS::Value> WebAssemblyObject::instantiate_module(Wasm::Module con
dbgln("Trying to resolve stuff because import object was specified");
for (const Wasm::Linker::Name& import_name : linker.unresolved_imports()) {
dbgln("Trying to resolve {}::{}", import_name.module, import_name.name);
- auto value = import_object->get(import_name.module);
- if (vm.exception())
+ auto value_or_error = import_object->get(import_name.module);
+ if (value_or_error.is_error())
break;
+ auto value = value_or_error.release_value();
auto object = value.to_object(global_object);
if (vm.exception())
break;
- auto import_ = object->get(import_name.name);
- if (vm.exception())
+ auto import_or_error = object->get(import_name.name);
+ if (import_or_error.is_error())
break;
+ auto import_ = import_or_error.release_value();
import_name.type.visit(
[&](Wasm::TypeIndex index) {
dbgln("Trying to resolve a function {}::{}, type index {}", import_name.module, import_name.name, index.value());
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp
index 480d2dea51..cfe8b67d05 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp
@@ -38,9 +38,7 @@ JS::Value WebAssemblyTableConstructor::construct(FunctionObject&)
if (vm.exception())
return {};
- auto element_value = descriptor->get("element");
- if (vm.exception())
- return {};
+ auto element_value = TRY_OR_DISCARD(descriptor->get("element"));
if (!element_value.is_string()) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::InvalidHint, element_value.to_string_without_side_effects());
return {};
@@ -58,12 +56,8 @@ JS::Value WebAssemblyTableConstructor::construct(FunctionObject&)
return {};
}
- auto initial_value = descriptor->get("initial");
- if (vm.exception())
- return {};
- auto maximum_value = descriptor->get("maximum");
- if (vm.exception())
- return {};
+ 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())
@@ -82,12 +76,9 @@ JS::Value WebAssemblyTableConstructor::construct(FunctionObject&)
return {};
}
- auto value_value = descriptor->get("value");
- if (vm.exception())
- return {};
-
+ auto value_value = TRY_OR_DISCARD(descriptor->get("value"));
auto reference_value = [&]() -> Optional<Wasm::Value> {
- if (value_value.is_empty() || value_value.is_undefined())
+ if (value_value.is_undefined())
return Wasm::Value(*reference_type, 0ull);
return to_webassembly_value(value_value, *reference_type, global_object);
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp
index 614c132228..a88d800a35 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp
@@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
auto initial_size = table->elements().size();
auto value_value = vm.argument(1);
auto reference_value = [&]() -> Optional<Wasm::Value> {
- if (value_value.is_empty() || value_value.is_undefined())
+ if (value_value.is_undefined())
return Wasm::Value(table->type().element_type(), 0ull);
return to_webassembly_value(value_value, table->type().element_type(), global_object);
@@ -111,7 +111,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
auto value_value = vm.argument(1);
auto reference_value = [&]() -> Optional<Wasm::Value> {
- if (value_value.is_empty() || value_value.is_undefined())
+ if (value_value.is_undefined())
return Wasm::Value(table->type().element_type(), 0ull);
return to_webassembly_value(value_value, table->type().element_type(), global_object);