| 1 |
// Copyright (C) 2019 Leo Balter. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-promise.allsettled |
| 6 |
description: > |
| 7 |
Throws a TypeError if capabilities executor already called with non-undefined values. |
| 8 |
info: | |
| 9 |
Promise.allSettled ( iterable ) |
| 10 |
|
| 11 |
... |
| 12 |
3. Let promiseCapability be ? NewPromiseCapability(C). |
| 13 |
... |
| 14 |
|
| 15 |
GetCapabilitiesExecutor Functions |
| 16 |
|
| 17 |
... |
| 18 |
4. If promiseCapability.[[Resolve]] is not undefined, throw a TypeError exception. |
| 19 |
5. If promiseCapability.[[Reject]] is not undefined, throw a TypeError exception. |
| 20 |
6. Set promiseCapability.[[Resolve]] to resolve. |
| 21 |
7. Set promiseCapability.[[Reject]] to reject. |
| 22 |
... |
| 23 |
features: [Promise.allSettled] |
| 24 |
---*/ |
| 25 |
|
| 26 |
var checkPoint = ''; |
| 27 |
function fn1(executor) { |
| 28 |
checkPoint += 'a'; |
| 29 |
executor(); |
| 30 |
checkPoint += 'b'; |
| 31 |
executor(function() {}, function() {}); |
| 32 |
checkPoint += 'c'; |
| 33 |
} |
| 34 |
fn1.resolve = function() { |
| 35 |
throw new Test262Error(); |
| 36 |
}; |
| 37 |
Promise.allSettled.call(fn1, []); |
| 38 |
assert.sameValue(checkPoint, 'abc', 'executor initially called with no arguments'); |
| 39 |
|
| 40 |
checkPoint = ''; |
| 41 |
function fn2(executor) { |
| 42 |
checkPoint += 'a'; |
| 43 |
executor(undefined, undefined); |
| 44 |
checkPoint += 'b'; |
| 45 |
executor(function() {}, function() {}); |
| 46 |
checkPoint += 'c'; |
| 47 |
} |
| 48 |
fn2.resolve = function() { |
| 49 |
throw new Test262Error(); |
| 50 |
}; |
| 51 |
Promise.allSettled.call(fn2, []); |
| 52 |
assert.sameValue(checkPoint, 'abc', 'executor initially called with (undefined, undefined)'); |
| 53 |
|
| 54 |
checkPoint = ''; |
| 55 |
function fn3(executor) { |
| 56 |
checkPoint += 'a'; |
| 57 |
executor(undefined, function() {}); |
| 58 |
checkPoint += 'b'; |
| 59 |
executor(function() {}, function() {}); |
| 60 |
checkPoint += 'c'; |
| 61 |
} |
| 62 |
Object.defineProperty(fn3, 'resolve', { |
| 63 |
get() { |
| 64 |
throw new Test262Error(); |
| 65 |
} |
| 66 |
}); |
| 67 |
assert.throws(TypeError, function() { |
| 68 |
Promise.allSettled.call(fn3, []); |
| 69 |
}, 'executor initially called with (undefined, function)'); |
| 70 |
assert.sameValue(checkPoint, 'ab', 'executor initially called with (undefined, function)'); |
| 71 |
|
| 72 |
checkPoint = ''; |
| 73 |
function fn4(executor) { |
| 74 |
checkPoint += 'a'; |
| 75 |
executor(function() {}, undefined); |
| 76 |
checkPoint += 'b'; |
| 77 |
executor(function() {}, function() {}); |
| 78 |
checkPoint += 'c'; |
| 79 |
} |
| 80 |
Object.defineProperty(fn4, 'resolve', { |
| 81 |
get() { |
| 82 |
throw new Test262Error(); |
| 83 |
} |
| 84 |
}); |
| 85 |
assert.throws(TypeError, function() { |
| 86 |
Promise.allSettled.call(fn4, []); |
| 87 |
}, 'executor initially called with (function, undefined)'); |
| 88 |
assert.sameValue(checkPoint, 'ab', 'executor initially called with (function, undefined)'); |
| 89 |
|
| 90 |
checkPoint = ''; |
| 91 |
function fn5(executor) { |
| 92 |
checkPoint += 'a'; |
| 93 |
executor('invalid value', 123); |
| 94 |
checkPoint += 'b'; |
| 95 |
executor(function() {}, function() {}); |
| 96 |
checkPoint += 'c'; |
| 97 |
} |
| 98 |
Object.defineProperty(fn5, 'resolve', { |
| 99 |
get() { |
| 100 |
throw new Test262Error(); |
| 101 |
} |
| 102 |
}); |
| 103 |
assert.throws(TypeError, function() { |
| 104 |
Promise.allSettled.call(fn5, []); |
| 105 |
}, 'executor initially called with (String, Number)'); |
| 106 |
assert.sameValue(checkPoint, 'ab', 'executor initially called with (String, Number)'); |
| 107 |
|
| 108 |
reportCompare(0, 0); |