diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit-test/tests/promise/promise-race-with-default-resolving-internal.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/promise/promise-race-with-default-resolving-internal.js')
-rw-r--r-- | js/src/jit-test/tests/promise/promise-race-with-default-resolving-internal.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/promise/promise-race-with-default-resolving-internal.js b/js/src/jit-test/tests/promise/promise-race-with-default-resolving-internal.js new file mode 100644 index 0000000000..815124c46f --- /dev/null +++ b/js/src/jit-test/tests/promise/promise-race-with-default-resolving-internal.js @@ -0,0 +1,54 @@ +function newPromiseCapability() { + let resolve, reject, promise = new Promise(function(r1, r2) { + resolve = r1; + reject = r2; + }); + return {promise, resolve, reject}; +} + +function neverCalled() { + // Quit with non-zero exit code to ensure a test suite error is shown, + // even when this function is called within promise handlers which normally + // swallow any exceptions. + quit(1); +} + +var c = 0; +var g_resolve; + +class P extends Promise { + constructor(executor) { + // Only the very first object created through this constructor gets + // special treatment, all other invocations create built-in Promise + // objects. + if (c++ > 1) { + return new Promise(executor); + } + + // Pass a native ResolvePromiseFunction function as the resolve handler. + // (It's okay that the promise of this promise capability is never used.) + executor(newPromiseCapability().resolve, neverCalled); + + let {promise, resolve} = newPromiseCapability(); + g_resolve = resolve; + + // Use an async function to create a Promise without resolving functions. + return async function(){ await promise; return 456; }(); + } + + // Ensure we don't take the (spec) fast path in Promise.resolve and instead + // create a new promise object. (We could not provide an override at all + // and rely on the default behaviour, but giving an explicit definition + // may help to interpret this test case.) + static resolve(v) { + return super.resolve(v); + } +} + +let {promise: alwaysPending} = newPromiseCapability(); + +P.race([alwaysPending]).then(neverCalled, neverCalled); + +g_resolve(123); + +drainJobQueue(); |