Bug 471285 - 'Workers: Spec for runtime error behavior has changed'. r+sr=jst, a=blocking1.9+

This commit is contained in:
Ben Turner 2008-12-30 16:25:05 -06:00
parent c01314e672
commit 18f2466ba1
16 changed files with 345 additions and 72 deletions

View File

@ -67,6 +67,22 @@ interface nsIWorkerMessageEvent : nsIDOMEvent
in nsISupports aSourceArg); in nsISupports aSourceArg);
}; };
[scriptable, uuid(73d82c1d-05de-49c9-a23b-7121ff09a67a)]
interface nsIWorkerErrorEvent : nsIDOMEvent
{
readonly attribute DOMString message;
readonly attribute DOMString filename;
readonly attribute unsigned long lineno;
void initErrorEvent(in DOMString aTypeArg,
in boolean aCanBubbleArg,
in boolean aCancelableArg,
in DOMString aMessageArg,
in DOMString aFilenameArg,
in unsigned long aLinenoArg);
};
[scriptable, uuid(74fb665a-e477-4ce2-b3c6-c58b1b28b6c3)] [scriptable, uuid(74fb665a-e477-4ce2-b3c6-c58b1b28b6c3)]
interface nsIWorkerNavigator : nsISupports interface nsIWorkerNavigator : nsISupports
{ {
@ -76,11 +92,13 @@ interface nsIWorkerNavigator : nsISupports
readonly attribute DOMString userAgent; readonly attribute DOMString userAgent;
}; };
[scriptable, uuid(a41ac154-ba18-4926-8954-cd6973ea490e)] [scriptable, uuid(d7d7cf59-6c8a-4598-8753-630953ae7409)]
interface nsIWorkerGlobalScope : nsISupports interface nsIWorkerGlobalScope : nsISupports
{ {
readonly attribute nsIWorkerGlobalScope self; readonly attribute nsIWorkerGlobalScope self;
readonly attribute nsIWorkerNavigator navigator; readonly attribute nsIWorkerNavigator navigator;
attribute nsIDOMEventListener onerror;
}; };
[scriptable, uuid(d30a2f61-86e2-434e-837f-4f1985efa865)] [scriptable, uuid(d30a2f61-86e2-434e-837f-4f1985efa865)]

View File

