Bug 743049 - Part 2: Use the new API from NS_ScriptErrorReporter to get an error type name. r=jst

This commit is contained in:
Masatoshi Kimura 2012-04-11 17:55:22 -04:00
Родитель ab10f4e4db
Коммит 7988d128f1
7 изменённых файлов: 113 добавлений и 8 удалений

Просмотреть файл

@ -33,7 +33,7 @@ window.onerror = function(message, uri, line) {
</script> </script>
<script type="application/javascript"> <script type="application/javascript">
window.onerror = function(message, uri, line) { window.onerror = function(message, uri, line) {
is(message, "c is not defined", "Should have correct error message"); is(message, "ReferenceError: c is not defined", "Should have correct error message");
is(uri, is(uri,
"http://mochi.test:8888/tests/content/base/test/bug461735-redirect2.sjs", "http://mochi.test:8888/tests/content/base/test/bug461735-redirect2.sjs",
"Unexpected error location URI"); "Unexpected error location URI");

Просмотреть файл

@ -38,7 +38,7 @@ window.onerror = function(message, uri, line) {
errorFired = false; errorFired = false;
global = ""; global = "";
window.onerror = function(message, uri, line) { window.onerror = function(message, uri, line) {
is(message, "c is not defined", "Should have correct error message"); is(message, "ReferenceError: c is not defined", "Should have correct error message");
is(uri, is(uri,
"http://example.com/tests/content/base/test/bug696301-script-1.js", "http://example.com/tests/content/base/test/bug696301-script-1.js",
"Should also have correct script URI"); "Should also have correct script URI");

Просмотреть файл

@ -40,7 +40,7 @@ window.onerror = function(message, uri, line) {
errorFired = false; errorFired = false;
global = ""; global = "";
window.onerror = function(message, uri, line) { window.onerror = function(message, uri, line) {
is(message, "c is not defined", "Should have correct error message"); is(message, "ReferenceError: c is not defined", "Should have correct error message");
is(uri, is(uri,
"http://example.com/tests/content/base/test/bug696301-script-1.js", "http://example.com/tests/content/base/test/bug696301-script-1.js",
"Should also have correct script URI"); "Should also have correct script URI");

Просмотреть файл

@ -487,10 +487,15 @@ NS_ScriptErrorReporter(JSContext *cx,
fileName.AssignWithConversion(report->filename); fileName.AssignWithConversion(report->filename);
} }
const PRUnichar *m = reinterpret_cast<const PRUnichar*> const PRUnichar* m = static_cast<const PRUnichar*>(report->ucmessage);
(report->ucmessage);
if (m) { if (m) {
msg.Assign(m); const PRUnichar* n = static_cast<const PRUnichar*>
(js::GetErrorTypeNameFromNumber(cx, report->errorNumber));
if (n) {
msg.Assign(n);
msg.AppendLiteral(": ");
}
msg.Append(m);
} }
if (msg.IsEmpty() && message) { if (msg.IsEmpty() && message) {

Просмотреть файл

@ -153,6 +153,7 @@ _TEST_FILES = \
test_bug38959.html \ test_bug38959.html \
iframe_bug38959-1.html \ iframe_bug38959-1.html \
iframe_bug38959-2.html \ iframe_bug38959-2.html \
test_onerror_message.html \
$(NULL) $(NULL)
libs:: $(_TEST_FILES) libs:: $(_TEST_FILES)

Просмотреть файл

@ -21,7 +21,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=531176
var errorCount = 0; var errorCount = 0;
function errorHandler(msg, filename, linenr) { function errorHandler(msg, filename, linenr) {
is(msg, "syntax error", "Wrong error!"); is(msg, "SyntaxError: syntax error", "Wrong error!");
is(filename, window.location, "Wrong filename!"); is(filename, window.location, "Wrong filename!");
is(linenr, 1, "Wrong linenr!"); is(linenr, 1, "Wrong linenr!");
++errorCount; ++errorCount;
@ -34,7 +34,7 @@ document.body.onclick;
is(errorCount, 1, "Error handler should have been called! (1)"); is(errorCount, 1, "Error handler should have been called! (1)");
function recursiveHandler(msg, filename, linenr) { function recursiveHandler(msg, filename, linenr) {
is(msg, "syntax error", "Wrong error!"); is(msg, "SyntaxError: syntax error", "Wrong error!");
is(filename, window.location, "Wrong filename!"); is(filename, window.location, "Wrong filename!");
is(linenr, 1, "Wrong linenr!"); is(linenr, 1, "Wrong linenr!");
++errorCount; ++errorCount;

Просмотреть файл

@ -0,0 +1,99 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=743049
-->
<head>
<meta charset="UTF-8">
<title>Test for Bug 743049</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=743049">Mozilla Bug 743049</a>
<p id="display"></p>
<div id="content" style="display: none">
<iframe id="frame"></iframe>
</div>
<pre id="test">
<script type="application/javascript">
"use strict";
/** Test for Bug 743049 **/
var expected = [
{ name: "Error", message: "foo", filename: location, lineNumber: 45 },
{ name: "Error", message: "foo", filename: "bar", lineNumber: 123 },
{ name: "", message: "uncaught exception: [object Object]" },
{ name: "DuckError", message: "foo", filename: "bar", lineNumber: 123 },
{ name: "", message: "uncaught exception: [object Object]" },
{ name: "", message: "foo", filename: "baz", lineNumber: 123 },
{ name: "", message: "uncaught exception: [object Object]" },
{ name: "InvalidStateError", message: "An attempt was made to use an object that is not, or is no longer, usable", filename: location, lineNumber: 60 },
{ name: "ReferenceError", message: "xxx is not defined", filename: location, lineNumber: 64 },
{ name: "ReferenceError", message: "xxx is not defined", filename: location, lineNumber: 66 }
];
var counter = 0;
var origin = location.protocol + "//" + location.host;
postMessage(counter, origin);
window.onmessage = function(e) {
if (e.origin !== origin)
return;
try {
if (e.data == 0) {
throw new Error("foo");
} else if (e.data == 1) {
throw new Error("foo","bar",123);
} else if (e.data == 2) {
throw {};
} else if (e.data == 3) {
throw {name:"DuckError",message:"foo",filename:"bar",lineNumber:123};
} else if (e.data == 4) {
throw {name:"DuckError",filename:"bar",lineNumber:123};
} else if (e.data == 5) {
throw {message:"foo",fileName:"baz",lineNumber:123};
} else if (e.data == 6) {
throw {name:3,message:4,lineNumber:123};
} else if (e.data == 7) {
var x = new XMLHttpRequest();
x.responseType = "arraybuffer";
x.open("GET", location, false);
var a = x.send();
} else if (e.data == 8) {
throw new ReferenceError("xxx is not defined");
} else if (e.data == 9) {
new xxx;
} else {
SimpleTest.finish();
return;
}
} catch (e) {
if (e instanceof Error || typeof e.message=="string" &&
("filename" in e || "fileName" in e) && "lineNumber" in e) {
is(e.message, expected[counter].message, counter + " catch message");
is(e.filename || e.fileName, expected[counter].filename, counter + " catch filename");
is(e.lineNumber, expected[counter].lineNumber, counter + " catch lineno");
} else {
is("uncaught exception: " + e, expected[counter].message, counter + " catch message");
is(undefined, expected[counter].filename, counter + " catch filename");
is(undefined, expected[counter].lineNumber, counter + " catch lineno");
}
throw e;
}
ok(false, counter + " Error should be thrown or test should finish");
};
window.onerror = function(message, filename, lineno) {
is(message, Error.prototype.toString.call(expected[counter]), counter + " onerror message");
is(filename, expected[counter].filename || "", counter + " onerror filename");
is(lineno, expected[counter].lineNumber || 0, counter + " onerror lineno");
postMessage(++counter, origin);
return true;
};
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>