Commit 86235036 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[promises] Fix undefined case in promise macros

Handle the undefined promiseOrCapability case in
RejectPromiseReactionJob and FulfillPromiseReactionJob.

Fixed: chromium:1046213
Change-Id: If6f51c28189a27476969c7b5b456741b5be829be
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2050399
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66248}
parent b3c38223
...@@ -17,27 +17,28 @@ namespace promise { ...@@ -17,27 +17,28 @@ namespace promise {
promiseOrCapability: JSPromise|PromiseCapability|Undefined, reason: JSAny, promiseOrCapability: JSPromise|PromiseCapability|Undefined, reason: JSAny,
reactionType: constexpr PromiseReactionType): JSAny { reactionType: constexpr PromiseReactionType): JSAny {
if constexpr (reactionType == kPromiseReactionReject) { if constexpr (reactionType == kPromiseReactionReject) {
if (IsJSPromise(promiseOrCapability)) { typeswitch (promiseOrCapability) {
// For fast native promises we can skip the indirection via the case (promise: JSPromise): {
// promiseCapability.[[Reject]] function and run the resolve logic // For fast native promises we can skip the indirection via the
// directly from here. // promiseCapability.[[Reject]] function and run the resolve logic
return RejectPromise( // directly from here.
UnsafeCast<JSPromise>(promiseOrCapability), reason, False); return RejectPromise(promise, reason, False);
} else }
deferred { case (Undefined): {
assert(IsPromiseCapability(promiseOrCapability)); return Undefined;
}
case (capability: PromiseCapability): {
// In the general case we need to call the (user provided) // In the general case we need to call the (user provided)
// promiseCapability.[[Reject]] function. // promiseCapability.[[Reject]] function.
try { try {
const promiseCapability = const reject = UnsafeCast<Callable>(capability.reject);
UnsafeCast<PromiseCapability>(promiseOrCapability);
const reject = UnsafeCast<Callable>(promiseCapability.reject);
return Call(context, reject, Undefined, reason); return Call(context, reject, Undefined, reason);
} catch (e) { } catch (e) {
// Swallow the exception here. // Swallow the exception here.
return runtime::ReportMessage(e); return runtime::ReportMessage(e);
} }
} }
}
} else { } else {
StaticAssert(reactionType == kPromiseReactionFulfill); StaticAssert(reactionType == kPromiseReactionFulfill);
// We have to call out to the dedicated PromiseRejectReactionJob // We have to call out to the dedicated PromiseRejectReactionJob
...@@ -53,20 +54,20 @@ namespace promise { ...@@ -53,20 +54,20 @@ namespace promise {
context: Context, context: Context,
promiseOrCapability: JSPromise|PromiseCapability|Undefined, result: JSAny, promiseOrCapability: JSPromise|PromiseCapability|Undefined, result: JSAny,
reactionType: constexpr PromiseReactionType): JSAny { reactionType: constexpr PromiseReactionType): JSAny {
if (IsJSPromise(promiseOrCapability)) { typeswitch (promiseOrCapability) {
// For fast native promises we can skip the indirection via the case (promise: JSPromise): {
// promiseCapability.[[Resolve]] function and run the resolve logic // For fast native promises we can skip the indirection via the
// directly from here. // promiseCapability.[[Resolve]] function and run the resolve logic
return ResolvePromise( // directly from here.
context, UnsafeCast<JSPromise>(promiseOrCapability), result); return ResolvePromise(context, promise, result);
} else }
deferred { case (Undefined): {
assert(IsPromiseCapability(promiseOrCapability)); return Undefined;
}
case (capability: PromiseCapability): {
// In the general case we need to call the (user provided) // In the general case we need to call the (user provided)
// promiseCapability.[[Resolve]] function. // promiseCapability.[[Resolve]] function.
const promiseCapability = const resolve = UnsafeCast<Callable>(capability.resolve);
UnsafeCast<PromiseCapability>(promiseOrCapability);
const resolve = UnsafeCast<Callable>(promiseCapability.resolve);
try { try {
return Call(context, resolve, Undefined, result); return Call(context, resolve, Undefined, result);
} catch (e) { } catch (e) {
...@@ -74,6 +75,7 @@ namespace promise { ...@@ -74,6 +75,7 @@ namespace promise {
context, promiseOrCapability, e, reactionType); context, promiseOrCapability, e, reactionType);
} }
} }
}
} }
// https://tc39.es/ecma262/#sec-promisereactionjob // https://tc39.es/ecma262/#sec-promisereactionjob
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment