@@ -265,8 +265,8 @@ const kPromiseCapabilitySize:
265265type PromiseResolvingFunctionContext extends FunctionContext;
266266extern enum PromiseResolvingFunctionContextSlot extends intptr
267267 constexpr 'PromiseBuiltins::PromiseResolvingFunctionContextSlot' {
268- kPromiseSlot: Slot<PromiseResolvingFunctionContext, JSPromise>,
269- kAlreadyResolvedSlot: Slot<PromiseResolvingFunctionContext, Boolean >,
268+ kPromiseIfNotResolvedSlot:
269+ Slot<PromiseResolvingFunctionContext, JSPromise|Undefined >,
270270 kDebugEventSlot: Slot<PromiseResolvingFunctionContext, Boolean>,
271271 kPromiseContextLength
272272}
@@ -390,25 +390,29 @@ transitioning builtin NewPromiseCapability(
390390transitioning javascript builtin PromiseCapabilityDefaultReject(
391391 js-implicit context: Context, receiver: JSAny)(reason: JSAny): JSAny {
392392 const context = %RawDownCast<PromiseResolvingFunctionContext>(context);
393- // 2. Let promise be F.[[Promise]].
394- const promise =
395- *ContextSlot(context, PromiseResolvingFunctionContextSlot::kPromiseSlot);
396-
397- // 3. Let alreadyResolved be F.[[AlreadyResolved]].
398- const alreadyResolved = *ContextSlot(
399- context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot);
400-
401- // 4. If alreadyResolved.[[Value]] is true, return undefined.
402- if (alreadyResolved == True) {
403- return Undefined;
393+ // 2. Let promise be promiseOrEmpty.[[Value]].
394+ const promiseOrEmpty =
395+ *ContextSlot(
396+ context, PromiseResolvingFunctionContextSlot::kPromiseIfNotResolvedSlot);
397+
398+ // 1. If promiseOrEmpty.[[Value]] is ~empty~, return undefined.
399+ let promise: JSPromise;
400+ typeswitch (promiseOrEmpty) {
401+ case (Undefined): {
402+ return Undefined;
403+ }
404+ case (p: JSPromise): {
405+ promise = p;
406+ }
404407 }
405408
406- // 5 . Set alreadyResolved .[[Value]] to true .
409+ // 3 . Set promiseOrEmpty .[[Value]] to ~empty~ .
407410 *ContextSlot(
408- context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot ) =
409- True ;
411+ context, PromiseResolvingFunctionContextSlot::kPromiseIfNotResolvedSlot ) =
412+ Undefined ;
410413
411- // 6. Return RejectPromise(promise, reason).
414+ // 4. Perform RejectPromise(promise, reason).
415+ // 5. Return undefined.
412416 const debugEvent = *ContextSlot(
413417 context, PromiseResolvingFunctionContextSlot::kDebugEventSlot);
414418 return RejectPromise(promise, reason, debugEvent);
@@ -418,23 +422,26 @@ transitioning javascript builtin PromiseCapabilityDefaultReject(
418422transitioning javascript builtin PromiseCapabilityDefaultResolve(
419423 js-implicit context: Context, receiver: JSAny)(resolution: JSAny): JSAny {
420424 const context = %RawDownCast<PromiseResolvingFunctionContext>(context);
421- // 2. Let promise be F.[[Promise]].
422- const promise: JSPromise =
423- *ContextSlot(context, PromiseResolvingFunctionContextSlot::kPromiseSlot);
424-
425- // 3. Let alreadyResolved be F.[[AlreadyResolved]].
426- const alreadyResolved: Boolean = *ContextSlot(
427- context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot);
428-
429- // 4. If alreadyResolved.[[Value]] is true, return undefined.
430- if (alreadyResolved == True) {
431- return Undefined;
425+ // 2. Let promise be promiseOrEmpty.[[Value]].
426+ const promiseOrEmpty =
427+ *ContextSlot(
428+ context, PromiseResolvingFunctionContextSlot::kPromiseIfNotResolvedSlot);
429+
430+ // 1. If promiseOrEmpty.[[Value]] is ~empty~, return undefined.
431+ let promise: JSPromise;
432+ typeswitch (promiseOrEmpty) {
433+ case (Undefined): {
434+ return Undefined;
435+ }
436+ case (p: JSPromise): {
437+ promise = p;
438+ }
432439 }
433440
434- // 5 . Set alreadyResolved .[[Value]] to true .
441+ // 3 . Set promiseOrEmpty .[[Value]] to ~empty~ .
435442 *ContextSlot(
436- context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot ) =
437- True ;
443+ context, PromiseResolvingFunctionContextSlot::kPromiseIfNotResolvedSlot ) =
444+ Undefined ;
438445
439446 // The rest of the logic (and the catch prediction) is
440447 // encapsulated in the dedicated ResolvePromise builtin.
0 commit comments