diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/fromAsync/returns-promise.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Array/fromAsync/returns-promise.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/fromAsync/returns-promise.js b/js/src/tests/test262/built-ins/Array/fromAsync/returns-promise.js new file mode 100644 index 0000000000..a8b456d66e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/fromAsync/returns-promise.js @@ -0,0 +1,36 @@ +// |reftest| async +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.fromasync +description: Array.fromAsync returns a Promise +info: | + 5. Return _promiseCapability_.[[Promise]]. +flags: [async] +includes: [asyncHelpers.js] +features: [Array.fromAsync] +---*/ + +asyncTest(async function () { + let p = Array.fromAsync([0, 1, 2]); + + assert(p instanceof Promise, "Array.fromAsync returns a Promise"); + assert.sameValue( + Object.getPrototypeOf(p), + Promise.prototype, + "Array.fromAsync returns an object with prototype Promise.prototype" + ); + + p = Array.fromAsync([0, 1, 2], () => { + throw new Test262Error("this will make the Promise reject"); + }) + assert(p instanceof Promise, "Array.fromAsync returns a Promise even on error"); + assert.sameValue( + Object.getPrototypeOf(p), + Promise.prototype, + "Array.fromAsync returns an object with prototype Promise.prototype even on error" + ); + + await assert.throwsAsync(Test262Error, () => p, "Prevent unhandled rejection"); +}); |