Debian Codegraph @

js/src/tests/test262/built-ins/Promise/any/capability-executor-not-callable.js

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