LibJS: Fix Promise constructor reject function argument
If calling the executor function throws an exception, the return value
of `vm.call()` will be an empty value, which we then passed as an
argument to the reject function, which is incorrect - what it actually
needs is the exception value. This stems from a misunderstanding of the
spec I had at the time of implementing this - in their case, the
exception value is part of the completion record returned by Call().
This error was previously masked as we would use a fallback
(`value_or(js_undefined())` for the empty value argument, but that was
removed in 57f7e6e
.
Fixes #8447.
This commit is contained in:
parent
fe9dc47320
commit
073071c634
Notes:
sideshowbarker
2024-07-18 10:23:28 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/073071c634a Pull-request: https://github.com/SerenityOS/serenity/pull/8454 Issue: https://github.com/SerenityOS/serenity/issues/8447 Reviewed-by: https://github.com/IdanHo ✅
1 changed files with 3 additions and 3 deletions
|
@ -68,11 +68,11 @@ Value PromiseConstructor::construct(FunctionObject& new_target)
|
|||
|
||||
auto [resolve_function, reject_function] = promise->create_resolving_functions();
|
||||
|
||||
auto completion_value = vm.call(executor.as_function(), js_undefined(), &resolve_function, &reject_function);
|
||||
if (vm.exception()) {
|
||||
(void)vm.call(executor.as_function(), js_undefined(), &resolve_function, &reject_function);
|
||||
if (auto* exception = vm.exception()) {
|
||||
vm.clear_exception();
|
||||
vm.stop_unwind();
|
||||
[[maybe_unused]] auto result = vm.call(reject_function, js_undefined(), completion_value);
|
||||
(void)vm.call(reject_function, js_undefined(), exception->value());
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue