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