Skip to content

Commit 3c37396

Browse files
committed
deps: V8: cherry-pick 5f4413194480
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 <jgruber@chromium.org> Commit-Queue: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/master@{#74223} Refs: v8/v8@5f44131 PR-URL: #38273 Backport-PR-URL: #38991 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Mary Marchini <oss@mmarchini.me>
1 parent 3433559 commit 3c37396

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.10',
39+
'v8_embedder_string': '-node.11',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/src/builtins/promise-misc.tq

+3-7
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ transitioning macro RunContextPromiseHookInit(implicit context: Context)(
104104
promise: JSPromise, parent: Object) {
105105
const maybeHook = *NativeContextSlot(
106106
ContextSlot::PROMISE_HOOK_INIT_FUNCTION_INDEX);
107-
if (IsUndefined(maybeHook)) return;
108-
109-
const hook = Cast<JSFunction>(maybeHook) otherwise unreachable;
107+
const hook = Cast<Callable>(maybeHook) otherwise return;
110108
const parentObject = Is<JSPromise>(parent) ? Cast<JSPromise>(parent)
111109
otherwise unreachable: Undefined;
112110

@@ -165,13 +163,11 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
165163
}
166164

167165
transitioning macro RunContextPromiseHook(implicit context: Context)(
168-
slot: Slot<NativeContext, Undefined|JSFunction>,
166+
slot: Slot<NativeContext, Undefined|Callable>,
169167
promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
170168
if (!IsContextPromiseHookEnabled(flags)) return;
171169
const maybeHook = *NativeContextSlot(slot);
172-
if (IsUndefined(maybeHook)) return;
173-
174-
const hook = Cast<JSFunction>(maybeHook) otherwise unreachable;
170+
const hook = Cast<Callable>(maybeHook) otherwise return;
175171

176172
let promise: JSPromise;
177173
typeswitch (promiseOrCapability) {

deps/v8/src/builtins/promise-resolve.tq

+9-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ transitioning builtin
3030
PromiseResolve(implicit context: Context)(
3131
constructor: JSReceiver, value: JSAny): JSAny {
3232
const nativeContext = LoadNativeContext(context);
33-
const promiseFun = *NativeContextSlot(ContextSlot::PROMISE_FUNCTION_INDEX);
33+
const promiseFun = *NativeContextSlot(
34+
nativeContext, ContextSlot::PROMISE_FUNCTION_INDEX);
3435
try {
3536
// Check if {value} is a JSPromise.
3637
const value = Cast<JSPromise>(value) otherwise NeedToAllocate;
@@ -40,7 +41,8 @@ PromiseResolve(implicit context: Context)(
4041
// intact, as that guards the lookup path for "constructor" on
4142
// JSPromise instances which have the (initial) Promise.prototype.
4243
const promisePrototype =
43-
*NativeContextSlot(ContextSlot::PROMISE_PROTOTYPE_INDEX);
44+
*NativeContextSlot(
45+
nativeContext, ContextSlot::PROMISE_PROTOTYPE_INDEX);
4446
// Check that Torque load elimination works.
4547
static_assert(nativeContext == LoadNativeContext(context));
4648
if (value.map.prototype != promisePrototype) {
@@ -139,18 +141,20 @@ ResolvePromise(implicit context: Context)(
139141
assert(IsJSReceiverMap(resolutionMap));
140142
assert(!IsPromiseThenProtectorCellInvalid());
141143
if (resolutionMap ==
142-
*NativeContextSlot(ContextSlot::ITERATOR_RESULT_MAP_INDEX)) {
144+
*NativeContextSlot(
145+
nativeContext, ContextSlot::ITERATOR_RESULT_MAP_INDEX)) {
143146
return FulfillPromise(promise, resolution);
144147
} else {
145148
goto Slow;
146149
}
147150
}
148151

149152
const promisePrototype =
150-
*NativeContextSlot(ContextSlot::PROMISE_PROTOTYPE_INDEX);
153+
*NativeContextSlot(
154+
nativeContext, ContextSlot::PROMISE_PROTOTYPE_INDEX);
151155
if (resolutionMap.prototype == promisePrototype) {
152156
// The {resolution} is a native Promise in this case.
153-
then = *NativeContextSlot(ContextSlot::PROMISE_THEN_INDEX);
157+
then = *NativeContextSlot(nativeContext, ContextSlot::PROMISE_THEN_INDEX);
154158
// Check that Torque load elimination works.
155159
static_assert(nativeContext == LoadNativeContext(context));
156160
goto Enqueue;

deps/v8/src/objects/contexts.tq

+4-5
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ extern enum ContextSlot extends intptr constexpr 'Context::Field' {
124124
PROMISE_PROTOTYPE_INDEX: Slot<NativeContext, JSObject>,
125125
STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX: Slot<NativeContext, Map>,
126126

127-
PROMISE_HOOK_INIT_FUNCTION_INDEX: Slot<NativeContext, Undefined|JSFunction>,
128-
PROMISE_HOOK_BEFORE_FUNCTION_INDEX: Slot<NativeContext, Undefined|JSFunction>,
129-
PROMISE_HOOK_AFTER_FUNCTION_INDEX: Slot<NativeContext, Undefined|JSFunction>,
130-
PROMISE_HOOK_RESOLVE_FUNCTION_INDEX:
131-
Slot<NativeContext, Undefined|JSFunction>,
127+
PROMISE_HOOK_INIT_FUNCTION_INDEX: Slot<NativeContext, Undefined|Callable>,
128+
PROMISE_HOOK_BEFORE_FUNCTION_INDEX: Slot<NativeContext, Undefined|Callable>,
129+
PROMISE_HOOK_AFTER_FUNCTION_INDEX: Slot<NativeContext, Undefined|Callable>,
130+
PROMISE_HOOK_RESOLVE_FUNCTION_INDEX: Slot<NativeContext, Undefined|Callable>,
132131

133132
CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX: Slot<NativeContext, HeapObject>,
134133

deps/v8/test/mjsunit/promise-hooks.js

+10
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,13 @@ exceptions();
252252
}
253253
__f_16(async () => { await Promise.resolve()});
254254
})();
255+
256+
(function boundFunction() {
257+
function hook() {};
258+
const bound = hook.bind(this);
259+
d8.promise.setHooks(bound, bound, bound, bound);
260+
Promise.resolve();
261+
Promise.reject();
262+
%PerformMicrotaskCheckpoint();
263+
d8.promise.setHooks();
264+
})();

0 commit comments

Comments
 (0)