Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: src/builtins/builtins-promise.cc

Issue 2575313002: [promisehook] Implement PromiseHook (Closed)
Patch Set: add tests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/builtins/builtins-promise.cc
diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc
index 829a0b64b152271d04596a48945b00699233220a..16cfc9fc2423367aca0e0754779a3445498d73ff 100644
--- a/src/builtins/builtins-promise.cc
+++ b/src/builtins/builtins-promise.cc
@@ -29,6 +29,12 @@ BUILTIN(PromiseRejectClosure) {
handle(PromiseUtils::GetDebugEvent(context), isolate);
MaybeHandle<Object> maybe_result;
Handle<Object> argv[] = {promise, value, debug_event};
+
+ if (isolate->IsPromiseHookEnabled()) {
+ isolate->RunPromiseHook(PromiseHookType::kResolve, promise,
+ isolate->factory()->undefined_value());
+ }
+
RETURN_FAILURE_ON_EXCEPTION(
isolate, Execution::Call(isolate, isolate->promise_internal_reject(),
isolate->factory()->undefined_value(),
@@ -98,6 +104,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 +190,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 +218,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 +629,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);
}
@@ -846,6 +871,12 @@ void Builtins::Generate_PromiseResolveClosure(
Node* const promise = a.LoadFixedArrayElement(
context, a.IntPtrConstant(PromiseUtils::kPromiseSlot));
+ Label run_resolve(&a);
+ a.GotoUnless(a.IsPromiseHookEnabled(), &run_resolve);
+ a.CallRuntime(Runtime::kPromiseHookResolve, context, promise);
+ a.Goto(&run_resolve);
+
+ a.Bind(&run_resolve);
InternalResolvePromise(&a, context, promise, value, &out);
a.Bind(&out);
@@ -909,6 +940,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);
@@ -926,11 +958,15 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
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);
+ debug_pop(&a), promisehook_after(&a);
+
+ a.GotoUnless(a.IsPromiseHookEnabled(), &debug_push);
+ a.CallRuntime(Runtime::kPromiseHookBefore, context, promise);
+ a.Goto(&debug_push);
a.Bind(&debug_push);
{
+ a.GotoUnless(is_debug_active, &run_handler);
a.CallRuntime(Runtime::kDebugPushPromise, context, deferred_promise);
a.Goto(&run_handler);
}
@@ -953,14 +989,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 +1011,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);
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-stub-assembler.cc » ('j') | src/isolate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698