From 3e7238e45ab68874542c9546dc9a90ccd911a067 Mon Sep 17 00:00:00 2001 From: Stephen Belanger Date: Thu, 22 Apr 2021 08:59:36 -0700 Subject: [PATCH] deps: V8: cherry-pick 272445f10927 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [runtime] Fix promise hooks promiseCapability can be undefined. Bug: v8:11025 Bug: chromium:1201113 Change-Id: I9da8764820cee0db1f0c38ed2fff0e3afeb9a80e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2844649 Reviewed-by: Marja Hölttä Commit-Queue: Camillo Bruni Cr-Commit-Position: refs/heads/master@{#74117} Refs: https://github.com/v8/v8/commit/272445f109273dcdf81d37b1f91f146cfd78ec41 PR-URL: https://github.com/nodejs/node/pull/36394 Backport-PR-URL: https://github.com/nodejs/node/pull/38577 Reviewed-By: Bryan English Reviewed-By: Gus Caplan Reviewed-By: Vladimir de Turckheim Reviewed-By: Gerhard Stöbich Reviewed-By: James M Snell --- common.gypi | 2 +- deps/v8/src/builtins/promise-misc.tq | 13 ++++++++----- deps/v8/test/mjsunit/promise-hooks.js | 12 +++++++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/common.gypi b/common.gypi index 3126f43aa975f3..a8bb1142f41662 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,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.77', + 'v8_embedder_string': '-node.78', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/builtins/promise-misc.tq b/deps/v8/src/builtins/promise-misc.tq index 3c2863077307d5..1962167067456a 100644 --- a/deps/v8/src/builtins/promise-misc.tq +++ b/deps/v8/src/builtins/promise-misc.tq @@ -133,7 +133,7 @@ transitioning macro RunContextPromiseHookResolve(implicit context: Context)( @export transitioning macro RunContextPromiseHookBefore(implicit context: Context)( - promiseOrCapability: JSPromise|PromiseCapability) { + promiseOrCapability: JSPromise|PromiseCapability|Undefined) { RunContextPromiseHook( NativeContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability, PromiseHookFlags()); @@ -141,7 +141,7 @@ transitioning macro RunContextPromiseHookBefore(implicit context: Context)( @export transitioning macro RunContextPromiseHookBefore(implicit context: Context)( - promiseOrCapability: JSPromise|PromiseCapability, flags: uint32) { + promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) { RunContextPromiseHook( NativeContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability, flags); @@ -149,7 +149,7 @@ transitioning macro RunContextPromiseHookBefore(implicit context: Context)( @export transitioning macro RunContextPromiseHookAfter(implicit context: Context)( - promiseOrCapability: JSPromise|PromiseCapability) { + promiseOrCapability: JSPromise|PromiseCapability|Undefined) { RunContextPromiseHook( NativeContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability, PromiseHookFlags()); @@ -157,7 +157,7 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)( @export transitioning macro RunContextPromiseHookAfter(implicit context: Context)( - promiseOrCapability: JSPromise|PromiseCapability, flags: uint32) { + promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) { RunContextPromiseHook( NativeContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability, flags); @@ -165,7 +165,7 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)( transitioning macro RunContextPromiseHook(implicit context: Context)( slot: NativeContextSlot, - promiseOrCapability: JSPromise|PromiseCapability, flags: uint32) { + promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) { if (!IsContextPromiseHookEnabled(flags)) return; const nativeContext: NativeContext = LoadNativeContext(context); const hook = Cast(nativeContext[slot]) otherwise return; @@ -178,6 +178,9 @@ transitioning macro RunContextPromiseHook(implicit context: Context)( case (capability: PromiseCapability): { promise = Cast(capability.promise) otherwise return; } + case (Undefined): { + return; + } } try { diff --git a/deps/v8/test/mjsunit/promise-hooks.js b/deps/v8/test/mjsunit/promise-hooks.js index 9e13206a525f95..db7041a8f5de97 100644 --- a/deps/v8/test/mjsunit/promise-hooks.js +++ b/deps/v8/test/mjsunit/promise-hooks.js @@ -1,7 +1,7 @@ // Copyright 2020 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// + // Flags: --allow-natives-syntax --opt --no-always-opt --no-stress-opt --deopt-every-n-times=0 --ignore-unhandled-promises let log = []; @@ -242,3 +242,13 @@ optimizerBailout(async () => { }); basicTest(); exceptions(); + +(function regress1126309() { + function __f_16(test) { + test(); + d8.promise.setHooks( undefined, () => {}); + %PerformMicrotaskCheckpoint(); + d8.promise.setHooks(); + } + __f_16(async () => { await Promise.resolve()}); +})();