Debian Codegraph @

js/src/tests/non262/ShadowRealms/error.js

raw
1 // |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell)
2
3 let sr = new ShadowRealm();
4
5 try {
6 sr.evaluate("throw new Error('hi')");
7 assertEq(true, false, "Should have thrown");
8 } catch (e) {
9 assertEq(e instanceof TypeError, true, "Correct type of error")
10 assertEq(/Error: hi/.test(e.message), true, "Should have included information from thrown error");
11 }
12
13 try {
14 sr.evaluate("throw new Error('∂å∂')");
15 assertEq(true, false, "Should have thrown");
16 } catch (e) {
17 assertEq(e instanceof TypeError, true, "Correct type of error")
18 assertEq(/Error: ∂å∂/.test(e.message), true, "Should have included information from thrown error, UTF-8 Pass through.");
19 }
20
21 try {
22 sr.evaluate("throw {name: 'Hello', message: 'goodbye'}");
23 assertEq(true, false, "Should have thrown");
24 } catch (e) {
25 assertEq(e instanceof TypeError, true, "Correct type of error")
26 assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic fillin message, non-string");
27 }
28
29 try {
30 sr.evaluate("throw {name: 10, message: 11}");
31 assertEq(true, false, "Should have thrown");
32 } catch (e) {
33 assertEq(e instanceof TypeError, true, "Correct type of error")
34 assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic fillin message, non-string");
35 }
36
37
38 try {
39 sr.evaluate("throw { get name() { return 'holy'; }, get message() { return 'smokes' } }");
40 assertEq(true, false, "Should have thrown");
41 } catch (e) {
42 assertEq(e instanceof TypeError, true, "Correct type of error")
43 assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message, getters");
44 }
45
46 // Wrapped Functions
47 try {
48 var wrapped = sr.evaluate("() => { throw new Error('hi') }");
49 assertEq(!!wrapped, true, "Wrapped created");
50 wrapped();
51 assertEq(true, false, "Should have thrown");
52 } catch (e) {
53 assertEq(e instanceof TypeError, true, "Correct type of error")
54 assertEq(/Error: hi/.test(e.message), true, "Should have included information from thrown error");
55 }
56
57 try {
58 var wrapped = sr.evaluate("() => { throw new Error('∂å∂') } ");
59 assertEq(!!wrapped, true, "Wrapped created");
60 wrapped();
61 assertEq(true, false, "Should have thrown");
62 } catch (e) {
63 assertEq(e instanceof TypeError, true, "Correct type of error")
64 assertEq(/Error: ∂å∂/.test(e.message), true, "Should have included information from thrown error, UTF-8 Pass through.");
65 }
66
67 try {
68 var wrapped = sr.evaluate("() => { throw {name: 'Hello', message: 'goodbye'} } ");
69 assertEq(!!wrapped, true, "Wrapped created");
70 wrapped();
71 assertEq(true, false, "Should have thrown");
72 } catch (e) {
73 assertEq(e instanceof TypeError, true, "Correct type of error")
74 assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message");
75 }
76
77 try {
78 var wrapped = sr.evaluate("() => { throw {name: 10, message: 11} } ");
79 assertEq(!!wrapped, true, "Wrapped created");
80 wrapped();
81 assertEq(true, false, "Should have thrown");
82 } catch (e) {
83 assertEq(e instanceof TypeError, true, "Correct type of error")
84 print(e.message)
85 assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message");
86 }
87
88
89 try {
90 var wrapped = sr.evaluate("() => { throw { get name() { return 'holy'; }, get message() { return 'smokes' } } } ");
91 assertEq(!!wrapped, true, "Wrapped created");
92 wrapped();
93 assertEq(true, false, "Should have thrown");
94 } catch (e) {
95 assertEq(e instanceof TypeError, true, "Correct type of error")
96 assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message");
97 }
98
99
100
101 if (typeof reportCompare === 'function')
102 reportCompare(true, true);