diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp index cda7c4de4df..dc2a79a26f6 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.cpp +++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp @@ -19,16 +19,16 @@ namespace JS { // 27.2.4.7.1 PromiseResolve ( C, x ), https://tc39.es/ecma262/#sec-promise-resolve -Object* promise_resolve(GlobalObject& global_object, Object& constructor, Value value) +ThrowCompletionOr promise_resolve(GlobalObject& global_object, Object& constructor, Value value) { auto& vm = global_object.vm(); if (value.is_object() && is(value.as_object())) { - auto value_constructor = TRY_OR_DISCARD(value.as_object().get(vm.names.constructor)); + auto value_constructor = TRY(value.as_object().get(vm.names.constructor)); if (same_value(value_constructor, &constructor)) return &static_cast(value.as_object()); } - auto promise_capability = TRY_OR_DISCARD(new_promise_capability(global_object, &constructor)); - [[maybe_unused]] auto result = TRY_OR_DISCARD(vm.call(*promise_capability.resolve, js_undefined(), value)); + auto promise_capability = TRY(new_promise_capability(global_object, &constructor)); + (void)TRY(vm.call(*promise_capability.resolve, js_undefined(), value)); return promise_capability.promise; } diff --git a/Userland/Libraries/LibJS/Runtime/Promise.h b/Userland/Libraries/LibJS/Runtime/Promise.h index 0f1c927c789..60db733a96e 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.h +++ b/Userland/Libraries/LibJS/Runtime/Promise.h @@ -11,7 +11,7 @@ namespace JS { -Object* promise_resolve(GlobalObject&, Object& constructor, Value); +ThrowCompletionOr promise_resolve(GlobalObject&, Object& constructor, Value); class Promise final : public Object { JS_OBJECT(Promise, Object); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index c0d231a5f0f..51407f1d8a1 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -357,7 +357,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PromiseConstructor::resolve) { auto* constructor = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object)); auto value = vm.argument(0); - return promise_resolve(global_object, *constructor, value); + return TRY_OR_DISCARD(promise_resolve(global_object, *constructor, value)); } // 27.2.4.8 get Promise [ @@species ], https://tc39.es/ecma262/#sec-get-promise-@@species diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp index 109deba9d2e..a0041bdee2d 100644 --- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp @@ -72,9 +72,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PromisePrototype::finally) auto& on_finally = const_cast(*on_finally_handle.cell()); auto value = vm.argument(0); auto result = TRY(vm.call(on_finally, js_undefined())); - auto* promise = promise_resolve(global_object, constructor, result); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto* promise = TRY(promise_resolve(global_object, constructor, result)); auto* value_thunk = NativeFunction::create(global_object, "", [value](auto&, auto&) -> ThrowCompletionOr { return value; }); @@ -88,9 +86,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PromisePrototype::finally) auto& on_finally = const_cast(*on_finally_handle.cell()); auto reason = vm.argument(0); auto result = TRY(vm.call(on_finally, js_undefined())); - auto* promise = promise_resolve(global_object, constructor, result); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto* promise = TRY(promise_resolve(global_object, constructor, result)); auto* thrower = NativeFunction::create(global_object, "", [reason](auto& vm, auto& global_object) -> ThrowCompletionOr { vm.throw_exception(global_object, reason); return throw_completion(reason);