Debian Codegraph @

js/src/jit-test/tests/basic/iterable-error-messages.js

raw
1 // |jit-test| skip-if: getBuildConfiguration('pbl')
2
3 function assertThrowsMsgEndsWith(f, msg) {
4 try {
5 f();
6 assertEq(0, 1);
7 } catch(e) {
8 assertEq(e instanceof TypeError, true);
9 assertEq(e.message.endsWith(msg), true);
10 }
11 }
12
13 // For-of
14 function testForOf(val) {
15 for (var x of val) {}
16 }
17 for (v of [{}, Math, new Proxy({}, {})]) {
18 assertThrowsMsgEndsWith(() => testForOf(v), "val is not iterable");
19 }
20 assertThrowsMsgEndsWith(() => testForOf(null), "val is null");
21 assertThrowsMsgEndsWith(() => { for (var x of () => 1) {}}, "() => 1 is not iterable");
22
23 // Destructuring
24 function testDestr(val) {
25 var [a, b] = val;
26 }
27 for (v of [{}, Math, new Proxy({}, {})]) {
28 assertThrowsMsgEndsWith(() => testDestr(v), "val is not iterable");
29 }
30 assertThrowsMsgEndsWith(() => testDestr(null), "val is null");
31 assertThrowsMsgEndsWith(() => { [a, b] = () => 1; }, "() => 1 is not iterable");
32
33 // Spread
34 function testSpread(val) {
35 [...val];
36 }
37 for (v of [{}, Math, new Proxy({}, {})]) {
38 assertThrowsMsgEndsWith(() => testSpread(v), "val is not iterable");
39 }
40 assertThrowsMsgEndsWith(() => testSpread(null), "val is null");
41 assertThrowsMsgEndsWith(() => { [...() => 1]; }, "() => 1 is not iterable");