Skip to content

Commit

Permalink
deps: V8: cherry-pick eec10a2fd8fa
Browse files Browse the repository at this point in the history
Original commit message:

    [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/+/2215624
    Reviewed-by: Camillo Bruni <cbruni@chromium.org>
    Reviewed-by: Sathya Gunasekaran  <gsathya@chromium.org>
    Commit-Queue: Gus Caplan <me@gus.host>
    Cr-Commit-Position: refs/heads/master@{#68207}

Refs: v8/v8@eec10a2

PR-URL: #33778
Backport-PR-URL: #35393
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
Qard authored and richardlau committed Oct 7, 2020
1 parent 020ba1a commit 3564424
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.58',
'v8_embedder_string': '-node.59',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
7 changes: 7 additions & 0 deletions deps/v8/src/builtins/builtins-internal-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,17 @@ TF_BUILTIN(RunMicrotasks, InternalBuiltinsAssembler) {
Node* const thenable = LoadObjectField(
microtask, PromiseResolveThenableJobTask::kThenableOffset);

RunPromiseHook(Runtime::kPromiseHookBefore, microtask_context,
CAST(promise_to_resolve));

Node* const result =
CallBuiltin(Builtins::kPromiseResolveThenableJob, native_context,
promise_to_resolve, thenable, then);
GotoIfException(result, &if_exception, &var_exception);

RunPromiseHook(Runtime::kPromiseHookAfter, microtask_context,
CAST(promise_to_resolve));

LeaveMicrotaskContext();
SetCurrentContext(current_context);
Goto(&loop_next);
Expand Down
13 changes: 12 additions & 1 deletion deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18771,7 +18771,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);
Expand Down

0 comments on commit 3564424

Please sign in to comment.