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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
load(libdir + "../../tests/ecma_6/shell.js");
if (typeof assertWarning === 'undefined') {
var assertWarning = function assertWarning(f, errorClass, msg) {
var hadWerror = options().split(",").indexOf("werror") !== -1;
// Ensure the "werror" option is disabled.
if (hadWerror)
options("werror");
try {
f();
} catch (exc) {
if (hadWerror)
options("werror");
// print() rather than throw a different exception value, in case
// the caller wants exc.stack.
if (msg)
print("assertWarning: " + msg);
print("assertWarning: Unexpected exception calling " + f +
" with warnings-as-errors disabled");
throw exc;
}
// Enable the "werror" option.
options("werror");
try {
assertThrowsInstanceOf(f, errorClass, msg);
} catch (exc) {
if (msg)
print("assertWarning: " + msg);
throw exc;
} finally {
if (!hadWerror)
options("werror");
}
};
}
if (typeof assertNoWarning === 'undefined') {
var assertNoWarning = function assertWarning(f, msg) {
// Ensure the "werror" option is enabled.
var hadWerror = options().split(",").indexOf("werror") !== -1;
if (!hadWerror)
options("werror");
try {
f();
} catch (exc) {
if (msg)
print("assertNoWarning: " + msg);
print("assertNoWarning: Unexpected exception calling " + f +
"with warnings-as-errors enabled");
throw exc;
} finally {
if (!hadWerror)
options("werror");
}
};
}
if (typeof assertErrorMessage === 'undefined') {
var assertErrorMessage = function assertErrorMessage(f, ctor, test) {
try {
f();
} catch (e) {
if (!(e instanceof ctor))
throw new Error("Assertion failed: expected exception " + ctor.name + ", got " + e);
if (typeof test == "string") {
if (test != e.message)
throw new Error("Assertion failed: expected " + test + ", got " + e.message);
} else {
if (!test.test(e.message))
throw new Error("Assertion failed: expected " + test.toString() + ", got " + e.message);
}
return;
}
throw new Error("Assertion failed: expected exception " + ctor.name + ", no exception thrown");
};
}
if (typeof assertTypeErrorMessage === 'undefined') {
var assertTypeErrorMessage = function assertTypeErrorMessage(f, test) {
assertErrorMessage(f, TypeError, test);
};
}
if (typeof assertRangeErrorMessage === 'undefined') {
var assertRangeErrorMessage = function assertRangeErrorMessage(f, test) {
assertErrorMessage(f, RangeError, test);
};
}
|