| Index: src/builtins/builtins-promise.cc
|
| diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc
|
| index 3d4f6c3a50a97cc562594214a60cc675688c02b7..6c03cbe972dcf09f2907698518dd7813fa2394cb 100644
|
| --- a/src/builtins/builtins-promise.cc
|
| +++ b/src/builtins/builtins-promise.cc
|
| @@ -24,11 +24,13 @@ BUILTIN(PromiseRejectClosure) {
|
|
|
| PromiseUtils::SetAlreadyVisited(context);
|
| Handle<Object> value = args.atOrUndefined(isolate, 1);
|
| - Handle<JSObject> promise = handle(PromiseUtils::GetPromise(context), isolate);
|
| + Handle<JSPromise> promise =
|
| + handle(PromiseUtils::GetPromise(context), isolate);
|
| Handle<Object> debug_event =
|
| handle(PromiseUtils::GetDebugEvent(context), isolate);
|
| MaybeHandle<Object> maybe_result;
|
| Handle<Object> argv[] = {promise, value, debug_event};
|
| +
|
| RETURN_FAILURE_ON_EXCEPTION(
|
| isolate, Execution::Call(isolate, isolate->promise_internal_reject(),
|
| isolate->factory()->undefined_value(),
|
| @@ -98,6 +100,9 @@ void Builtins::Generate_PromiseConstructor(
|
| {
|
| Node* const instance = a.AllocateJSPromise(context);
|
| var_result.Bind(instance);
|
| + a.GotoUnless(a.IsPromiseHookEnabled(), &init);
|
| + a.CallRuntime(Runtime::kPromiseHookInit, context, instance,
|
| + a.UndefinedConstant());
|
| a.Goto(&init);
|
| }
|
|
|
| @@ -181,17 +186,26 @@ void Builtins::Generate_PromiseConstructor(
|
| void Builtins::Generate_PromiseInternalConstructor(
|
| compiler::CodeAssemblerState* state) {
|
| typedef compiler::Node Node;
|
| + typedef CodeStubAssembler::Label Label;
|
| CodeStubAssembler a(state);
|
|
|
| - Node* const context = a.Parameter(3);
|
| + Node* const parent = a.Parameter(1);
|
| + Node* const context = a.Parameter(4);
|
| Node* const instance = a.AllocateJSPromise(context);
|
| a.PromiseInit(instance);
|
| +
|
| + Label out(&a);
|
| + a.GotoUnless(a.IsPromiseHookEnabled(), &out);
|
| + a.CallRuntime(Runtime::kPromiseHookInit, context, instance, parent);
|
| + a.Goto(&out);
|
| + a.Bind(&out);
|
| a.Return(instance);
|
| }
|
|
|
| void Builtins::Generate_PromiseCreateAndSet(
|
| compiler::CodeAssemblerState* state) {
|
| typedef compiler::Node Node;
|
| + typedef CodeStubAssembler::Label Label;
|
| CodeStubAssembler a(state);
|
|
|
| Node* const status = a.Parameter(1);
|
| @@ -200,6 +214,13 @@ void Builtins::Generate_PromiseCreateAndSet(
|
|
|
| Node* const instance = a.AllocateJSPromise(context);
|
| a.PromiseSet(instance, status, result);
|
| +
|
| + Label out(&a);
|
| + a.GotoUnless(a.IsPromiseHookEnabled(), &out);
|
| + a.CallRuntime(Runtime::kPromiseHookInit, context, instance,
|
| + a.UndefinedConstant());
|
| + a.Goto(&out);
|
| + a.Bind(&out);
|
| a.Return(instance);
|
| }
|
|
|
| @@ -604,7 +625,7 @@ void Builtins::Generate_PromiseThen(compiler::CodeAssemblerState* state) {
|
| native_context, Context::INTERNAL_PROMISE_CAPABILITY_INDEX);
|
| Node* const capability =
|
| a.CallJS(call_callable, context, promise_internal_capability,
|
| - a.UndefinedConstant());
|
| + a.UndefinedConstant(), promise);
|
| var_deferred.Bind(capability);
|
| a.Goto(&perform_promise_then);
|
| }
|
| @@ -677,6 +698,12 @@ void InternalResolvePromise(CodeStubAssembler* a, compiler::Node* context,
|
| Label do_enqueue(a), fulfill(a), if_cycle(a, Label::kDeferred),
|
| if_rejectpromise(a, Label::kDeferred);
|
|
|
| + Label cycle_check(a);
|
| + a->GotoUnless(a->IsPromiseHookEnabled(), &cycle_check);
|
| + a->CallRuntime(Runtime::kPromiseHookResolve, context, promise);
|
| + a->Goto(&cycle_check);
|
| +
|
| + a->Bind(&cycle_check);
|
| // 6. If SameValue(resolution, promise) is true, then
|
| a->GotoIf(a->SameValue(promise, result, context), &if_cycle);
|
|
|
| @@ -909,6 +936,7 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
|
| typedef CodeStubAssembler::Label Label;
|
| typedef CodeStubAssembler::Variable Variable;
|
|
|
| + Node* const promise = a.Parameter(1);
|
| Node* const value = a.Parameter(2);
|
| Node* const handler = a.Parameter(3);
|
| Node* const deferred = a.Parameter(4);
|
| @@ -925,13 +953,17 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
|
| Variable var_reason(&a, MachineRepresentation::kTagged);
|
|
|
| Node* const is_debug_active = a.IsDebugActive();
|
| - Label run_handler(&a), if_rejectpromise(&a), debug_push(&a, Label::kDeferred),
|
| - debug_pop(&a, Label::kDeferred);
|
| - a.Branch(is_debug_active, &debug_push, &run_handler);
|
| + Label run_handler(&a), if_rejectpromise(&a), promisehook_before(&a),
|
| + debug_pop(&a), promisehook_after(&a);
|
|
|
| - a.Bind(&debug_push);
|
| + a.GotoUnless(is_debug_active, &promisehook_before);
|
| + a.CallRuntime(Runtime::kDebugPushPromise, context, deferred_promise);
|
| + a.Goto(&promisehook_before);
|
| +
|
| + a.Bind(&promisehook_before);
|
| {
|
| - a.CallRuntime(Runtime::kDebugPushPromise, context, deferred_promise);
|
| + a.GotoUnless(a.IsPromiseHookEnabled(), &run_handler);
|
| + a.CallRuntime(Runtime::kPromiseHookBefore, context, promise);
|
| a.Goto(&run_handler);
|
| }
|
|
|
| @@ -953,14 +985,15 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
|
| a.Branch(a.IsUndefined(on_resolve), &if_internalhandler, &if_customhandler);
|
|
|
| a.Bind(&if_internalhandler);
|
| - InternalResolvePromise(&a, context, deferred_promise, result, &debug_pop);
|
| + InternalResolvePromise(&a, context, deferred_promise, result,
|
| + &promisehook_after);
|
|
|
| a.Bind(&if_customhandler);
|
| {
|
| Node* const maybe_exception = a.CallJS(call_callable, context, on_resolve,
|
| a.UndefinedConstant(), result);
|
| a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason);
|
| - a.Goto(&debug_pop);
|
| + a.Goto(&promisehook_after);
|
| }
|
| }
|
|
|
| @@ -974,13 +1007,19 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
|
| Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate);
|
| a.CallStub(promise_handle_reject, context, deferred_promise, on_reject,
|
| var_reason.value());
|
| + a.Goto(&promisehook_after);
|
| + }
|
| +
|
| + a.Bind(&promisehook_after);
|
| + {
|
| + a.GotoUnless(a.IsPromiseHookEnabled(), &debug_pop);
|
| + a.CallRuntime(Runtime::kPromiseHookAfter, context, promise);
|
| a.Goto(&debug_pop);
|
| }
|
|
|
| a.Bind(&debug_pop);
|
| {
|
| Label out(&a);
|
| -
|
| a.GotoUnless(is_debug_active, &out);
|
| a.CallRuntime(Runtime::kDebugPopPromise, context);
|
| a.Goto(&out);
|
|
|