Fix tests for new resolve lookup in Promise.allSettled

This commit is contained in:
Leo Balter 2019-04-24 14:37:54 -04:00
parent 24d1b6d59c
commit 3b2ad0b5d0
6 changed files with 129 additions and 64 deletions

View File

@ -24,57 +24,83 @@ features: [Promise.allSettled]
---*/ ---*/
var checkPoint = ''; var checkPoint = '';
Promise.allSettled.call(function(executor) { function fn1(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(); executor();
checkPoint += 'b'; checkPoint += 'b';
executor(function() {}, function() {}); executor(function() {}, function() {});
checkPoint += 'c'; checkPoint += 'c';
}, []); }
fn1.resolve = function() {
throw new Test262Error();
};
Promise.allSettled.call(fn1, []);
assert.sameValue(checkPoint, 'abc', 'executor initially called with no arguments'); assert.sameValue(checkPoint, 'abc', 'executor initially called with no arguments');
var checkPoint = ''; checkPoint = '';
Promise.allSettled.call(function(executor) { function fn2(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(undefined, undefined); executor(undefined, undefined);
checkPoint += 'b'; checkPoint += 'b';
executor(function() {}, function() {}); executor(function() {}, function() {});
checkPoint += 'c'; checkPoint += 'c';
}, []); }
fn2.resolve = function() {
throw new Test262Error();
};
Promise.allSettled.call(fn2, []);
assert.sameValue(checkPoint, 'abc', 'executor initially called with (undefined, undefined)'); assert.sameValue(checkPoint, 'abc', 'executor initially called with (undefined, undefined)');
var checkPoint = ''; checkPoint = '';
assert.throws(TypeError, function() { function fn3(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(undefined, function() {}); executor(undefined, function() {});
checkPoint += 'b'; checkPoint += 'b';
executor(function() {}, function() {}); executor(function() {}, function() {});
checkPoint += 'c'; checkPoint += 'c';
}, []); }
Object.defineProperty(fn3, 'resolve', {
get() {
throw new Test262Error();
}
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn3, []);
}, 'executor initially called with (undefined, function)'); }, 'executor initially called with (undefined, function)');
assert.sameValue(checkPoint, 'ab', 'executor initially called with (undefined, function)'); assert.sameValue(checkPoint, 'ab', 'executor initially called with (undefined, function)');
var checkPoint = ''; checkPoint = '';
assert.throws(TypeError, function() { function fn4(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(function() {}, undefined); executor(function() {}, undefined);
checkPoint += 'b'; checkPoint += 'b';
executor(function() {}, function() {}); executor(function() {}, function() {});
checkPoint += 'c'; checkPoint += 'c';
}, []); }
Object.defineProperty(fn4, 'resolve', {
get() {
throw new Test262Error();
}
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn4, []);
}, 'executor initially called with (function, undefined)'); }, 'executor initially called with (function, undefined)');
assert.sameValue(checkPoint, 'ab', 'executor initially called with (function, undefined)'); assert.sameValue(checkPoint, 'ab', 'executor initially called with (function, undefined)');
var checkPoint = ''; checkPoint = '';
assert.throws(TypeError, function() { function fn5(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor('invalid value', 123); executor('invalid value', 123);
checkPoint += 'b'; checkPoint += 'b';
executor(function() {}, function() {}); executor(function() {}, function() {});
checkPoint += 'c'; checkPoint += 'c';
}, []); }
Object.defineProperty(fn5, 'resolve', {
get() {
throw new Test262Error();
}
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn5, []);
}, 'executor initially called with (String, Number)'); }, 'executor initially called with (String, Number)');
assert.sameValue(checkPoint, 'ab', 'executor initially called with (String, Number)'); assert.sameValue(checkPoint, 'ab', 'executor initially called with (String, Number)');

View File

