Skip to content

Instantly share code, notes, and snippets.

@BretCameron
Created April 15, 2020 08:16
Show Gist options
  • Save BretCameron/5e9b790aef79e33e1389fb5fdf768d1e to your computer and use it in GitHub Desktop.
Save BretCameron/5e9b790aef79e33e1389fb5fdf768d1e to your computer and use it in GitHub Desktop.
A snippet from V8's unit tests, taken for demonstration purposes
// 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