Debian Codegraph @

js/src/tests/test262/built-ins/Promise/all/capability-executor-called-twice.js

raw
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 esid: sec-promise.all
6 description: >
7 Throws a TypeError if capabilities executor already called with non-undefined values.
8 info: |
9 Promise.all ( iterable )
10
11 ...
12 6. Let promiseCapability be NewPromiseCapability(C).
13 7. ReturnIfAbrupt(promiseCapability).
14 ...
15
16 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 PerformPromiseAll ( iteratorRecord, constructor, resultCapability )
25
26 ...
27 1. Let promiseResolve be ? Get(constructor, `"resolve"`).
28 1. If IsCallable(promiseResolve) is *false*, throw a *TypeError* exception.
29 ...
30 ---*/
31
32 var checkPoint = "";
33 function fn1(executor) {
34 checkPoint += "a";
35 executor();
36 checkPoint += "b";
37 executor(function() {}, function() {});
38 checkPoint += "c";
39 }
40 fn1.resolve = function() {};
41 Promise.all.call(fn1, []);
42 assert.sameValue(checkPoint, "abc", "executor initially called with no arguments");
43
44 checkPoint = "";
45 function fn2(executor) {
46 checkPoint += "a";
47 executor(undefined, undefined);
48 checkPoint += "b";
49 executor(function() {}, function() {});
50 checkPoint += "c";
51 }
52 fn2.resolve = function() {};
53 Promise.all.call(fn2, []);
54 assert.sameValue(checkPoint, "abc", "executor initially called with (undefined, undefined)");
55
56 checkPoint = "";
57 function fn3(executor) {
58 checkPoint += "a";
59 executor(undefined, function() {});
60 checkPoint += "b";
61 executor(function() {}, function() {});
62 checkPoint += "c";
63 }
64 Object.defineProperty(fn3, 'resolve', {
65 get() { throw new Test262Error; }
66 });
67 assert.throws(TypeError, function() {
68 Promise.all.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() { throw new Test262Error; }
82 });
83 assert.throws(TypeError, function() {
84 Promise.all.call(fn4, []);
85 }, "executor initially called with (function, undefined)");
86 assert.sameValue(checkPoint, "ab", "executor initially called with (function, undefined)");
87
88 checkPoint = "";
89 function fn5(executor) {
90 checkPoint += "a";
91 executor("invalid value", 123);
92 checkPoint += "b";
93 executor(function() {}, function() {});
94 checkPoint += "c";
95 }
96 Object.defineProperty(fn5, 'resolve', {
97 get() { throw new Test262Error; }
98 });
99 assert.throws(TypeError, function() {
100 Promise.all.call(fn5, []);
101 }, "executor initially called with (String, Number)");
102 assert.sameValue(checkPoint, "ab", "executor initially called with (String, Number)");
103
104 reportCompare(0, 0);