// |jit-test| skip-if: getBuildConfiguration("release_or_beta") // // JS::SafeResolve latches the promise's resolving functions on return, so any // subsequent resolve/reject (including a second SafeResolve) is a silent // no-op. The promise also stays pending through the deferral window.
// --------------------------------------------------------------------------- // Fast path latches synchronously. A follow-up resolve() must be ignored.
{ const {promise, resolve, reject} = Promise.withResolvers();
safeResolvePromise(promise, "first");
resolve("second"); // should no-op, promise already fulfilled.
reject("third"); // should no-op.
// --------------------------------------------------------------------------- // Deferred path latches synchronously too: before the microtask runs, the // resolving functions are already no-ops, and a direct resolve() on the // capability is swallowed.
{ const {promise, resolve, reject} = Promise.withResolvers();
safeResolvePromise(promise, thenable); // Capability is latched even though the promise is still pending.
resolve("racing-resolve");
reject("racing-reject");
// --------------------------------------------------------------------------- // SafeResolve after the promise has already settled is a no-op (the top-level // pending check short-circuits before we touch anything).
{ const {promise, resolve} = Promise.withResolvers();
resolve("preset");
safeResolvePromise(promise, {then(r){ r("ignored"); }});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.