summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-10-12 19:24:57 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-13 09:55:10 +0100
commit52976bfac675f9166fd1a9bf0bf6082e4615a086 (patch)
tree7cb7b7971db2f4df59472b7887b1304c38b94e30 /Tests
parent9eb065a1f62f34f62f2484139cf3063ef42565dd (diff)
downloadserenity-52976bfac675f9166fd1a9bf0bf6082e4615a086.zip
LibJS: Convert to_object() to ThrowCompletionOr
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibJS/test-js.cpp8
-rw-r--r--Tests/LibWasm/test-wasm.cpp18
2 files changed, 7 insertions, 19 deletions
diff --git a/Tests/LibJS/test-js.cpp b/Tests/LibJS/test-js.cpp
index de7b53156f..e83c1a548d 100644
--- a/Tests/LibJS/test-js.cpp
+++ b/Tests/LibJS/test-js.cpp
@@ -32,9 +32,7 @@ TESTJS_GLOBAL_FUNCTION(run_queued_promise_jobs, runQueuedPromiseJobs)
TESTJS_GLOBAL_FUNCTION(get_weak_set_size, getWeakSetSize)
{
- auto* object = vm.argument(0).to_object(global_object);
- if (!object)
- return {};
+ auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object));
if (!is<JS::WeakSet>(object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WeakSet");
return {};
@@ -45,9 +43,7 @@ TESTJS_GLOBAL_FUNCTION(get_weak_set_size, getWeakSetSize)
TESTJS_GLOBAL_FUNCTION(get_weak_map_size, getWeakMapSize)
{
- auto* object = vm.argument(0).to_object(global_object);
- if (!object)
- return {};
+ auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object));
if (!is<JS::WeakMap>(object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WeakMap");
return {};
diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp
index 8daf451312..0f6a8ad4ba 100644
--- a/Tests/LibWasm/test-wasm.cpp
+++ b/Tests/LibWasm/test-wasm.cpp
@@ -93,9 +93,7 @@ HashMap<Wasm::Linker::Name, Wasm::ExternValue> WebAssemblyModule::s_spec_test_na
TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
{
- auto object = vm.argument(0).to_object(global_object);
- if (vm.exception())
- return {};
+ auto* object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object));
if (!is<JS::Uint8Array>(object)) {
vm.throw_exception<JS::TypeError>(global_object, "Expected a Uint8Array argument to parse_webassembly_module");
return {};
@@ -139,17 +137,13 @@ TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
TESTJS_GLOBAL_FUNCTION(compare_typed_arrays, compareTypedArrays)
{
- auto lhs = vm.argument(0).to_object(global_object);
- if (vm.exception())
- return {};
+ auto* lhs = TRY_OR_DISCARD(vm.argument(0).to_object(global_object));
if (!is<JS::TypedArrayBase>(lhs)) {
vm.throw_exception<JS::TypeError>(global_object, "Expected a TypedArray");
return {};
}
auto& lhs_array = static_cast<JS::TypedArrayBase&>(*lhs);
- auto rhs = vm.argument(1).to_object(global_object);
- if (vm.exception())
- return {};
+ auto* rhs = TRY_OR_DISCARD(vm.argument(1).to_object(global_object));
if (!is<JS::TypedArrayBase>(rhs)) {
vm.throw_exception<JS::TypeError>(global_object, "Expected a TypedArray");
return {};
@@ -169,10 +163,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::get_export)
{
auto name = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
auto this_value = vm.this_value(global_object);
- auto object = this_value.to_object(global_object);
- if (vm.exception())
- return {};
- if (!object || !is<WebAssemblyModule>(object)) {
+ auto* object = TRY_OR_DISCARD(this_value.to_object(global_object));
+ if (!is<WebAssemblyModule>(object)) {
vm.throw_exception<JS::TypeError>(global_object, "Not a WebAssemblyModule");
return {};
}