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 = '';
Promise.allSettled.call(function(executor) {
function fn1(executor) {
checkPoint += 'a';
executor();
checkPoint += 'b';
executor(function() {}, function() {});
checkPoint += 'c';
}, []);
}
fn1.resolve = function() {
throw new Test262Error();
};
Promise.allSettled.call(fn1, []);
assert.sameValue(checkPoint, 'abc', 'executor initially called with no arguments');
var checkPoint = '';
Promise.allSettled.call(function(executor) {
checkPoint = '';
function fn2(executor) {
checkPoint += 'a';
executor(undefined, undefined);
checkPoint += 'b';
executor(function() {}, function() {});
checkPoint += 'c';
}, []);
}
fn2.resolve = function() {
throw new Test262Error();
};
Promise.allSettled.call(fn2, []);
assert.sameValue(checkPoint, 'abc', 'executor initially called with (undefined, undefined)');
var checkPoint = '';
checkPoint = '';
function fn3(executor) {
checkPoint += 'a';
executor(undefined, function() {});
checkPoint += 'b';
executor(function() {}, function() {});
checkPoint += 'c';
}
Object.defineProperty(fn3, 'resolve', {
get() {
throw new Test262Error();
}
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
executor(undefined, function() {});
checkPoint += 'b';
executor(function() {}, function() {});
checkPoint += 'c';
}, []);
Promise.allSettled.call(fn3, []);
}, 'executor initially called with (undefined, function)');
assert.sameValue(checkPoint, 'ab', 'executor initially called with (undefined, function)');
var checkPoint = '';
checkPoint = '';
function fn4(executor) {
checkPoint += 'a';
executor(function() {}, undefined);
checkPoint += 'b';
executor(function() {}, function() {});
checkPoint += 'c';
}
Object.defineProperty(fn4, 'resolve', {
get() {
throw new Test262Error();
}
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
executor(function() {}, undefined);
checkPoint += 'b';
executor(function() {}, function() {});
checkPoint += 'c';
}, []);
Promise.allSettled.call(fn4, []);
}, 'executor initially called with (function, undefined)');
assert.sameValue(checkPoint, 'ab', 'executor initially called with (function, undefined)');
var checkPoint = '';
checkPoint = '';
function fn5(executor) {
checkPoint += 'a';
executor('invalid value', 123);
checkPoint += 'b';
executor(function() {}, function() {});
checkPoint += 'c';
}
Object.defineProperty(fn5, 'resolve', {
get() {
throw new Test262Error();
}
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
executor('invalid value', 123);
checkPoint += 'b';
executor(function() {}, function() {});
checkPoint += 'c';
}, []);
Promise.allSettled.call(fn5, []);
}, '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 = '';
function fn1(executor) {
checkPoint += 'a';
}
Object.defineProperty(fn1, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
}, []);
Promise.allSettled.call(fn1, []);
}, 'executor not called at all');
assert.sameValue(checkPoint, 'a', 'executor not called at all');
var checkPoint = '';
checkPoint = '';
function fn2(executor) {
checkPoint += 'a';
executor();
checkPoint += 'b';
}
Object.defineProperty(fn2, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
executor();
checkPoint += 'b';
}, []);
Promise.allSettled.call(fn2, []);
}, 'executor called with no arguments');
assert.sameValue(checkPoint, 'ab', 'executor called with no arguments');
var checkPoint = '';
checkPoint = '';
function fn3(executor) {
checkPoint += 'a';
executor(undefined, undefined);
checkPoint += 'b';
}
Object.defineProperty(fn3, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
executor(undefined, undefined);
checkPoint += 'b';
}, []);
Promise.allSettled.call(fn3, []);
}, 'executor called with (undefined, undefined)');
assert.sameValue(checkPoint, 'ab', 'executor called with (undefined, undefined)');
var checkPoint = '';
checkPoint = '';
function fn4(executor) {
checkPoint += 'a';
executor(undefined, function() {});
checkPoint += 'b';
}
Object.defineProperty(fn4, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
executor(undefined, function() {});
checkPoint += 'b';
}, []);
Promise.allSettled.call(fn4, []);
}, 'executor called with (undefined, function)');
assert.sameValue(checkPoint, 'ab', 'executor called with (undefined, function)');
var checkPoint = '';
checkPoint = '';
function fn5(executor) {
checkPoint += 'a';
executor(function() {}, undefined);
checkPoint += 'b';
}
Object.defineProperty(fn5, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
executor(function() {}, undefined);
checkPoint += 'b';
}, []);
Promise.allSettled.call(fn5, []);
}, 'executor called with (function, undefined)');
assert.sameValue(checkPoint, 'ab', 'executor called with (function, undefined)');
var checkPoint = '';
checkPoint = '';
function fn6(executor) {
checkPoint += 'a';
executor(123, 'invalid value');
checkPoint += 'b';
}
Object.defineProperty(fn6, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allSettled.call(function(executor) {
checkPoint += 'a';
executor(123, 'invalid value');
checkPoint += 'b';
}, []);
Promise.allSettled.call(fn6, []);
}, '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);
assert.sameValue(returnCount, 0);

View File

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

View File

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