forked from stacktracejs/stacktrace.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Moving ExceptionLab stuff so it doesn't interfere with automated testing
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Exception Lab</title> | ||
<style> | ||
#info { | ||
height: 25em; | ||
width: 100%; | ||
} | ||
</style> | ||
<script src="ExceptionLab.js"></script> | ||
<script> | ||
document.getElementById("userAgent").innerHTML = navigator.userAgent; | ||
|
||
function dumpException(ex) { | ||
ex = ex || new Error("Default error"); | ||
var text = "{\n " + getExceptionProps(ex).join(",\n ") + "\n}"; | ||
document.getElementById("info").innerHTML = text; | ||
} | ||
|
||
function dumpException1() { | ||
dumpException(); | ||
} | ||
|
||
function dumpException2() { | ||
try { | ||
undef(); | ||
} catch (ex) { | ||
dumpException(ex); | ||
} | ||
} | ||
|
||
function dumpException3() { | ||
dumpException((function(x) { | ||
try { | ||
x.undef(); | ||
} catch (ex) { | ||
return ex; | ||
} | ||
})(null)); | ||
} | ||
|
||
function createException4() { | ||
return createException(); | ||
} | ||
|
||
function dumpException4() { | ||
dumpException(createException4()); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<span id="userAgent">userAgent</span> | ||
<script> | ||
document.getElementById("userAgent").innerHTML = navigator.userAgent; | ||
</script> | ||
<textarea id="info">Info</textarea> | ||
<br/> | ||
<button onclick="dumpException1();">Exception 1</button> | ||
<button onclick="dumpException2();">Exception 2</button> | ||
<button onclick="dumpException3();">Exception 3</button> | ||
<button onclick="dumpException4();">Exception 4</button> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function createException() { | ||
return ((function(x) { | ||
try { | ||
x.undef(); | ||
} catch (ex) { | ||
return ex; | ||
} | ||
})(null)); | ||
} | ||
|
||
function printProp(prop, value) { | ||
if (typeof value === "string") { | ||
value = '"' + value.replace(/\"/g, '\\"').replace(/\r/g, "\\r").replace(/\n/g, '\\n" +\n "') + '"'; | ||
} | ||
return prop + ': ' + value; | ||
} | ||
|
||
function getExceptionProps(ex) { | ||
var prop, props = [], obj = { | ||
message: true, | ||
stack: true, | ||
stacktrace: true, | ||
'arguments': true | ||
}; | ||
// find enumerable properties | ||
for (prop in ex) { | ||
obj[prop] = true; | ||
} | ||
|
||
for (prop in obj) { | ||
var value = ex[prop]; | ||
if (typeof value !== "undefined") { | ||
props.push(printProp(prop, value)); | ||
} | ||
} | ||
return props; | ||
} |