Commit 9aa8ac8f authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Romain Courteaud

On crash, display list of all errors

parent cdf44572
...@@ -71,7 +71,12 @@ ...@@ -71,7 +71,12 @@
Monitor, Monitor,
scope_increment = 0, scope_increment = 0,
isAbsoluteOrDataURL = new RegExp('^(?:[a-z]+:)?//|data:', 'i'), isAbsoluteOrDataURL = new RegExp('^(?:[a-z]+:)?//|data:', 'i'),
is_page_unloaded = false; is_page_unloaded = false,
error_list = [];
window.addEventListener('error', function (error) {
error_list.push(error);
});
window.addEventListener('beforeunload', function () { window.addEventListener('beforeunload', function () {
// XXX If another listener cancel the page unload, // XXX If another listener cancel the page unload,
...@@ -91,6 +96,10 @@ ...@@ -91,6 +96,10 @@
} }
function letsCrash(e) { function letsCrash(e) {
var i,
body,
container,
paragraph;
if (is_page_unloaded) { if (is_page_unloaded) {
/*global console*/ /*global console*/
console.info('-- Error dropped, as page is unloaded'); console.info('-- Error dropped, as page is unloaded');
...@@ -113,7 +122,34 @@ ...@@ -113,7 +122,34 @@
} catch (ignore) { } catch (ignore) {
} }
} }
document.getElementsByTagName('body')[0].textContent = e; error_list.push(e);
body = document.getElementsByTagName('body')[0];
while (body.firstChild) {
body.removeChild(body.firstChild);
}
for (i = 0; i < error_list.length; i += 1) {
container = document.createElement("section");
paragraph = document.createElement("h2");
paragraph.textContent = error_list[i].message;
container.appendChild(paragraph);
if (error_list[i].fileName !== undefined) {
paragraph = document.createElement("p");
paragraph.textContent = 'File: ' +
error_list[i].fileName +
': ' + error_list[i].lineNumber;
container.appendChild(paragraph);
}
if (error_list[i].stack !== undefined) {
paragraph = document.createElement("pre");
paragraph.textContent = 'Stack: ' + error_list[i].stack;
container.appendChild(paragraph);
}
body.appendChild(container);
}
// XXX Do not crash the application if it fails // XXX Do not crash the application if it fails
// Where to write the error? // Where to write the error?
/*global console*/ /*global console*/
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Error event for renderJS test</title>
<meta name="viewport" content="width=device-width, height=device-height"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../node_modules/rsvp/dist/rsvp-2.0.4.js" type="text/javascript"></script>
<script src="../dist/renderjs-latest.js" type="text/javascript"></script>
<script>
window.getFoo = functypo {
return "foo";
};
</script>
<script>
rJS(window)
.declareService(function () {
return this.getElement()
.push(function (elt) {
elt.textContent = getFoo();
});
});
</script>
</head>
<body>
</body>
</html>
...@@ -4229,5 +4229,34 @@ ...@@ -4229,5 +4229,34 @@
}); });
}); });
test('check page error', function () {
var fixture = document.getElementById("qunit-fixture"),
iframe;
fixture.innerHTML =
"<iframe id=renderjsIframe src='./error_gadget.html'></iframe>";
iframe = document.getElementById('renderjsIframe');
stop();
return new RSVP.Promise(function (resolve, reject) {
iframe.addEventListener("load", function (evt) {
resolve(evt.target.result);
});
})
.then(function () {
var iframe_body = iframe.contentWindow.document.body,
iframe_text = iframe_body.textContent;
ok(true, iframe_text.indexOf('SyntaxError') !== -1, iframe_text);
ok(true, iframe_text.indexOf('getFoo') !== -1, iframe_text);
ok(true, iframe_text.indexOf('error_gadget.html') !== -1, iframe_text);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
}(document, renderJS, QUnit, sinon, URI, URL)); }(document, renderJS, QUnit, sinon, URI, URL));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment