Commit 272445f1 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[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/+/2844649Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74117}
parent 4504fbe2
...@@ -134,7 +134,7 @@ transitioning macro RunContextPromiseHookResolve(implicit context: Context)( ...@@ -134,7 +134,7 @@ transitioning macro RunContextPromiseHookResolve(implicit context: Context)(
@export @export
transitioning macro RunContextPromiseHookBefore(implicit context: Context)( transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability) { promiseOrCapability: JSPromise|PromiseCapability|Undefined) {
RunContextPromiseHook( RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability, ContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability,
PromiseHookFlags()); PromiseHookFlags());
...@@ -142,7 +142,7 @@ transitioning macro RunContextPromiseHookBefore(implicit context: Context)( ...@@ -142,7 +142,7 @@ transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
@export @export
transitioning macro RunContextPromiseHookBefore(implicit context: Context)( transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability, flags: uint32) { promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
RunContextPromiseHook( RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability, ContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability,
flags); flags);
...@@ -150,7 +150,7 @@ transitioning macro RunContextPromiseHookBefore(implicit context: Context)( ...@@ -150,7 +150,7 @@ transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
@export @export
transitioning macro RunContextPromiseHookAfter(implicit context: Context)( transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability) { promiseOrCapability: JSPromise|PromiseCapability|Undefined) {
RunContextPromiseHook( RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability, ContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability,
PromiseHookFlags()); PromiseHookFlags());
...@@ -158,7 +158,7 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)( ...@@ -158,7 +158,7 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
@export @export
transitioning macro RunContextPromiseHookAfter(implicit context: Context)( transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability, flags: uint32) { promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
RunContextPromiseHook( RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability, ContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability,
flags); flags);
...@@ -166,7 +166,7 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)( ...@@ -166,7 +166,7 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
transitioning macro RunContextPromiseHook(implicit context: Context)( transitioning macro RunContextPromiseHook(implicit context: Context)(
slot: Slot<NativeContext, Undefined|JSFunction>, slot: Slot<NativeContext, Undefined|JSFunction>,
promiseOrCapability: JSPromise|PromiseCapability, flags: uint32) { promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
if (!IsContextPromiseHookEnabled(flags)) return; if (!IsContextPromiseHookEnabled(flags)) return;
const maybeHook = *NativeContextSlot(slot); const maybeHook = *NativeContextSlot(slot);
if (IsUndefined(maybeHook)) return; if (IsUndefined(maybeHook)) return;
...@@ -181,6 +181,9 @@ transitioning macro RunContextPromiseHook(implicit context: Context)( ...@@ -181,6 +181,9 @@ transitioning macro RunContextPromiseHook(implicit context: Context)(
case (capability: PromiseCapability): { case (capability: PromiseCapability): {
promise = Cast<JSPromise>(capability.promise) otherwise return; promise = Cast<JSPromise>(capability.promise) otherwise return;
} }
case (Undefined): {
return;
}
} }
try { try {
......
// Copyright 2020 the V8 project authors. All rights reserved. // Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
//
// Flags: --allow-natives-syntax --opt --no-always-opt --no-stress-opt --deopt-every-n-times=0 --ignore-unhandled-promises // Flags: --allow-natives-syntax --opt --no-always-opt --no-stress-opt --deopt-every-n-times=0 --ignore-unhandled-promises
let log = []; let log = [];
...@@ -242,3 +242,13 @@ optimizerBailout(async () => { ...@@ -242,3 +242,13 @@ optimizerBailout(async () => {
}); });
basicTest(); basicTest();
exceptions(); exceptions();
(function regress1126309() {
function __f_16(test) {
test();
d8.promise.setHooks( undefined, () => {});
%PerformMicrotaskCheckpoint();
d8.promise.setHooks();
}
__f_16(async () => { await Promise.resolve()});
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment