| 1 |
function newPromiseCapability() { |
| 2 |
let resolve, reject, promise = new Promise(function(r1, r2) { |
| 3 |
resolve = r1; |
| 4 |
reject = r2; |
| 5 |
}); |
| 6 |
return {promise, resolve, reject}; |
| 7 |
} |
| 8 |
|
| 9 |
function neverCalled() { |
| 10 |
// Quit with non-zero exit code to ensure a test suite error is shown, |
| 11 |
// even when this function is called within promise handlers which normally |
| 12 |
// swallow any exceptions. |
| 13 |
quit(1); |
| 14 |
} |
| 15 |
|
| 16 |
var c = 0; |
| 17 |
var g_resolve; |
| 18 |
|
| 19 |
class P extends Promise { |
| 20 |
constructor(executor) { |
| 21 |
// Only the very first object created through this constructor gets |
| 22 |
// special treatment, all other invocations create built-in Promise |
| 23 |
// objects. |
| 24 |
if (c++ > 1) { |
| 25 |
return new Promise(executor); |
| 26 |
} |
| 27 |
|
| 28 |
// Pass a native ResolvePromiseFunction function as the resolve handler. |
| 29 |
// (It's okay that the promise of this promise capability is never used.) |
| 30 |
executor(newPromiseCapability().resolve, neverCalled); |
| 31 |
|
| 32 |
let {promise, resolve} = newPromiseCapability(); |
| 33 |
g_resolve = resolve; |
| 34 |
|
| 35 |
// Use an async function to create a Promise without resolving functions. |
| 36 |
return async function(){ await promise; return 456; }(); |
| 37 |
} |
| 38 |
|
| 39 |
// Ensure we don't take the (spec) fast path in Promise.resolve and instead |
| 40 |
// create a new promise object. (We could not provide an override at all |
| 41 |
// and rely on the default behaviour, but giving an explicit definition |
| 42 |
// may help to interpret this test case.) |
| 43 |
static resolve(v) { |
| 44 |
return super.resolve(v); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
let {promise: alwaysPending} = newPromiseCapability(); |
| 49 |
|
| 50 |
P.race([alwaysPending]).then(neverCalled, neverCalled); |
| 51 |
|
| 52 |
g_resolve(123); |
| 53 |
|
| 54 |
drainJobQueue(); |