Bug 558182 - 'Workers: Don't assume we always get a JSErrorReport in DOMWorkerErrorReporter'. r=mrbkap.

This commit is contained in:
Ben Turner 2010-04-08 15:57:45 -07:00
Родитель 60f6a7b719
Коммит 8f32ed7d0e
4 изменённых файлов: 71 добавлений и 22 удалений

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

@ -578,29 +578,44 @@ DOMWorkerErrorReporter(JSContext* aCx,
JSAutoSuspendRequest ar(aCx);
scriptError = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
if (NS_FAILED(rv))
return;
}
const PRUnichar* message =
reinterpret_cast<const PRUnichar*>(aReport->ucmessage);
nsAutoString filename;
filename.AssignWithConversion(aReport->filename);
const PRUnichar* line =
reinterpret_cast<const PRUnichar*>(aReport->uclinebuf);
PRUint32 column = aReport->uctokenptr - aReport->uclinebuf;
rv = scriptError->Init(message, filename.get(), line, aReport->lineno,
column, aReport->flags, "DOM Worker javascript");
if (NS_FAILED(rv))
if (NS_FAILED(rv)) {
return;
}
nsAutoString message, filename, line;
PRUint32 lineNumber, columnNumber, flags, errorNumber;
if (aReport) {
if (aReport->ucmessage) {
message.Assign(reinterpret_cast<const PRUnichar*>(aReport->ucmessage));
}
filename.AssignWithConversion(aReport->filename);
line.Assign(reinterpret_cast<const PRUnichar*>(aReport->uclinebuf));
lineNumber = aReport->lineno;
columnNumber = aReport->uctokenptr - aReport->uclinebuf;
flags = aReport->flags;
errorNumber = aReport->errorNumber;
}
else {
lineNumber = columnNumber = errorNumber = 0;
flags = nsIScriptError::errorFlag | nsIScriptError::exceptionFlag;
}
if (message.IsEmpty()) {
message.AssignWithConversion(aMessage);
}
rv = scriptError->Init(message.get(), filename.get(), line.get(), lineNumber,
columnNumber, flags, "DOM Worker javascript");
if (NS_FAILED(rv)) {
return;
}
// Don't call the error handler if we're out of stack space.
if (aReport->errorNumber != JSMSG_SCRIPT_STACK_QUOTA &&
aReport->errorNumber != JSMSG_OVER_RECURSED) {
if (errorNumber != JSMSG_SCRIPT_STACK_QUOTA &&
errorNumber != JSMSG_OVER_RECURSED) {
// Try the onerror handler for the worker's scope.
nsRefPtr<nsDOMWorkerScope> scope = worker->GetInnerScope();
NS_ASSERTION(scope, "Null scope!");
@ -609,9 +624,9 @@ DOMWorkerErrorReporter(JSContext* aCx,
if (hasListeners) {
nsRefPtr<nsDOMWorkerErrorEvent> event(new nsDOMWorkerErrorEvent());
if (event) {
rv = event->InitErrorEvent(NS_LITERAL_STRING("error"), PR_FALSE, PR_TRUE,
nsDependentString(message), filename,
aReport->lineno);
rv = event->InitErrorEvent(NS_LITERAL_STRING("error"), PR_FALSE,
PR_TRUE, nsDependentString(message),
filename, lineNumber);
if (NS_SUCCEEDED(rv)) {
event->SetTarget(scope);
@ -645,8 +660,9 @@ DOMWorkerErrorReporter(JSContext* aCx,
// top-level worker and we send the message to the main thread.
rv = parent ? nsDOMThreadService::get()->Dispatch(parent, runnable)
: NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL);
if (NS_FAILED(rv))
if (NS_FAILED(rv)) {
return;
}
}
/*******************************************************************************

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

@ -105,6 +105,8 @@ _TEST_FILES = \
testXHR.txt \
test_fibonacci.html \
fibonacci_worker.js \
test_newError.html \
newError_worker.js \
$(NULL)
_SUBDIR_TEST_FILES = \

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

@ -0,0 +1 @@
throw new Error("foo!");

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

@ -0,0 +1,30 @@
<html>
<head>
<title>Test for DOM Worker Threads</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var worker = new Worker("newError_worker.js");
worker.onmessage = function(event) {
ok(false, "Shouldn't get a message!");
SimpleTest.finish();
}
worker.onerror = function(event) {
is(event.message, "foo!", "Got wrong error message!");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>