From 04e4b4cf57274fd99b26304931bcf1ee36b17fec Mon Sep 17 00:00:00 2001 From: Stephen Belanger Date: Sat, 6 Jun 2020 14:13:16 -0700 Subject: [PATCH] deps: V8: cherry-pick eec10a2fd8fa MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sathya Gunasekaran Commit-Queue: Gus Caplan Cr-Commit-Position: refs/heads/master@{#68207} Refs: https://github.com/v8/v8/commit/eec10a2fd8fa4d0e7f5e32dedbd239d938a5dd87 PR-URL: https://github.com/nodejs/node/pull/33778 Reviewed-By: Anna Henningsen Reviewed-By: Michaël Zasso Reviewed-By: Gus Caplan Reviewed-By: Gerhard Stöbich Reviewed-By: Michael Dawson --- common.gypi | 2 +- .../v8/src/builtins/builtins-microtask-queue-gen.cc | 7 +++++++ deps/v8/test/cctest/test-api.cc | 13 ++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common.gypi b/common.gypi index 0932ebff5c4610..5e5307ffb49c7b 100644 --- a/common.gypi +++ b/common.gypi @@ -34,7 +34,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.39', + 'v8_embedder_string': '-node.40', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/builtins/builtins-microtask-queue-gen.cc b/deps/v8/src/builtins/builtins-microtask-queue-gen.cc index 427fd6edb65f71..b484fec9399d86 100644 --- a/deps/v8/src/builtins/builtins-microtask-queue-gen.cc +++ b/deps/v8/src/builtins/builtins-microtask-queue-gen.cc @@ -202,10 +202,17 @@ void MicrotaskQueueBuiltinsAssembler::RunSingleMicrotask( TNode const thenable = LoadObjectField( microtask, PromiseResolveThenableJobTask::kThenableOffset); + RunPromiseHook(Runtime::kPromiseHookBefore, microtask_context, + CAST(promise_to_resolve)); + TNode 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)); + RewindEnteredContext(saved_entered_context_count); SetCurrentContext(current_context); Goto(&done); diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index bf278c7ae513ae..e45f925a282d7a 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -16350,7 +16350,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);