Skip to content

Commit 008c355

Browse files
committed
1 parent 7a0b136 commit 008c355

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Source/JavaScriptCore/builtins/BuiltinNames.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ namespace JSC {
213213
macro(hasOwn) \
214214
macro(indexOf) \
215215
macro(pop) \
216+
macro(pushAsyncContextFrame) \
217+
macro(popAsyncContextFrame) \
218+
macro(getAsyncContextFrame) \
216219

217220

218221
namespace Symbols {

Source/JavaScriptCore/builtins/PromiseOperations.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function pushNewPromiseReaction(thenable, existingReactions, promiseOrCapability
3636
@promiseOrCapability: promiseOrCapability,
3737
@onFulfilled: onFulfilled,
3838
@onRejected: onRejected,
39-
@context: context,
39+
@context: @getAsyncContextFrame ? @getAsyncContextFrame(context) : context,
4040
// This is 4x the number of out of line reactions (promise, fulfill callback, reject callback, context).
4141
@outOfLineReactionCounts: 0,
4242
};
@@ -46,7 +46,7 @@ function pushNewPromiseReaction(thenable, existingReactions, promiseOrCapability
4646
@putByValDirect(existingReactions, outOfLineReactionCounts++, promiseOrCapability);
4747
@putByValDirect(existingReactions, outOfLineReactionCounts++, onFulfilled);
4848
@putByValDirect(existingReactions, outOfLineReactionCounts++, onRejected);
49-
@putByValDirect(existingReactions, outOfLineReactionCounts++, context);
49+
@putByValDirect(existingReactions, outOfLineReactionCounts++, @getAsyncContextFrame ? @getAsyncContextFrame(context) : context);
5050
existingReactions.@outOfLineReactionCounts = outOfLineReactionCounts;
5151
}
5252
}
@@ -318,6 +318,10 @@ function createResolvingFunctions(promise)
318318
function promiseReactionJobWithoutPromise(handler, argument, context)
319319
{
320320
"use strict";
321+
var pushed;
322+
if (@pushAsyncContextFrame) {
323+
pushed = @pushAsyncContextFrame(context);
324+
}
321325

322326
try {
323327
if (context)
@@ -326,6 +330,10 @@ function promiseReactionJobWithoutPromise(handler, argument, context)
326330
handler(argument);
327331
} catch {
328332
// This is user-uncatchable promise. We just ignore the error here.
333+
} finally {
334+
if (@popAsyncContextFrame) {
335+
@popAsyncContextFrame(pushed);
336+
}
329337
}
330338
}
331339

@@ -457,6 +465,11 @@ function promiseReactionJob(promiseOrCapability, handler, argument, contextOrSta
457465
return;
458466
}
459467

468+
var pushed;
469+
if (@pushAsyncContextFrame) {
470+
pushed = @pushAsyncContextFrame(contextOrState);
471+
}
472+
460473
// Case (1), or (2).
461474
try {
462475
var result = (contextOrState) ? handler(argument, contextOrState) : handler(argument);
@@ -466,14 +479,23 @@ function promiseReactionJob(promiseOrCapability, handler, argument, contextOrSta
466479
return;
467480
}
468481
promiseOrCapability.@reject.@call(@undefined, error);
482+
if (@popAsyncContextFrame) {
483+
@popAsyncContextFrame(pushed);
484+
}
469485
return;
470486
}
471487

472488
if (@isPromise(promiseOrCapability)) {
473489
@resolvePromise(promiseOrCapability, result);
490+
if (@popAsyncContextFrame) {
491+
@popAsyncContextFrame(pushed);
492+
}
474493
return;
475494
}
476495
promiseOrCapability.@resolve.@call(@undefined, result);
496+
if (@popAsyncContextFrame) {
497+
@popAsyncContextFrame(pushed);
498+
}
477499
}
478500

479501
@linkTimeConstant

Source/JavaScriptCore/runtime/JSGlobalObject.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,10 @@ capitalName ## Constructor* lowerName ## Constructor = featureFlag ? capitalName
16621662
putDirectWithoutTransition(vm, Identifier::fromString(vm, "__signpostStop"_s), JSFunction::create(vm, this, 1, "signpostStop"_s, signpostStop, ImplementationVisibility::Public), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
16631663
}
16641664

1665+
putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().pushAsyncContextFramePrivateName(), jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | 0);
1666+
putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().popAsyncContextFramePrivateName(), jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | 0);
1667+
putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().getAsyncContextFramePrivateName(), jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | 0);
1668+
16651669
initStaticGlobals(vm);
16661670

16671671
if (UNLIKELY(Options::useDollarVM()))

0 commit comments

Comments
 (0)