blob: 9315c76e6598d26b2673f3708c46f5af11543842 [file] [log] [blame]
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var originalThen = Promise.prototype.then;
Promise.prototype.then = function (onFulfilled, onRejected) {
return originalThen.call(this, onFulfilled, onRejected);
};
var array = [];
for (var i = 0; i < 1e4; ++i) {
let value = i;
array.push(new Promise(function (resolve) { resolve(Promise.resolve(value)); }));
}
drainMicrotasks();
for (var i = 0; i < 1e4; ++i) {
let expected = i;
array[i].then(function (value) {
shouldBe(value, expected);
array[expected] = true;
});
}
drainMicrotasks();
for (var i = 0; i < 1e4; ++i)
shouldBe(array[i], true);