@@ -278,8 +278,8 @@ const kPromiseCapabilitySize:
278278type PromiseResolvingFunctionContext extends FunctionContext;
279279extern enum PromiseResolvingFunctionContextSlot extends intptr
280280 constexpr 'PromiseBuiltins::PromiseResolvingFunctionContextSlot' {
281- kPromiseSlot: Slot<PromiseResolvingFunctionContext, JSPromise>,
282- kAlreadyResolvedSlot: Slot<PromiseResolvingFunctionContext, Boolean >,
281+ kPromiseIfNotResolvedSlot:
282+ Slot<PromiseResolvingFunctionContext, JSPromise|Undefined >,
283283 kDebugEventSlot: Slot<PromiseResolvingFunctionContext, Boolean>,
284284 kPromiseContextLength
285285}
@@ -403,25 +403,29 @@ transitioning builtin NewPromiseCapability(
403403transitioning javascript builtin PromiseCapabilityDefaultReject(
404404 js-implicit context: Context, receiver: JSAny)(reason: JSAny): JSAny {
405405 const context = %RawDownCast<PromiseResolvingFunctionContext>(context);
406- // 2. Let promise be F.[[Promise]].
407- const promise =
408- *ContextSlot(context, PromiseResolvingFunctionContextSlot::kPromiseSlot);
409-
410- // 3. Let alreadyResolved be F.[[AlreadyResolved]].
411- const alreadyResolved = *ContextSlot(
412- context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot);
413-
414- // 4. If alreadyResolved.[[Value]] is true, return undefined.
415- if (alreadyResolved == True) {
416- return Undefined;
406+ // 2. Let promise be promiseOrEmpty.[[Value]].
407+ const promiseOrEmpty =
408+ *ContextSlot(
409+ context, PromiseResolvingFunctionContextSlot::kPromiseIfNotResolvedSlot);
410+
411+ // 1. If promiseOrEmpty.[[Value]] is ~empty~, return undefined.
412+ let promise: JSPromise;
413+ typeswitch (promiseOrEmpty) {
414+ case (Undefined): {
415+ return Undefined;
416+ }
417+ case (p: JSPromise): {
418+ promise = p;
419+ }
417420 }
418421
419- // 5 . Set alreadyResolved .[[Value]] to true .
422+ // 3 . Set promiseOrEmpty .[[Value]] to ~empty~ .
420423 *ContextSlot(
421- context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot ) =
422- True ;
424+ context, PromiseResolvingFunctionContextSlot::kPromiseIfNotResolvedSlot ) =
425+ Undefined ;
423426
424- // 6. Return RejectPromise(promise, reason).
427+ // 4. Perform RejectPromise(promise, reason).
428+ // 5. Return undefined.
425429 const debugEvent = *ContextSlot(
426430 context, PromiseResolvingFunctionContextSlot::kDebugEventSlot);
427431 return RejectPromise(promise, reason, debugEvent);
@@ -431,23 +435,26 @@ transitioning javascript builtin PromiseCapabilityDefaultReject(
431435transitioning javascript builtin PromiseCapabilityDefaultResolve(
432436 js-implicit context: Context, receiver: JSAny)(resolution: JSAny): JSAny {
433437 const context = %RawDownCast<PromiseResolvingFunctionContext>(context);
434- // 2. Let promise be F.[[Promise]].
435- const promise: JSPromise =
436- *ContextSlot(context, PromiseResolvingFunctionContextSlot::kPromiseSlot);
437-
438- // 3. Let alreadyResolved be F.[[AlreadyResolved]].
439- const alreadyResolved: Boolean = *ContextSlot(
440- context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot);
441-
442- // 4. If alreadyResolved.[[Value]] is true, return undefined.
443- if (alreadyResolved == True) {
444- return Undefined;
438+ // 2. Let promise be promiseOrEmpty.[[Value]].
439+ const promiseOrEmpty =
440+ *ContextSlot(
441+ context, PromiseResolvingFunctionContextSlot::kPromiseIfNotResolvedSlot);
442+
443+ // 1. If promiseOrEmpty.[[Value]] is ~empty~, return undefined.
444+ let promise: JSPromise;
445+ typeswitch (promiseOrEmpty) {
446+ case (Undefined): {
447+ return Undefined;
448+ }
449+ case (p: JSPromise): {
450+ promise = p;
451+ }
445452 }
446453
447- // 5 . Set alreadyResolved .[[Value]] to true .
454+ // 3 . Set promiseOrEmpty .[[Value]] to ~empty~ .
448455 *ContextSlot(
449- context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot ) =
450- True ;
456+ context, PromiseResolvingFunctionContextSlot::kPromiseIfNotResolvedSlot ) =
457+ Undefined ;
451458
452459 // The rest of the logic (and the catch prediction) is
453460 // encapsulated in the dedicated ResolvePromise builtin.
0 commit comments