1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:37:35 +00:00

LibJS: Capture values as handles in Promise.prototype.finally callbacks

This commit is contained in:
Linus Groh 2022-02-20 22:16:06 +00:00
parent 47cdd90836
commit 7feeb2df0d

View file

@ -111,9 +111,9 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
auto* promise = TRY(promise_resolve(global_object, constructor, result));
// iii. Let returnValue be a new Abstract Closure with no parameters that captures value and performs the following steps when called:
auto return_value = [value](auto&, auto&) -> ThrowCompletionOr<Value> {
auto return_value = [value_handle = make_handle(value)](auto&, auto&) -> ThrowCompletionOr<Value> {
// 1. Return value.
return value;
return value_handle.value();
};
// iv. Let valueThunk be ! CreateBuiltinFunction(returnValue, 0, "", « »).
@ -139,9 +139,9 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
auto* promise = TRY(promise_resolve(global_object, constructor, result));
// iii. Let throwReason be a new Abstract Closure with no parameters that captures reason and performs the following steps when called:
auto throw_reason = [reason](auto&, auto&) -> ThrowCompletionOr<Value> {
auto throw_reason = [reason_handle = make_handle(reason)](auto&, auto&) -> ThrowCompletionOr<Value> {
// 1. Return ThrowCompletion(reason).
return throw_completion(reason);
return throw_completion(reason_handle.value());
};
// iv. Let thrower be ! CreateBuiltinFunction(throwReason, 0, "", « »).