@ -160,7 +160,8 @@ class nsReportErrorRunnable : public nsIRunnable
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
nsReportErrorRunnable(nsDOMWorker* aWorker, nsIScriptError* aScriptError) nsReportErrorRunnable(nsDOMWorker* aWorker,
nsIScriptError* aScriptError)
: mWorker(aWorker), mWorkerWN(aWorker->GetWrappedNative()), : mWorker(aWorker), mWorkerWN(aWorker->GetWrappedNative()),
mScriptError(aScriptError) { mScriptError(aScriptError) {
NS_ASSERTION(aScriptError, "Null pointer!"); NS_ASSERTION(aScriptError, "Null pointer!");
@ -191,34 +192,37 @@ public:
NS_NAMED_LITERAL_STRING(errorStr, "error"); NS_NAMED_LITERAL_STRING(errorStr, "error");
PRBool hasListener = PR_FALSE, stopPropagation = PR_FALSE; nsresult rv;
nsresult rv = NS_OK;
if (mWorker->mOuterHandler->HasListeners(errorStr)) { if (mWorker->mOuterHandler->HasListeners(errorStr)) {
hasListener = PR_TRUE; // Construct the error event.
nsRefPtr<nsDOMWorkerMessageEvent> event(new nsDOMWorkerMessageEvent()); nsString message;
if (event) { rv = mScriptError->GetErrorMessage(message);
nsCString errorMessage; NS_ENSURE_SUCCESS(rv, rv);
rv = mScriptError->ToString(errorMessage);
if (NS_SUCCEEDED(rv)) {
rv = event->InitMessageEvent(errorStr, PR_FALSE, PR_FALSE,
NS_ConvertUTF8toUTF16(errorMessage),
EmptyString(), nsnull);
if (NS_SUCCEEDED(rv)) {
event->SetTarget(mWorker);
rv = mWorker->DispatchEvent(static_cast<nsDOMWorkerEvent*>(event),
&stopPropagation);
if (NS_FAILED(rv)) {
stopPropagation = PR_FALSE;
}
}
}
}
}
NS_ENSURE_SUCCESS(rv, rv);
if (stopPropagation) { nsString filename;
return NS_OK; rv = mScriptError->GetSourceName(filename);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 lineno;
rv = mScriptError->GetLineNumber(&lineno);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsDOMWorkerErrorEvent> event(new nsDOMWorkerErrorEvent());
NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
rv = event->InitErrorEvent(errorStr, PR_FALSE, PR_TRUE, message,
filename, lineno);
NS_ENSURE_SUCCESS(rv, rv);
event->SetTarget(mWorker);
PRBool stopPropagation = PR_FALSE;
rv = mWorker->DispatchEvent(static_cast<nsDOMWorkerEvent*>(event),
&stopPropagation);
if (NS_SUCCEEDED(rv) && stopPropagation) {
return NS_OK;
}
} }
nsRefPtr<nsDOMWorker> parent = mWorker->GetParent(); nsRefPtr<nsDOMWorker> parent = mWorker->GetParent();
@ -504,6 +508,31 @@ DOMWorkerErrorReporter(JSContext* aCx,
column, aReport->flags, "DOM Worker javascript"); column, aReport->flags, "DOM Worker javascript");
NS_ENSURE_SUCCESS(rv,); NS_ENSURE_SUCCESS(rv,);
// Try the onerror handler for the worker's scope.
nsCOMPtr<nsIDOMEventListener> handler =
worker->mInnerHandler->GetOnXListener(NS_LITERAL_STRING("error"));
if (handler) {
nsRefPtr<nsDOMWorkerErrorEvent> event(new nsDOMWorkerErrorEvent());
NS_ENSURE_TRUE(event,);
rv = event->InitErrorEvent(NS_LITERAL_STRING("error"), PR_FALSE, PR_TRUE,
nsDependentString(message), filename,
aReport->lineno);
NS_ENSURE_SUCCESS(rv,);
NS_ASSERTION(worker->GetInnerScope(), "Null scope!");
event->SetTarget(worker->GetInnerScope());
rv = handler->HandleEvent(static_cast<nsDOMWorkerEvent*>(event));
NS_ENSURE_SUCCESS(rv,);
if (event->PreventDefaultCalled()) {
return;
}
}
// Still unhandled, fire at the onerror handler on the worker.
nsCOMPtr<nsIRunnable> runnable = nsCOMPtr<nsIRunnable> runnable =
new nsReportErrorRunnable(worker, scriptError); new nsReportErrorRunnable(worker, scriptError);
NS_ENSURE_TRUE(runnable,); NS_ENSURE_TRUE(runnable,);

View File

@ -522,29 +522,12 @@ GetStringForArgument(nsAString& aString,
return NS_OK; return NS_OK;
} }
class nsDOMWorkerScope : public nsIWorkerScope, nsDOMWorkerScope::nsDOMWorkerScope(nsDOMWorker* aWorker)
public nsIDOMEventTarget, : mWorker(aWorker),
public nsIXPCScriptable, mHasOnerror(PR_FALSE)
public nsIClassInfo
{ {
public: NS_ASSERTION(aWorker, "Null pointer!");
NS_DECL_ISUPPORTS }
NS_DECL_NSIWORKERGLOBALSCOPE
NS_DECL_NSIWORKERSCOPE
NS_DECL_NSIDOMEVENTTARGET
NS_DECL_NSIXPCSCRIPTABLE
NS_DECL_NSICLASSINFO
nsDOMWorkerScope(nsDOMWorker* aWorker)
: mWorker(aWorker) {
NS_ASSERTION(aWorker, "Null pointer!");
}
private:
nsDOMWorker* mWorker;
nsRefPtr<nsDOMWorkerNavigator> mNavigator;
};
NS_IMPL_THREADSAFE_ISUPPORTS5(nsDOMWorkerScope, nsIWorkerScope, NS_IMPL_THREADSAFE_ISUPPORTS5(nsDOMWorkerScope, nsIWorkerScope,
nsIWorkerGlobalScope, nsIWorkerGlobalScope,
@ -617,6 +600,56 @@ nsDOMWorkerScope::GetNavigator(nsIWorkerNavigator** _retval)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsDOMWorkerScope::GetOnerror(nsIDOMEventListener** aOnerror)
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
NS_ENSURE_ARG_POINTER(aOnerror);
if (mWorker->IsCanceled()) {
return NS_ERROR_ABORT;
}
if (!mHasOnerror) {
// Spec says we have to return 'undefined' until something is set here.
nsIXPConnect* xpc = nsContentUtils::XPConnect();
NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED);
nsAXPCNativeCallContext* cc;
nsresult rv = xpc->GetCurrentNativeCallContext(&cc);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED);
jsval* retval;
rv = cc->GetRetValPtr(&retval);
NS_ENSURE_SUCCESS(rv, rv);
*retval = JSVAL_VOID;
return cc->SetReturnValueWasSet(PR_TRUE);
}
nsCOMPtr<nsIDOMEventListener> listener =
mWorker->mInnerHandler->GetOnXListener(NS_LITERAL_STRING("error"));
listener.forget(aOnerror);
return NS_OK;
}
NS_IMETHODIMP
nsDOMWorkerScope::SetOnerror(nsIDOMEventListener* aOnerror)
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
if (mWorker->IsCanceled()) {
return NS_ERROR_ABORT;
}
mHasOnerror = PR_TRUE;
return mWorker->mInnerHandler->SetOnXListener(NS_LITERAL_STRING("error"),
aOnerror);
}
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWorkerScope::PostMessage(/* JSObject aMessage */) nsDOMWorkerScope::PostMessage(/* JSObject aMessage */)
{ {

View File

@ -54,9 +54,11 @@
#include "nsDOMWorkerMessageHandler.h" #include "nsDOMWorkerMessageHandler.h"
class nsDOMWorker;
class nsDOMWorkerFeature;
class nsDOMWorkerMessageHandler; class nsDOMWorkerMessageHandler;
class nsDOMWorkerNavigator;
class nsDOMWorkerPool; class nsDOMWorkerPool;
class nsDOMWorkerScope;
class nsDOMWorkerTimeout; class nsDOMWorkerTimeout;
class nsICancelable; class nsICancelable;
class nsIDOMEventListener; class nsIDOMEventListener;
@ -64,7 +66,28 @@ class nsIEventTarget;
class nsIScriptGlobalObject; class nsIScriptGlobalObject;
class nsIXPConnectWrappedNative; class nsIXPConnectWrappedNative;
class nsDOMWorkerFeature; class nsDOMWorkerScope : public nsIWorkerScope,
public nsIDOMEventTarget,
public nsIXPCScriptable,
public nsIClassInfo
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWORKERGLOBALSCOPE
NS_DECL_NSIWORKERSCOPE
NS_DECL_NSIDOMEVENTTARGET
NS_DECL_NSIXPCSCRIPTABLE
NS_DECL_NSICLASSINFO
nsDOMWorkerScope(nsDOMWorker* aWorker);
private:
nsDOMWorker* mWorker;
nsRefPtr<nsDOMWorkerNavigator> mNavigator;
PRPackedBool mHasOnerror;
};
class nsDOMWorker : public nsIWorker, class nsDOMWorker : public nsIWorker,
public nsIJSNativeInitializer, public nsIJSNativeInitializer,

View File

@ -56,6 +56,7 @@ nsDOMWorkerPrivateEvent::nsDOMWorkerPrivateEvent(nsIDOMEvent* aEvent)
: mEvent(aEvent), : mEvent(aEvent),
mProgressEvent(do_QueryInterface(aEvent)), mProgressEvent(do_QueryInterface(aEvent)),
mMessageEvent(do_QueryInterface(aEvent)), mMessageEvent(do_QueryInterface(aEvent)),
mErrorEvent(do_QueryInterface(aEvent)),
mPreventDefaultCalled(PR_FALSE) mPreventDefaultCalled(PR_FALSE)
{ {
NS_ASSERTION(aEvent, "Null pointer!"); NS_ASSERTION(aEvent, "Null pointer!");
@ -70,6 +71,7 @@ NS_INTERFACE_MAP_BEGIN(nsDOMWorkerPrivateEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOMWorkerPrivateEvent) NS_INTERFACE_MAP_ENTRY(nsIDOMWorkerPrivateEvent)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMProgressEvent, mProgressEvent) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMProgressEvent, mProgressEvent)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIWorkerMessageEvent, mMessageEvent) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIWorkerMessageEvent, mMessageEvent)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIWorkerErrorEvent, mErrorEvent)
NS_INTERFACE_MAP_ENTRY(nsIClassInfo) NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
@ -91,7 +93,13 @@ nsDOMWorkerPrivateEvent::GetInterfaces(PRUint32* aCount, nsIID*** aArray)
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWorkerPrivateEvent::PreventDefault() nsDOMWorkerPrivateEvent::PreventDefault()
{ {
mPreventDefaultCalled = PR_TRUE; PRBool cancelable = PR_FALSE;
mEvent->GetCancelable(&cancelable);
if (cancelable) {
mPreventDefaultCalled = PR_TRUE;
}
return mEvent->PreventDefault(); return mEvent->PreventDefault();
} }
@ -136,6 +144,21 @@ nsDOMWorkerPrivateEvent::InitMessageEvent(const nsAString& aTypeArg,
aSourceArg); aSourceArg);
} }
NS_IMETHODIMP
nsDOMWorkerPrivateEvent::InitErrorEvent(const nsAString& aTypeArg,
PRBool aCanBubbleArg,
PRBool aCancelableArg,
const nsAString& aMessageArg,
const nsAString& aFilenameArg,
PRUint32 aLinenoArg)
{
NS_ASSERTION(mErrorEvent, "Impossible!");
mPreventDefaultCalled = PR_FALSE;
return mErrorEvent->InitErrorEvent(aTypeArg, aCanBubbleArg, aCancelableArg,
aMessageArg, aFilenameArg, aLinenoArg);
}
PRBool PRBool
nsDOMWorkerPrivateEvent::PreventDefaultCalled() nsDOMWorkerPrivateEvent::PreventDefaultCalled()
{ {
@ -539,3 +562,47 @@ nsDOMWorkerXHREvent::Run()
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return NS_OK; return NS_OK;
} }
NS_IMPL_ISUPPORTS_INHERITED1(nsDOMWorkerErrorEvent, nsDOMWorkerEvent,
nsIWorkerErrorEvent)
NS_IMPL_CI_INTERFACE_GETTER2(nsDOMWorkerErrorEvent, nsIDOMEvent,
nsIWorkerErrorEvent)
NS_IMPL_THREADSAFE_DOM_CI_GETINTERFACES(nsDOMWorkerErrorEvent)
nsresult
nsDOMWorkerErrorEvent::GetMessage(nsAString& aMessage)
{
aMessage.Assign(mMessage);
return NS_OK;
}
nsresult
nsDOMWorkerErrorEvent::GetFilename(nsAString& aFilename)
{
aFilename.Assign(mFilename);
return NS_OK;
}
nsresult
nsDOMWorkerErrorEvent::GetLineno(PRUint32* aLineno)
{
NS_ENSURE_ARG_POINTER(aLineno);
*aLineno = mLineno;
return NS_OK;
}
nsresult
nsDOMWorkerErrorEvent::InitErrorEvent(const nsAString& aTypeArg,
PRBool aCanBubbleArg,
PRBool aCancelableArg,
const nsAString& aMessageArg,
const nsAString& aFilenameArg,
PRUint32 aLinenoArg)
{
mMessage.Assign(aMessageArg);
mFilename.Assign(aFilenameArg);
mLineno = aLinenoArg;
return InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
}

