зеркало из https://github.com/mozilla/pjs.git
Bug 471285 - 'Workers: Spec for runtime error behavior has changed'. r+sr=jst, a=blocking1.9+
This commit is contained in:
Родитель
dd933bada4
Коммит
c63930de05
|
@ -67,6 +67,22 @@ interface nsIWorkerMessageEvent : nsIDOMEvent
|
|||
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)]
|
||||
interface nsIWorkerNavigator : nsISupports
|
||||
{
|
||||
|
@ -76,11 +92,13 @@ interface nsIWorkerNavigator : nsISupports
|
|||
readonly attribute DOMString userAgent;
|
||||
};
|
||||
|
||||
[scriptable, uuid(a41ac154-ba18-4926-8954-cd6973ea490e)]
|
||||
[scriptable, uuid(d7d7cf59-6c8a-4598-8753-630953ae7409)]
|
||||
interface nsIWorkerGlobalScope : nsISupports
|
||||
{
|
||||
readonly attribute nsIWorkerGlobalScope self;
|
||||
readonly attribute nsIWorkerNavigator navigator;
|
||||
|
||||
attribute nsIDOMEventListener onerror;
|
||||
};
|
||||
|
||||
[scriptable, uuid(d30a2f61-86e2-434e-837f-4f1985efa865)]
|
||||
|
|
|
@ -160,7 +160,8 @@ class nsReportErrorRunnable : public nsIRunnable
|
|||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsReportErrorRunnable(nsDOMWorker* aWorker, nsIScriptError* aScriptError)
|
||||
nsReportErrorRunnable(nsDOMWorker* aWorker,
|
||||
nsIScriptError* aScriptError)
|
||||
: mWorker(aWorker), mWorkerWN(aWorker->GetWrappedNative()),
|
||||
mScriptError(aScriptError) {
|
||||
NS_ASSERTION(aScriptError, "Null pointer!");
|
||||
|
@ -191,34 +192,37 @@ public:
|
|||
|
||||
NS_NAMED_LITERAL_STRING(errorStr, "error");
|
||||
|
||||
PRBool hasListener = PR_FALSE, stopPropagation = PR_FALSE;
|
||||
nsresult rv = NS_OK;
|
||||
nsresult rv;
|
||||
|
||||
if (mWorker->mOuterHandler->HasListeners(errorStr)) {
|
||||
hasListener = PR_TRUE;
|
||||
nsRefPtr<nsDOMWorkerMessageEvent> event(new nsDOMWorkerMessageEvent());
|
||||
if (event) {
|
||||
nsCString errorMessage;
|
||||
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);
|
||||
// Construct the error event.
|
||||
nsString message;
|
||||
rv = mScriptError->GetErrorMessage(message);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (stopPropagation) {
|
||||
return NS_OK;
|
||||
nsString filename;
|
||||
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();
|
||||
|
@ -504,6 +508,31 @@ DOMWorkerErrorReporter(JSContext* aCx,
|
|||
column, aReport->flags, "DOM Worker javascript");
|
||||
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 =
|
||||
new nsReportErrorRunnable(worker, scriptError);
|
||||
NS_ENSURE_TRUE(runnable,);
|
||||
|
|
|
@ -522,29 +522,12 @@ GetStringForArgument(nsAString& aString,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
class nsDOMWorkerScope : public nsIWorkerScope,
|
||||
public nsIDOMEventTarget,
|
||||
public nsIXPCScriptable,
|
||||
public nsIClassInfo
|
||||
nsDOMWorkerScope::nsDOMWorkerScope(nsDOMWorker* aWorker)
|
||||
: mWorker(aWorker),
|
||||
mHasOnerror(PR_FALSE)
|
||||
{
|
||||
public:
|
||||
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_ASSERTION(aWorker, "Null pointer!");
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS5(nsDOMWorkerScope, nsIWorkerScope,
|
||||
nsIWorkerGlobalScope,
|
||||
|
@ -617,6 +600,56 @@ nsDOMWorkerScope::GetNavigator(nsIWorkerNavigator** _retval)
|
|||
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
|
||||
nsDOMWorkerScope::PostMessage(/* JSObject aMessage */)
|
||||
{
|
||||
|
|
|
@ -54,9 +54,11 @@
|
|||
|
||||
#include "nsDOMWorkerMessageHandler.h"
|
||||
|
||||
class nsDOMWorker;
|
||||
class nsDOMWorkerFeature;
|
||||
class nsDOMWorkerMessageHandler;
|
||||
class nsDOMWorkerNavigator;
|
||||
class nsDOMWorkerPool;
|
||||
class nsDOMWorkerScope;
|
||||
class nsDOMWorkerTimeout;
|
||||
class nsICancelable;
|
||||
class nsIDOMEventListener;
|
||||
|
@ -64,7 +66,28 @@ class nsIEventTarget;
|
|||
class nsIScriptGlobalObject;
|
||||
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,
|
||||
public nsIJSNativeInitializer,
|
||||
|
|
|
@ -56,6 +56,7 @@ nsDOMWorkerPrivateEvent::nsDOMWorkerPrivateEvent(nsIDOMEvent* aEvent)
|
|||
: mEvent(aEvent),
|
||||
mProgressEvent(do_QueryInterface(aEvent)),
|
||||
mMessageEvent(do_QueryInterface(aEvent)),
|
||||
mErrorEvent(do_QueryInterface(aEvent)),
|
||||
mPreventDefaultCalled(PR_FALSE)
|
||||
{
|
||||
NS_ASSERTION(aEvent, "Null pointer!");
|
||||
|
@ -70,6 +71,7 @@ NS_INTERFACE_MAP_BEGIN(nsDOMWorkerPrivateEvent)
|
|||
NS_INTERFACE_MAP_ENTRY(nsIDOMWorkerPrivateEvent)
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMProgressEvent, mProgressEvent)
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIWorkerMessageEvent, mMessageEvent)
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIWorkerErrorEvent, mErrorEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
@ -91,7 +93,13 @@ nsDOMWorkerPrivateEvent::GetInterfaces(PRUint32* aCount, nsIID*** aArray)
|
|||
NS_IMETHODIMP
|
||||
nsDOMWorkerPrivateEvent::PreventDefault()
|
||||
{
|
||||
mPreventDefaultCalled = PR_TRUE;
|
||||
PRBool cancelable = PR_FALSE;
|
||||
mEvent->GetCancelable(&cancelable);
|
||||
|
||||
if (cancelable) {
|
||||
mPreventDefaultCalled = PR_TRUE;
|
||||
}
|
||||
|
||||
return mEvent->PreventDefault();
|
||||
}
|
||||
|
||||
|
@ -136,6 +144,21 @@ nsDOMWorkerPrivateEvent::InitMessageEvent(const nsAString& aTypeArg,
|
|||
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
|
||||
nsDOMWorkerPrivateEvent::PreventDefaultCalled()
|
||||
{
|
||||
|
@ -539,3 +562,47 @@ nsDOMWorkerXHREvent::Run()
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -108,9 +108,18 @@ public:
|
|||
NS_IMETHOD GetSource(nsISupports** 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,
|
||||
public nsIDOMProgressEvent,
|
||||
public nsIWorkerMessageEvent,
|
||||
public nsIWorkerErrorEvent,
|
||||
public nsIClassInfo
|
||||
{
|
||||
public:
|
||||
|
@ -118,6 +127,7 @@ public:
|
|||
NS_FORWARD_NSIDOMEVENT_SPECIAL
|
||||
NS_FORWARD_NSIWORKERMESSAGEEVENT_SPECIAL
|
||||
NS_FORWARD_NSIDOMPROGRESSEVENT_SPECIAL
|
||||
NS_FORWARD_NSIWORKERERROREVENT_SPECIAL
|
||||
NS_DECL_NSICLASSINFO
|
||||
|
||||
nsDOMWorkerPrivateEvent(nsIDOMEvent* aEvent);
|
||||
|
@ -142,12 +152,20 @@ public:
|
|||
const nsAString& aOriginArg,
|
||||
nsISupports* aSourceArg);
|
||||
|
||||
NS_IMETHOD InitErrorEvent(const nsAString& aTypeArg,
|
||||
PRBool aCanBubbleArg,
|
||||
PRBool aCancelableArg,
|
||||
const nsAString& aMessageArg,
|
||||
const nsAString& aFilenameArg,
|
||||
PRUint32 aLinenoArg);
|
||||
|
||||
virtual PRBool PreventDefaultCalled();
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIDOMEvent> mEvent;
|
||||
nsCOMPtr<nsIDOMProgressEvent> mProgressEvent;
|
||||
nsCOMPtr<nsIWorkerMessageEvent> mMessageEvent;
|
||||
nsCOMPtr<nsIWorkerErrorEvent> mErrorEvent;
|
||||
PRBool mPreventDefaultCalled;
|
||||
};
|
||||
|
||||
|
@ -167,6 +185,10 @@ public:
|
|||
mTarget = aTarget;
|
||||
}
|
||||
|
||||
PRBool PreventDefaultCalled() {
|
||||
return PRBool(mPreventDefaultCalled);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~nsDOMWorkerEvent() { }
|
||||
|
||||
|
@ -300,4 +322,22 @@ protected:
|
|||
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__ */
|
||||
|
|
|
@ -70,6 +70,8 @@ _TEST_FILES = \
|
|||
relativeLoad_worker.js \
|
||||
relativeLoad_worker2.js \
|
||||
relativeLoad_import.js \
|
||||
test_scopeOnerror.html \
|
||||
scopeOnerror_worker.js \
|
||||
test_simpleThread.html \
|
||||
simpleThread_worker.js \
|
||||
test_terminate.html \
|
||||
|
|
|
@ -10,11 +10,11 @@ worker.onerror = function(event) {
|
|||
case 2:
|
||||
// Stop and rethrow.
|
||||
event.preventDefault();
|
||||
throw event.data;
|
||||
throw event.message;
|
||||
break;
|
||||
case 3:
|
||||
event.preventDefault();
|
||||
postMessage(event.data);
|
||||
postMessage(event.message);
|
||||
worker.onerror = null;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -3,5 +3,4 @@ var myConstructor = {}.constructor;
|
|||
|
||||
// Try to call a function defined in the imported script.
|
||||
function importedScriptFunction() {
|
||||
dump("running importedScriptFunction\n");
|
||||
}
|
||||
|
|
|
@ -3,5 +3,4 @@ var myConstructor2 = {}.constructor;
|
|||
|
||||
// Try to call a function defined in the imported script.
|
||||
function importedScriptFunction2() {
|
||||
dump("running importedScriptFunction2\n");
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ onmessage = function(event) {
|
|||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "testXHR.txt", false);
|
||||
xhr.send(null);
|
||||
dump("XXXben: " + xhr.responseText + "\n");
|
||||
if (xhr.status != 200 ||
|
||||
xhr.responseText != "A noisy noise annoys an oyster.") {
|
||||
throw "Couldn't get xhr text from where we wanted it!";
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
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();
|
||||
setTimeout("postMessage('Done');", 10);
|
||||
}
|
||||
}
|
||||
|
||||
onmessage = function(event) {
|
||||
if (onerror === undefined || typeof(onerror) == "undefined") {
|
||||
throw "onerror has a bad type!";
|
||||
}
|
||||
throw event.data;
|
||||
}
|
|
@ -35,8 +35,7 @@ Tests of DOM Worker Threads
|
|||
|
||||
worker.onmessage = function(event) {
|
||||
is(event.target, worker);
|
||||
ok(event.data.indexOf(errors[errorIndex]) != -1,
|
||||
"Wrong message!");
|
||||
isnot(-1, event.data.indexOf(errors[errorIndex]));
|
||||
ok(errorIndex == errors.length - 1, "Wrong number of errors seen!");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
@ -49,8 +48,7 @@ Tests of DOM Worker Threads
|
|||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
is(event.target, worker);
|
||||
ok(event.data.indexOf(errors[errorIndex]) != -1,
|
||||
"Wrong message!");
|
||||
isnot(-1, event.message.indexOf(errors[errorIndex]));
|
||||
|
||||
switch (errorIndex) {
|
||||
case 1:
|
||||
|
@ -79,7 +77,9 @@ Tests of DOM Worker Threads
|
|||
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;
|
||||
nextError();
|
||||
},
|
||||
|
|
|
@ -20,9 +20,7 @@ Tests of DOM Worker Threads
|
|||
var worker = new Worker("recursion_worker.js");
|
||||
|
||||
worker.onerror = function(event) {
|
||||
is(event.data,
|
||||
'[JavaScript Error: "too much recursion" {file: "http://localhost:8888' +
|
||||
'/tests/dom/src/threads/test/recursion_worker.js" line: 2}]');
|
||||
is(event.message, "too much recursion");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<!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">
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
|
||||
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");
|
||||
|
||||
if (consoleListener) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
consoleService.unregisterListener(consoleListener);
|
||||
consoleService.reset();
|
||||
consoleListener = null;
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
worker.onerror = function(event) {
|
||||
is(event.target, worker);
|
||||
is(event.message,
|
||||
"uncaught exception: This exception should make it to onerror");
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
var consoleListener = {
|
||||
observe: function(message) {
|
||||
ok(false, "An error made it to the console: " + message);
|
||||
|
||||
if (consoleListener) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
consoleService.unregisterListener(consoleListener);
|
||||
consoleService.reset();
|
||||
consoleListener = null;
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
if (iid.equals(Ci.nsIConsoleListener) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_NOINTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
var consoleService =
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
|
||||
|
||||
consoleService.reset();
|
||||
consoleService.registerListener(consoleListener);
|
||||
|
||||
for (var index in errors) {
|
||||
worker.postMessage(errors[index]);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -43,19 +43,15 @@ Tests of DOM Worker Threads (Bug 437152)
|
|||
var gotErrors = false;
|
||||
worker.onerror = function(event) {
|
||||
is(event.target, worker);
|
||||
is(event.data,
|
||||
'[JavaScript Error: "uncaught exception: Bad message: asdf"]');
|
||||
is(event.message, "uncaught exception: Bad message: asdf");
|
||||
|
||||
worker.onerror = function(otherEvent) {
|
||||
is(otherEvent.target, worker);
|
||||
is(otherEvent.data,
|
||||
'[JavaScript Error: "Components is not defined" {file: ' +
|
||||
'"http://localhost:8888/tests/dom/src/threads/test/' +
|
||||
'simpleThread_worker.js" line: 6}]');
|
||||
is(otherEvent.message, "Components is not defined");
|
||||
gotErrors = true;
|
||||
|
||||
worker.onerror = function(oneMoreEvent) {
|
||||
ok(false, "Worker had an error:" + oneMoreEvent.data);
|
||||
ok(false, "Worker had an error:" + oneMoreEvent.message);
|
||||
SimpleTest.finish();
|
||||
};
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче