summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/ShadowRealms/error.js
blob: 0d0a559b28348fe179c43cdfd98d24b4714b7e07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell)

let sr = new ShadowRealm();

try {
    sr.evaluate("throw new Error('hi')");
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/Error: hi/.test(e.message), true, "Should have included information from thrown error");
}

try {
    sr.evaluate("throw new Error('∂å∂')");
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/Error: ∂å∂/.test(e.message), true, "Should have included information from thrown error, UTF-8 Pass through.");
}

try {
    sr.evaluate("throw {name: 'Hello', message: 'goodbye'}");
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic fillin message, non-string");
}

try {
    sr.evaluate("throw {name: 10, message: 11}");
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic fillin message, non-string");
}


try {
    sr.evaluate("throw { get name() { return 'holy'; }, get message() { return 'smokes' } }");
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message, getters");
}

// Wrapped Functions
try {
    var wrapped = sr.evaluate("() => { throw new Error('hi') }");
    assertEq(!!wrapped, true, "Wrapped created");
    wrapped();
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/Error: hi/.test(e.message), true, "Should have included information from thrown error");
}

try {
    var wrapped = sr.evaluate("() => { throw new Error('∂å∂') } ");
    assertEq(!!wrapped, true, "Wrapped created");
    wrapped();
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/Error: ∂å∂/.test(e.message), true, "Should have included information from thrown error, UTF-8 Pass through.");
}

try {
    var wrapped = sr.evaluate("() => { throw {name: 'Hello', message: 'goodbye'} } ");
    assertEq(!!wrapped, true, "Wrapped created");
    wrapped();
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message");
}

try {
    var wrapped = sr.evaluate("() =>  { throw {name: 10, message: 11} } ");
    assertEq(!!wrapped, true, "Wrapped created");
    wrapped();
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    print(e.message)
    assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message");
}


try {
    var wrapped = sr.evaluate("() => {  throw { get name() { return 'holy'; }, get message() { return 'smokes' } } } ");
    assertEq(!!wrapped, true, "Wrapped created");
    wrapped();
    assertEq(true, false, "Should have thrown");
} catch (e) {
    assertEq(e instanceof TypeError, true, "Correct type of error")
    assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message");
}



if (typeof reportCompare === 'function')
    reportCompare(true, true);