|
@@ -99,8 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
|
|
// 6. Else,
|
|
|
else {
|
|
|
// a. Let thenFinallyClosure be a new Abstract Closure with parameters (value) that captures onFinally and C and performs the following steps when called:
|
|
|
- // b. Let thenFinally be ! CreateBuiltinFunction(thenFinallyClosure, 1, "", « »).
|
|
|
- auto* then_finally_function = NativeFunction::create(global_object, "", [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
|
|
+ auto then_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
|
|
auto& constructor = const_cast<FunctionObject&>(*constructor_handle.cell());
|
|
|
auto& on_finally = const_cast<FunctionObject&>(*on_finally_handle.cell());
|
|
|
auto value = vm.argument(0);
|
|
@@ -112,21 +111,23 @@ 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:
|
|
|
- // iv. Let valueThunk be ! CreateBuiltinFunction(returnValue, 0, "", « »).
|
|
|
- auto* value_thunk = NativeFunction::create(global_object, "", [value](auto&, auto&) -> ThrowCompletionOr<Value> {
|
|
|
+ auto return_value = [value](auto&, auto&) -> ThrowCompletionOr<Value> {
|
|
|
// 1. Return value.
|
|
|
return value;
|
|
|
- });
|
|
|
+ };
|
|
|
+
|
|
|
+ // iv. Let valueThunk be ! CreateBuiltinFunction(returnValue, 0, "", « »).
|
|
|
+ auto* value_thunk = NativeFunction::create(global_object, move(return_value), 0, "");
|
|
|
|
|
|
// v. Return ? Invoke(promise, "then", « valueThunk »).
|
|
|
return TRY(Value(promise).invoke(global_object, vm.names.then, value_thunk));
|
|
|
- });
|
|
|
- then_finally_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
|
|
|
- then_finally = Value(then_finally_function);
|
|
|
+ };
|
|
|
+
|
|
|
+ // b. Let thenFinally be ! CreateBuiltinFunction(thenFinallyClosure, 1, "", « »).
|
|
|
+ then_finally = NativeFunction::create(global_object, move(then_finally_closure), 1, "");
|
|
|
|
|
|
// c. Let catchFinallyClosure be a new Abstract Closure with parameters (reason) that captures onFinally and C and performs the following steps when called:
|
|
|
- // d. Let catchFinally be ! CreateBuiltinFunction(catchFinallyClosure, 1, "", « »).
|
|
|
- auto* catch_finally_function = NativeFunction::create(global_object, "", [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
|
|
+ auto catch_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
|
|
auto& constructor = const_cast<FunctionObject&>(*constructor_handle.cell());
|
|
|
auto& on_finally = const_cast<FunctionObject&>(*on_finally_handle.cell());
|
|
|
auto reason = vm.argument(0);
|
|
@@ -137,17 +138,21 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
|
|
// ii. Let promise be ? PromiseResolve(C, result).
|
|
|
auto* promise = TRY(promise_resolve(global_object, constructor, result));
|
|
|
|
|
|
- // iv. Let thrower be ! CreateBuiltinFunction(throwReason, 0, "", « »).
|
|
|
- auto* thrower = NativeFunction::create(global_object, "", [reason](auto&, auto&) -> ThrowCompletionOr<Value> {
|
|
|
+ // 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> {
|
|
|
// 1. Return ThrowCompletion(reason).
|
|
|
return throw_completion(reason);
|
|
|
- });
|
|
|
+ };
|
|
|
+
|
|
|
+ // iv. Let thrower be ! CreateBuiltinFunction(throwReason, 0, "", « »).
|
|
|
+ auto* thrower = NativeFunction::create(global_object, move(throw_reason), 0, "");
|
|
|
|
|
|
// v. Return ? Invoke(promise, "then", « thrower »).
|
|
|
return TRY(Value(promise).invoke(global_object, vm.names.then, thrower));
|
|
|
- });
|
|
|
- catch_finally_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
|
|
|
- catch_finally = Value(catch_finally_function);
|
|
|
+ };
|
|
|
+
|
|
|
+ // d. Let catchFinally be ! CreateBuiltinFunction(catchFinallyClosure, 1, "", « »).
|
|
|
+ catch_finally = NativeFunction::create(global_object, move(catch_finally_closure), 1, "");
|
|
|
}
|
|
|
|
|
|
// 7. Return ? Invoke(promise, "then", « thenFinally, catchFinally »).
|