mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 17:30:38 +00:00
LibJS: Convert GetPromiseResolve AO to ThrowCompletionOr
This is a bit ugly because, rather than simply wrapping the invocation to GetPromiseResolve with TRY(), we have to invoke the promise's reject method with any error. But this will be a bit cleaner in a subsequent commit to change how IfAbruptRejectPromise is invoked.
This commit is contained in:
parent
6d6cd87b7b
commit
9064491a47
Notes:
sideshowbarker
2024-07-18 02:06:17 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/9064491a47b Pull-request: https://github.com/SerenityOS/serenity/pull/10551 Reviewed-by: https://github.com/linusg ✅
1 changed files with 16 additions and 14 deletions
|
@ -22,16 +22,14 @@
|
|||
namespace JS {
|
||||
|
||||
// 27.2.4.1.1 GetPromiseResolve ( promiseConstructor ), https://tc39.es/ecma262/#sec-getpromiseresolve
|
||||
static Value get_promise_resolve(GlobalObject& global_object, Value constructor)
|
||||
static ThrowCompletionOr<Value> get_promise_resolve(GlobalObject& global_object, Value constructor)
|
||||
{
|
||||
VERIFY(constructor.is_constructor());
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
auto promise_resolve = TRY_OR_DISCARD(constructor.get(global_object, vm.names.resolve));
|
||||
if (!promise_resolve.is_function()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, promise_resolve.to_string_without_side_effects());
|
||||
return {};
|
||||
}
|
||||
auto promise_resolve = TRY(constructor.get(global_object, vm.names.resolve));
|
||||
if (!promise_resolve.is_function())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, promise_resolve.to_string_without_side_effects());
|
||||
|
||||
return promise_resolve;
|
||||
}
|
||||
|
@ -289,9 +287,10 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PromiseConstructor::all)
|
|||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
auto promise_resolve = get_promise_resolve(global_object, constructor);
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, promise_resolve, promise_capability); abrupt.has_value())
|
||||
auto promise_resolve_or_error = get_promise_resolve(global_object, constructor);
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, promise_resolve_or_error, promise_capability); abrupt.has_value())
|
||||
return abrupt.value();
|
||||
auto promise_resolve = promise_resolve_or_error.release_value();
|
||||
|
||||
auto iterator_record_or_error = get_iterator(global_object, vm.argument(0));
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, iterator_record_or_error, promise_capability); abrupt.has_value())
|
||||
|
@ -324,9 +323,10 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PromiseConstructor::all_settled)
|
|||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
auto promise_resolve = get_promise_resolve(global_object, constructor);
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, promise_resolve, promise_capability); abrupt.has_value())
|
||||
auto promise_resolve_or_error = get_promise_resolve(global_object, constructor);
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, promise_resolve_or_error, promise_capability); abrupt.has_value())
|
||||
return abrupt.value();
|
||||
auto promise_resolve = promise_resolve_or_error.release_value();
|
||||
|
||||
auto iterator_record_or_error = get_iterator(global_object, vm.argument(0));
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, iterator_record_or_error, promise_capability); abrupt.has_value())
|
||||
|
@ -359,9 +359,10 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PromiseConstructor::any)
|
|||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
auto promise_resolve = get_promise_resolve(global_object, constructor);
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, promise_resolve, promise_capability); abrupt.has_value())
|
||||
auto promise_resolve_or_error = get_promise_resolve(global_object, constructor);
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, promise_resolve_or_error, promise_capability); abrupt.has_value())
|
||||
return abrupt.value();
|
||||
auto promise_resolve = promise_resolve_or_error.release_value();
|
||||
|
||||
auto iterator_record_or_error = get_iterator(global_object, vm.argument(0));
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, iterator_record_or_error, promise_capability); abrupt.has_value())
|
||||
|
@ -394,9 +395,10 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(PromiseConstructor::race)
|
|||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
auto promise_resolve = get_promise_resolve(global_object, constructor);
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, promise_resolve, promise_capability); abrupt.has_value())
|
||||
auto promise_resolve_or_error = get_promise_resolve(global_object, constructor);
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, promise_resolve_or_error, promise_capability); abrupt.has_value())
|
||||
return abrupt.value();
|
||||
auto promise_resolve = promise_resolve_or_error.release_value();
|
||||
|
||||
auto iterator_record_or_error = get_iterator(global_object, vm.argument(0));
|
||||
if (auto abrupt = if_abrupt_reject_promise(global_object, iterator_record_or_error, promise_capability); abrupt.has_value())
|
||||
|
|
Loading…
Reference in a new issue