View File

@ -108,9 +108,18 @@ public:
NS_IMETHOD GetSource(nsISupports** aSource) \ NS_IMETHOD GetSource(nsISupports** aSource) \
{ return mMessageEvent->GetSource(aSource); } { return mMessageEvent->GetSource(aSource); }
#define NS_FORWARD_NSIWORKERERROREVENT_SPECIAL \
NS_IMETHOD GetMessage(nsAString& aMessage) \
{ return mErrorEvent->GetMessage(aMessage); } \
NS_IMETHOD GetFilename(nsAString& aFilename) \
{ return mErrorEvent->GetFilename(aFilename); } \
NS_IMETHOD GetLineno(PRUint32* aLineno) \
{ return mErrorEvent->GetLineno(aLineno); }
class nsDOMWorkerPrivateEvent : public nsIDOMWorkerPrivateEvent, class nsDOMWorkerPrivateEvent : public nsIDOMWorkerPrivateEvent,
public nsIDOMProgressEvent, public nsIDOMProgressEvent,
public nsIWorkerMessageEvent, public nsIWorkerMessageEvent,
public nsIWorkerErrorEvent,
public nsIClassInfo public nsIClassInfo
{ {
public: public:
@ -118,6 +127,7 @@ public:
NS_FORWARD_NSIDOMEVENT_SPECIAL NS_FORWARD_NSIDOMEVENT_SPECIAL
NS_FORWARD_NSIWORKERMESSAGEEVENT_SPECIAL NS_FORWARD_NSIWORKERMESSAGEEVENT_SPECIAL
NS_FORWARD_NSIDOMPROGRESSEVENT_SPECIAL NS_FORWARD_NSIDOMPROGRESSEVENT_SPECIAL
NS_FORWARD_NSIWORKERERROREVENT_SPECIAL
NS_DECL_NSICLASSINFO NS_DECL_NSICLASSINFO
nsDOMWorkerPrivateEvent(nsIDOMEvent* aEvent); nsDOMWorkerPrivateEvent(nsIDOMEvent* aEvent);
@ -142,12 +152,20 @@ public:
const nsAString& aOriginArg, const nsAString& aOriginArg,
nsISupports* aSourceArg); nsISupports* aSourceArg);
NS_IMETHOD InitErrorEvent(const nsAString& aTypeArg,
PRBool aCanBubbleArg,
PRBool aCancelableArg,
const nsAString& aMessageArg,
const nsAString& aFilenameArg,
PRUint32 aLinenoArg);
virtual PRBool PreventDefaultCalled(); virtual PRBool PreventDefaultCalled();
private: private:
nsCOMPtr<nsIDOMEvent> mEvent; nsCOMPtr<nsIDOMEvent> mEvent;
nsCOMPtr<nsIDOMProgressEvent> mProgressEvent; nsCOMPtr<nsIDOMProgressEvent> mProgressEvent;
nsCOMPtr<nsIWorkerMessageEvent> mMessageEvent; nsCOMPtr<nsIWorkerMessageEvent> mMessageEvent;
nsCOMPtr<nsIWorkerErrorEvent> mErrorEvent;
PRBool mPreventDefaultCalled; PRBool mPreventDefaultCalled;
}; };
@ -167,6 +185,10 @@ public:
mTarget = aTarget; mTarget = aTarget;
} }
PRBool PreventDefaultCalled() {
return PRBool(mPreventDefaultCalled);
}
protected: protected:
virtual ~nsDOMWorkerEvent() { } virtual ~nsDOMWorkerEvent() { }
@ -300,4 +322,22 @@ protected:
PRPackedBool mProgressEvent; PRPackedBool mProgressEvent;
}; };
class nsDOMWorkerErrorEvent : public nsDOMWorkerEvent,
public nsIWorkerErrorEvent
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_NSIDOMEVENT(nsDOMWorkerEvent::)
NS_DECL_NSIWORKERERROREVENT
NS_DECL_NSICLASSINFO_GETINTERFACES
nsDOMWorkerErrorEvent()
: mLineno(0) { }
protected:
nsString mMessage;
nsString mFilename;
PRUint32 mLineno;
};
#endif /* __NSDOMWORKEREVENTS_H__ */ #endif /* __NSDOMWORKEREVENTS_H__ */

