Skip to content

Commit

Permalink
deps: V8: cherry-pick 272445f10927
Browse files Browse the repository at this point in the history
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ä <marja@chromium.org>
    Commit-Queue: Camillo Bruni <cbruni@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#74117}

Refs: v8/v8@272445f

PR-URL: #36394
Backport-PR-URL: #38577
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Stephen Belanger authored and MylesBorins committed Aug 31, 2021
1 parent 214e568 commit 3e7238e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####

Expand Down
13 changes: 8 additions & 5 deletions deps/v8/src/builtins/promise-misc.tq
Original file line number Diff line number Diff line change
Expand Up @@ -133,39 +133,39 @@ 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());
}

@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);
}

@export
transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined) {
RunContextPromiseHook(
NativeContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability,
PromiseHookFlags());
}

@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);
}

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<JSFunction>(nativeContext[slot]) otherwise return;
Expand All @@ -178,6 +178,9 @@ transitioning macro RunContextPromiseHook(implicit context: Context)(
case (capability: PromiseCapability): {
promise = Cast<JSPromise>(capability.promise) otherwise return;
}
case (Undefined): {
return;
}
}

try {
Expand Down
12 changes: 11 additions & 1 deletion deps/v8/test/mjsunit/promise-hooks.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down Expand Up @@ -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()});
})();

0 comments on commit 3e7238e

Please sign in to comment.