Commit eec10a2f authored by Gus Caplan's avatar Gus Caplan Committed by Commit Bot

[promisehook] Add before/after hooks to thenable tasks

This will allow Node.js to properly track async context in thenables.

Change-Id: If441423789a78307a57ad7e645daabf551cddb57
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2215624Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Gus Caplan <me@gus.host>
Cr-Commit-Position: refs/heads/master@{#68207}
parent 1a60100a
......@@ -198,11 +198,18 @@ void MicrotaskQueueBuiltinsAssembler::RunSingleMicrotask(
const TNode<Object> thenable = LoadObjectField(
microtask, PromiseResolveThenableJobTask::kThenableOffset);
RunPromiseHook(Runtime::kPromiseHookBefore, microtask_context,
CAST(promise_to_resolve));
{
ScopedExceptionHandler handler(this, &if_exception, &var_exception);
CallBuiltin(Builtins::kPromiseResolveThenableJob, native_context,
promise_to_resolve, thenable, then);
}
RunPromiseHook(Runtime::kPromiseHookAfter, microtask_context,
CAST(promise_to_resolve));
RewindEnteredContext(saved_entered_context_count);
SetCurrentContext(current_context);
Goto(&done);
......
......@@ -16352,7 +16352,18 @@ TEST(PromiseHook) {
CHECK_EQ(v8::Promise::kPending, GetPromise("p")->State());
CompileRun("resolve(Promise.resolve(value));\n");
CHECK_EQ(v8::Promise::kFulfilled, GetPromise("p")->State());
CHECK_EQ(9, promise_hook_data->promise_hook_count);
CHECK_EQ(11, promise_hook_data->promise_hook_count);
promise_hook_data->Reset();
source =
"var p = Promise.resolve({\n"
" then(r) {\n"
" r();\n"
" }\n"
"});";
CompileRun(source);
CHECK_EQ(GetPromise("p")->State(), v8::Promise::kFulfilled);
CHECK_EQ(promise_hook_data->promise_hook_count, 5);
delete promise_hook_data;
isolate->SetPromiseHook(nullptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment