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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for page errors</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript;version=1.8" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for page errors</p>
<script class="testbody" type="text/javascript;version=1.8">
SimpleTest.waitForExplicitFinish();
let expectedPageErrors = [];
function doPageErrors()
{
expectedPageErrors = {
"document.body.style.color = 'fooColor';": {
errorMessage: /fooColor/,
errorMessageName: undefined,
sourceName: /test_page_errors/,
category: "CSS Parser",
timeStamp: /^\d+$/,
error: false,
warning: true,
exception: false,
strict: false,
},
"document.doTheImpossible();": {
errorMessage: /doTheImpossible/,
errorMessageName: undefined,
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
strict: false,
},
"(42).toString(0);": {
errorMessage: /radix/,
errorMessageName: "JSMSG_BAD_RADIX",
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
strict: false,
},
"'use strict'; (Object.freeze({name: 'Elsa', score: 157})).score = 0;": {
errorMessage: /read.only/,
errorMessageName: "JSMSG_READ_ONLY",
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
},
"([]).length = -1": {
errorMessage: /array length/,
errorMessageName: "JSMSG_BAD_ARRAY_LENGTH",
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
},
"'abc'.repeat(-1);": {
errorMessage: /repeat count.*non-negative/,
errorMessageName: "JSMSG_NEGATIVE_REPETITION_COUNT",
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
},
"'a'.repeat(2e28);": {
errorMessage: /repeat count.*less than infinity/,
errorMessageName: "JSMSG_RESULTING_STRING_TOO_LARGE",
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
},
"77.1234.toExponential(-1);": {
errorMessage: /out of range/,
errorMessageName: "JSMSG_PRECISION_RANGE",
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
},
"var f = Function('x y', 'return x + y;');": {
errorMessage: /malformed formal/,
errorMessageName: "JSMSG_BAD_FORMAL",
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
},
"function a() { return; 1 + 1; }": {
errorMessage: /unreachable code/,
errorMessageName: "JSMSG_STMT_AFTER_RETURN",
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: true,
exception: false,
},
};
let container = document.createElement("script");
for (let stmt of Object.keys(expectedPageErrors)) {
if (expectedPageErrors[stmt].exception) {
SimpleTest.expectUncaughtException();
}
info("starting stmt: " + stmt);
container = document.createElement("script");
document.body.appendChild(container);
container.textContent = stmt;
document.body.removeChild(container);
info("ending stmt: " + stmt);
}
}
function startTest()
{
removeEventListener("load", startTest);
attachConsole(["PageError"], onAttach);
}
function onAttach(aState, aResponse)
{
onPageError = onPageError.bind(null, aState);
aState.dbgClient.addListener("pageError", onPageError);
doPageErrors();
}
let pageErrors = [];
function onPageError(aState, aType, aPacket)
{
if (!aPacket.pageError.sourceName.includes("test_page_errors")) {
info("Ignoring error from unknown source: " + aPacket.pageError.sourceName);
return;
}
is(aPacket.from, aState.actor, "page error actor");
pageErrors.push(aPacket.pageError);
if (pageErrors.length != Object.keys(expectedPageErrors).length) {
return;
}
aState.dbgClient.removeListener("pageError", onPageError);
Object.values(expectedPageErrors).forEach(function(aMessage, aIndex) {
info("checking received page error #" + aIndex);
checkObject(pageErrors[aIndex], Object.values(expectedPageErrors)[aIndex]);
});
closeDebugger(aState, function() {
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>
|