View File

@ -70,6 +70,8 @@ _TEST_FILES = \
relativeLoad_worker.js \ relativeLoad_worker.js \
relativeLoad_worker2.js \ relativeLoad_worker2.js \
relativeLoad_import.js \ relativeLoad_import.js \
test_scopeOnerror.html \
scopeOnerror_worker.js \
test_simpleThread.html \ test_simpleThread.html \
simpleThread_worker.js \ simpleThread_worker.js \
test_terminate.html \ test_terminate.html \

View File

@ -10,11 +10,11 @@ worker.onerror = function(event) {
case 2: case 2:
// Stop and rethrow. // Stop and rethrow.
event.preventDefault(); event.preventDefault();
throw event.data; throw event.message;
break; break;
case 3: case 3:
event.preventDefault(); event.preventDefault();
postMessage(event.data); postMessage(event.message);
worker.onerror = null; worker.onerror = null;
break; break;
default: default:

View File

@ -3,5 +3,4 @@ var myConstructor = {}.constructor;
// Try to call a function defined in the imported script. // Try to call a function defined in the imported script.
function importedScriptFunction() { function importedScriptFunction() {
dump("running importedScriptFunction\n");
} }

View File

@ -3,5 +3,4 @@ var myConstructor2 = {}.constructor;
// Try to call a function defined in the imported script. // Try to call a function defined in the imported script.
function importedScriptFunction2() { function importedScriptFunction2() {
dump("running importedScriptFunction2\n");
} }

View File

@ -4,7 +4,6 @@ onmessage = function(event) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("GET", "testXHR.txt", false); xhr.open("GET", "testXHR.txt", false);
xhr.send(null); xhr.send(null);
dump("XXXben: " + xhr.responseText + "\n");
if (xhr.status != 200 || if (xhr.status != 200 ||
xhr.responseText != "A noisy noise annoys an oyster.") { xhr.responseText != "A noisy noise annoys an oyster.") {
throw "Couldn't get xhr text from where we wanted it!"; throw "Couldn't get xhr text from where we wanted it!";

View File

@ -0,0 +1,26 @@
if (onerror !== undefined || typeof(onerror) != "undefined") {
throw "Undefined onerror has bad type!";
}
onerror = function(event) {
if (!event.cancelable) {
throw "Error event is not cancelable!";
}
if (event.target != this) {
throw "Error event is targeted at the wrong object!";
}
if (event.message == "uncaught exception: This error should not make it back out") {
event.preventDefault();
postMessage("Done");
}
}
if (onerror === undefined || typeof(onerror) == "undefined") {
throw "onerror has a bad type!";
}
onmessage = function(event) {
throw event.data;
}

View File

@ -35,8 +35,7 @@ Tests of DOM Worker Threads
worker.onmessage = function(event) { worker.onmessage = function(event) {
is(event.target, worker); is(event.target, worker);
ok(event.data.indexOf(errors[errorIndex]) != -1, isnot(-1, event.data.indexOf(errors[errorIndex]));
"Wrong message!");
ok(errorIndex == errors.length - 1, "Wrong number of errors seen!"); ok(errorIndex == errors.length - 1, "Wrong number of errors seen!");
SimpleTest.finish(); SimpleTest.finish();
} }
@ -49,8 +48,7 @@ Tests of DOM Worker Threads
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
is(event.target, worker); is(event.target, worker);
ok(event.data.indexOf(errors[errorIndex]) != -1, isnot(-1, event.message.indexOf(errors[errorIndex]));
"Wrong message!");
switch (errorIndex) { switch (errorIndex) {
case 1: case 1:
@ -79,7 +77,9 @@ Tests of DOM Worker Threads
return; return;
} }
ok(message.message.indexOf(errors[errorIndex]) != -1, "Wrong message!"); is(message.message,
'[JavaScript Error: "uncaught exception: This exception should show ' +
'up in the JS console"]');
worker.onerror = errorHandler; worker.onerror = errorHandler;
nextError(); nextError();
}, },

View File

@ -20,9 +20,7 @@ Tests of DOM Worker Threads
var worker = new Worker("recursion_worker.js"); var worker = new Worker("recursion_worker.js");
worker.onerror = function(event) { worker.onerror = function(event) {
is(event.data, is(event.message, "too much recursion");
'[JavaScript Error: "too much recursion" {file: "http://localhost:8888' +
'/tests/dom/src/threads/test/recursion_worker.js" line: 2}]');
SimpleTest.finish(); SimpleTest.finish();
} }

View File

@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html>
<!--
Tests of DOM Worker Threads
-->
<head>
<title>Test for DOM Worker Threads</title>
<script type="text/javascript" src="/MochiKit/MochiKit.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 errors = [
"This exception should make it to onerror",
"This error should not make it back out"
];
var worker = new Worker("scopeOnError_worker.js");
worker.onmessage = function(event) {
ok(event.data == "Done");
SimpleTest.finish();
}
worker.onerror = function(event) {
is(event.target, worker);
is(event.message, "uncaught exception: " + errors[0]);
event.preventDefault();
};
for (var index in errors) {
worker.postMessage(errors[index]);
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

View File

@ -43,19 +43,15 @@ Tests of DOM Worker Threads (Bug 437152)
var gotErrors = false; var gotErrors = false;
worker.onerror = function(event) { worker.onerror = function(event) {
is(event.target, worker); is(event.target, worker);
is(event.data, is(event.message, "uncaught exception: Bad message: asdf");
'[JavaScript Error: "uncaught exception: Bad message: asdf"]');
worker.onerror = function(otherEvent) { worker.onerror = function(otherEvent) {
is(otherEvent.target, worker); is(otherEvent.target, worker);
is(otherEvent.data, is(otherEvent.message, "Components is not defined");
'[JavaScript Error: "Components is not defined" {file: ' +
'"http://localhost:8888/tests/dom/src/threads/test/' +
'simpleThread_worker.js" line: 6}]');
gotErrors = true; gotErrors = true;
worker.onerror = function(oneMoreEvent) { worker.onerror = function(oneMoreEvent) {
ok(false, "Worker had an error:" + oneMoreEvent.data); ok(false, "Worker had an error:" + oneMoreEvent.message);
SimpleTest.finish(); SimpleTest.finish();
}; };
}; };