Created
April 15, 2020 08:16
-
-
Save BretCameron/5e9b790aef79e33e1389fb5fdf768d1e to your computer and use it in GitHub Desktop.
A snippet from V8's unit tests, taken for demonstration purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original source: v8/test/mjsunit/es6/promise-all-overflow-1.js | |
// https://github.com/v8/v8/blob/4b9b23521e6fd42373ebbcb20ebe03bf445494f9/test/mjsunit/es6/promise-all-overflow-1.js#L9-L12 | |
// Make sure we properly throw a RangeError when overflowing the maximum | |
// number of elements for Promise.all, which is capped at 2^21 bits right | |
// now, since we store the indices as identity hash on the resolve element | |
// closures. | |
const a = new Array(2 ** 21 - 1); | |
const p = Promise.resolve(1); | |
for (let i = 0; i < a.length; ++i) a[i] = p; | |
testAsync(assert => { | |
assert.plan(1); | |
Promise.all(a).then(assert.unreachable, reason => { | |
assert.equals(true, reason instanceof RangeError); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment