capability-executor-not-callable.js (2749B)
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 either resolve or reject capability is not callable. 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 NewPromiseCapability ( C ) 17 ... 18 4. Let executor be a new built-in function object as defined in GetCapabilitiesExecutor Functions (25.4.1.5.1). 19 5. Set the [[Capability]] internal slot of executor to promiseCapability. 20 6. Let promise be Construct(C, «executor»). 21 7. ReturnIfAbrupt(promise). 22 8. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception. 23 9. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception. 24 ... 25 ---*/ 26 27 var checkPoint = ""; 28 assert.throws(TypeError, function() { 29 Promise.race.call(function(executor) { 30 checkPoint += "a"; 31 }, []); 32 }, "executor not called at all"); 33 assert.sameValue(checkPoint, "a", "executor not called at all"); 34 35 var checkPoint = ""; 36 assert.throws(TypeError, function() { 37 Promise.race.call(function(executor) { 38 checkPoint += "a"; 39 executor(); 40 checkPoint += "b"; 41 }, []); 42 }, "executor called with no arguments"); 43 assert.sameValue(checkPoint, "ab", "executor called with no arguments"); 44 45 var checkPoint = ""; 46 assert.throws(TypeError, function() { 47 Promise.race.call(function(executor) { 48 checkPoint += "a"; 49 executor(undefined, undefined); 50 checkPoint += "b"; 51 }, []); 52 }, "executor called with (undefined, undefined)"); 53 assert.sameValue(checkPoint, "ab", "executor called with (undefined, undefined)"); 54 55 var checkPoint = ""; 56 assert.throws(TypeError, function() { 57 Promise.race.call(function(executor) { 58 checkPoint += "a"; 59 executor(undefined, function() {}); 60 checkPoint += "b"; 61 }, []); 62 }, "executor called with (undefined, function)"); 63 assert.sameValue(checkPoint, "ab", "executor called with (undefined, function)"); 64 65 var checkPoint = ""; 66 assert.throws(TypeError, function() { 67 Promise.race.call(function(executor) { 68 checkPoint += "a"; 69 executor(function() {}, undefined); 70 checkPoint += "b"; 71 }, []); 72 }, "executor called with (function, undefined)"); 73 assert.sameValue(checkPoint, "ab", "executor called with (function, undefined)"); 74 75 var checkPoint = ""; 76 assert.throws(TypeError, function() { 77 Promise.race.call(function(executor) { 78 checkPoint += "a"; 79 executor(123, "invalid value"); 80 checkPoint += "b"; 81 }, []); 82 }, "executor called with (Number, String)"); 83 assert.sameValue(checkPoint, "ab", "executor called with (Number, String)"); 84 85 reportCompare(0, 0);