Skip to content

Commit

Permalink
deps: V8: cherry-pick 5f4413194480
Browse files Browse the repository at this point in the history
Original commit message:

    [promises] Change context promise hooks to Callable

    The previously added perf-context Promise-hooks take a v8::Function as
    arguments. However, the builtin code was only accepting JSFunctions
    which causes cast errors.

    Drive-by-fix: Directly pass nativeContext in more places.

    Bug: chromium:1201465
    Change-Id: Ic8bed11253a1f18a84e71eb9ea809b1ec1c3f428
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2850162
    Reviewed-by: Jakob Gruber <[email protected]>
    Commit-Queue: Camillo Bruni <[email protected]>
    Cr-Commit-Position: refs/heads/master@{#74223}

Refs: v8/v8@5f44131

PR-URL: #36394
Reviewed-By: Bryan English <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Stephen Belanger authored and targos committed May 17, 2021
1 parent 1a104ba commit 043b1aa
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 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.13',
'v8_embedder_string': '-node.14',

##### V8 defaults for Node.js #####

Expand Down
10 changes: 3 additions & 7 deletions deps/v8/src/builtins/promise-misc.tq
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ transitioning macro RunContextPromiseHookInit(implicit context: Context)(
promise: JSPromise, parent: Object) {
const maybeHook = *NativeContextSlot(
ContextSlot::PROMISE_HOOK_INIT_FUNCTION_INDEX);
if (IsUndefined(maybeHook)) return;

const hook = Cast<JSFunction>(maybeHook) otherwise unreachable;
const hook = Cast<Callable>(maybeHook) otherwise return;
const parentObject = Is<JSPromise>(parent) ? Cast<JSPromise>(parent)
otherwise unreachable: Undefined;

Expand Down Expand Up @@ -165,13 +163,11 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
}

transitioning macro RunContextPromiseHook(implicit context: Context)(
slot: Slot<NativeContext, Undefined|JSFunction>,
slot: Slot<NativeContext, Undefined|Callable>,
promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
if (!IsContextPromiseHookEnabled(flags)) return;
const maybeHook = *NativeContextSlot(slot);
if (IsUndefined(maybeHook)) return;

const hook = Cast<JSFunction>(maybeHook) otherwise unreachable;
const hook = Cast<Callable>(maybeHook) otherwise return;

let promise: JSPromise;
typeswitch (promiseOrCapability) {
Expand Down
14 changes: 9 additions & 5 deletions deps/v8/src/builtins/promise-resolve.tq
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ transitioning builtin
PromiseResolve(implicit context: Context)(
constructor: JSReceiver, value: JSAny): JSAny {
const nativeContext = LoadNativeContext(context);
const promiseFun = *NativeContextSlot(ContextSlot::PROMISE_FUNCTION_INDEX);
const promiseFun = *NativeContextSlot(
nativeContext, ContextSlot::PROMISE_FUNCTION_INDEX);
try {
// Check if {value} is a JSPromise.
const value = Cast<JSPromise>(value) otherwise NeedToAllocate;
Expand All @@ -40,7 +41,8 @@ PromiseResolve(implicit context: Context)(
// intact, as that guards the lookup path for "constructor" on
// JSPromise instances which have the (initial) Promise.prototype.
const promisePrototype =
*NativeContextSlot(ContextSlot::PROMISE_PROTOTYPE_INDEX);
*NativeContextSlot(
nativeContext, ContextSlot::PROMISE_PROTOTYPE_INDEX);
// Check that Torque load elimination works.
static_assert(nativeContext == LoadNativeContext(context));
if (value.map.prototype != promisePrototype) {
Expand Down Expand Up @@ -139,18 +141,20 @@ ResolvePromise(implicit context: Context)(
assert(IsJSReceiverMap(resolutionMap));
assert(!IsPromiseThenProtectorCellInvalid());
if (resolutionMap ==
*NativeContextSlot(ContextSlot::ITERATOR_RESULT_MAP_INDEX)) {
*NativeContextSlot(
nativeContext, ContextSlot::ITERATOR_RESULT_MAP_INDEX)) {
return FulfillPromise(promise, resolution);
} else {
goto Slow;
}
}

const promisePrototype =
*NativeContextSlot(ContextSlot::PROMISE_PROTOTYPE_INDEX);
*NativeContextSlot(
nativeContext, ContextSlot::PROMISE_PROTOTYPE_INDEX);
if (resolutionMap.prototype == promisePrototype) {
// The {resolution} is a native Promise in this case.
then = *NativeContextSlot(ContextSlot::PROMISE_THEN_INDEX);
then = *NativeContextSlot(nativeContext, ContextSlot::PROMISE_THEN_INDEX);
// Check that Torque load elimination works.
static_assert(nativeContext == LoadNativeContext(context));
goto Enqueue;
Expand Down
9 changes: 4 additions & 5 deletions deps/v8/src/objects/contexts.tq
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ extern enum ContextSlot extends intptr constexpr 'Context::Field' {
PROMISE_PROTOTYPE_INDEX: Slot<NativeContext, JSObject>,
STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX: Slot<NativeContext, Map>,

PROMISE_HOOK_INIT_FUNCTION_INDEX: Slot<NativeContext, Undefined|JSFunction>,
PROMISE_HOOK_BEFORE_FUNCTION_INDEX: Slot<NativeContext, Undefined|JSFunction>,
PROMISE_HOOK_AFTER_FUNCTION_INDEX: Slot<NativeContext, Undefined|JSFunction>,
PROMISE_HOOK_RESOLVE_FUNCTION_INDEX:
Slot<NativeContext, Undefined|JSFunction>,
PROMISE_HOOK_INIT_FUNCTION_INDEX: Slot<NativeContext, Undefined|Callable>,
PROMISE_HOOK_BEFORE_FUNCTION_INDEX: Slot<NativeContext, Undefined|Callable>,
PROMISE_HOOK_AFTER_FUNCTION_INDEX: Slot<NativeContext, Undefined|Callable>,
PROMISE_HOOK_RESOLVE_FUNCTION_INDEX: Slot<NativeContext, Undefined|Callable>,

CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX: Slot<NativeContext, HeapObject>,

Expand Down
10 changes: 10 additions & 0 deletions deps/v8/test/mjsunit/promise-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,13 @@ exceptions();
}
__f_16(async () => { await Promise.resolve()});
})();

(function boundFunction() {
function hook() {};
const bound = hook.bind(this);
d8.promise.setHooks(bound, bound, bound, bound);
Promise.resolve();
Promise.reject();
%PerformMicrotaskCheckpoint();
d8.promise.setHooks();
})();

0 comments on commit 043b1aa

Please sign in to comment.