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
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 targos committed May 17, 2021
1 parent 827ae05 commit 1a104ba
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.12',
'v8_embedder_string': '-node.13',

##### 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 @@ -134,39 +134,39 @@ transitioning macro RunContextPromiseHookResolve(implicit context: Context)(

@export
transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined) {
RunContextPromiseHook(
ContextSlot::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(
ContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability,
flags);
}

@export
transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined) {
RunContextPromiseHook(
ContextSlot::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(
ContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability,
flags);
}

transitioning macro RunContextPromiseHook(implicit context: Context)(
slot: Slot<NativeContext, Undefined|JSFunction>,
promiseOrCapability: JSPromise|PromiseCapability, flags: uint32) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
if (!IsContextPromiseHookEnabled(flags)) return;
const maybeHook = *NativeContextSlot(slot);
if (IsUndefined(maybeHook)) return;
Expand All @@ -181,6 +181,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 1a104ba

Please sign in to comment.