@ -25,59 +25,83 @@ features: [Promise.allSettled]
---*/ ---*/
var checkPoint = ''; var checkPoint = '';
assert.throws(TypeError, function() { function fn1(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
}, []); }
Object.defineProperty(fn1, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn1, []);
}, 'executor not called at all'); }, 'executor not called at all');
assert.sameValue(checkPoint, 'a', 'executor not called at all'); assert.sameValue(checkPoint, 'a', 'executor not called at all');
var checkPoint = ''; checkPoint = '';
assert.throws(TypeError, function() { function fn2(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(); executor();
checkPoint += 'b'; checkPoint += 'b';
}, []); }
Object.defineProperty(fn2, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn2, []);
}, 'executor called with no arguments'); }, 'executor called with no arguments');
assert.sameValue(checkPoint, 'ab', 'executor called with no arguments'); assert.sameValue(checkPoint, 'ab', 'executor called with no arguments');
var checkPoint = ''; checkPoint = '';
assert.throws(TypeError, function() { function fn3(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(undefined, undefined); executor(undefined, undefined);
checkPoint += 'b'; checkPoint += 'b';
}, []); }
Object.defineProperty(fn3, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn3, []);
}, 'executor called with (undefined, undefined)'); }, 'executor called with (undefined, undefined)');
assert.sameValue(checkPoint, 'ab', 'executor called with (undefined, undefined)'); assert.sameValue(checkPoint, 'ab', 'executor called with (undefined, undefined)');
var checkPoint = ''; checkPoint = '';
assert.throws(TypeError, function() { function fn4(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(undefined, function() {}); executor(undefined, function() {});
checkPoint += 'b'; checkPoint += 'b';
}, []); }
Object.defineProperty(fn4, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn4, []);
}, 'executor called with (undefined, function)'); }, 'executor called with (undefined, function)');
assert.sameValue(checkPoint, 'ab', 'executor called with (undefined, function)'); assert.sameValue(checkPoint, 'ab', 'executor called with (undefined, function)');
var checkPoint = ''; checkPoint = '';
assert.throws(TypeError, function() { function fn5(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(function() {}, undefined); executor(function() {}, undefined);
checkPoint += 'b'; checkPoint += 'b';
}, []); }
Object.defineProperty(fn5, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn5, []);
}, 'executor called with (function, undefined)'); }, 'executor called with (function, undefined)');
assert.sameValue(checkPoint, 'ab', 'executor called with (function, undefined)'); assert.sameValue(checkPoint, 'ab', 'executor called with (function, undefined)');
var checkPoint = ''; checkPoint = '';
assert.throws(TypeError, function() { function fn6(executor) {
Promise.allSettled.call(function(executor) {
checkPoint += 'a'; checkPoint += 'a';
executor(123, 'invalid value'); executor(123, 'invalid value');
checkPoint += 'b'; checkPoint += 'b';
}, []); }
Object.defineProperty(fn6, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(fn6, []);
}, 'executor called with (Number, String)'); }, 'executor called with (Number, String)');
assert.sameValue(checkPoint, 'ab', 'executor called with (Number, String)'); assert.sameValue(checkPoint, 'ab', 'executor called with (Number, String)');

View File

@ -55,6 +55,10 @@ var P = function(executor) {
}); });
}; };
P.resolve = function() {
throw new Test262Error();
};
Promise.allSettled.call(P, iter); Promise.allSettled.call(P, iter);
assert.sameValue(returnCount, 0); assert.sameValue(returnCount, 0);

View File

@ -43,6 +43,10 @@ var P = function(executor) {
}); });
}; };
P.resolve = function() {
throw new Test262Error();
};
Promise.allSettled.call(P, []) Promise.allSettled.call(P, [])
.then(function() { .then(function() {
$DONE('Promise incorrectly fulfilled.'); $DONE('Promise incorrectly fulfilled.');

View File

@ -3,7 +3,7 @@
/*--- /*---
description: > description: >
Error retrieving the constructor's `resolve` method (closing iterator) Error retrieving the constructor's `resolve` method not opening iterator
esid: sec-promise.allsettled esid: sec-promise.allsettled
info: | info: |
6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability). 6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
@ -21,9 +21,11 @@ features: [Promise.allSettled, Symbol.iterator]
var iter = {}; var iter = {};
var returnCount = 0; var returnCount = 0;
var nextCount = 0;
iter[Symbol.iterator] = function() { iter[Symbol.iterator] = function() {
return { return {
next() { next() {
nextCount += 1;
return { return {
done: false done: false
}; };
@ -42,4 +44,5 @@ Object.defineProperty(Promise, 'resolve', {
Promise.allSettled(iter); Promise.allSettled(iter);
assert.sameValue(returnCount, 1); assert.sameValue(nextCount, 0);
assert.sameValue(returnCount, 0);

View File

@ -22,4 +22,8 @@ Object.defineProperty(C, Symbol.species, {
} }
}); });
C.resolve = function() {
throw new Test262Error();
};
Promise.allSettled.call(C, []); Promise.allSettled.call(C, []);