Skip to content

Commit

Permalink
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
eriwen committed Nov 15, 2011
1 parent b627146 commit 02ed417
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/functional/ExceptionLab.html
@@ -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>
37 changes: 37 additions & 0 deletions test/functional/ExceptionLab.js
@@ -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;
}

0 comments on commit 02ed417

Please sign in to comment.