Skip to content

Commit 02ed417

Browse files
committed
Moving ExceptionLab stuff so it doesn't interfere with automated testing
1 parent b627146 commit 02ed417

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

test/functional/ExceptionLab.html

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Exception Lab</title>
6+
<style>
7+
#info {
8+
height: 25em;
9+
width: 100%;
10+
}
11+
</style>
12+
<script src="ExceptionLab.js"></script>
13+
<script>
14+
document.getElementById("userAgent").innerHTML = navigator.userAgent;
15+
16+
function dumpException(ex) {
17+
ex = ex || new Error("Default error");
18+
var text = "{\n " + getExceptionProps(ex).join(",\n ") + "\n}";
19+
document.getElementById("info").innerHTML = text;
20+
}
21+
22+
function dumpException1() {
23+
dumpException();
24+
}
25+
26+
function dumpException2() {
27+
try {
28+
undef();
29+
} catch (ex) {
30+
dumpException(ex);
31+
}
32+
}
33+
34+
function dumpException3() {
35+
dumpException((function(x) {
36+
try {
37+
x.undef();
38+
} catch (ex) {
39+
return ex;
40+
}
41+
})(null));
42+
}
43+
44+
function createException4() {
45+
return createException();
46+
}
47+
48+
function dumpException4() {
49+
dumpException(createException4());
50+
}
51+
</script>
52+
</head>
53+
<body>
54+
<span id="userAgent">userAgent</span>
55+
<script>
56+
document.getElementById("userAgent").innerHTML = navigator.userAgent;
57+
</script>
58+
<textarea id="info">Info</textarea>
59+
<br/>
60+
<button onclick="dumpException1();">Exception 1</button>
61+
<button onclick="dumpException2();">Exception 2</button>
62+
<button onclick="dumpException3();">Exception 3</button>
63+
<button onclick="dumpException4();">Exception 4</button>
64+
</body>
65+
</html>

test/functional/ExceptionLab.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function createException() {
2+
return ((function(x) {
3+
try {
4+
x.undef();
5+
} catch (ex) {
6+
return ex;
7+
}
8+
})(null));
9+
}
10+
11+
function printProp(prop, value) {
12+
if (typeof value === "string") {
13+
value = '"' + value.replace(/\"/g, '\\"').replace(/\r/g, "\\r").replace(/\n/g, '\\n" +\n "') + '"';
14+
}
15+
return prop + ': ' + value;
16+
}
17+
18+
function getExceptionProps(ex) {
19+
var prop, props = [], obj = {
20+
message: true,
21+
stack: true,
22+
stacktrace: true,
23+
'arguments': true
24+
};
25+
// find enumerable properties
26+
for (prop in ex) {
27+
obj[prop] = true;
28+
}
29+
30+
for (prop in obj) {
31+
var value = ex[prop];
32+
if (typeof value !== "undefined") {
33+
props.push(printProp(prop, value));
34+
}
35+
}
36+
return props;
37+
}

0 commit comments

Comments
 (0)