diff --git a/dom/workers/MessagePort.cpp b/dom/workers/MessagePort.cpp index 1079383c54d..d01b1da8344 100644 --- a/dom/workers/MessagePort.cpp +++ b/dom/workers/MessagePort.cpp @@ -7,6 +7,7 @@ #include "mozilla/EventDispatcher.h" #include "mozilla/dom/MessagePortBinding.h" +#include "mozilla/dom/ScriptSettings.h" #include "nsIDOMEvent.h" #include "SharedWorker.h" @@ -17,6 +18,7 @@ using mozilla::dom::EventHandlerNonNull; using mozilla::dom::MessagePortBase; using mozilla::dom::Optional; using mozilla::dom::Sequence; +using mozilla::dom::AutoNoJSAPI; using namespace mozilla; USING_WORKERS_NAMESPACE @@ -42,6 +44,28 @@ public: mEvents.SwapElements(aEvents); } + bool PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) + { + if (mBehavior == WorkerThreadModifyBusyCount) { + return aWorkerPrivate->ModifyBusyCount(aCx, true); + } + + return true; + } + + void PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate, + bool aDispatchResult) + { + if (!aDispatchResult) { + if (mBehavior == WorkerThreadModifyBusyCount) { + aWorkerPrivate->ModifyBusyCount(aCx, false); + } + if (aCx) { + JS_ReportPendingException(aCx); + } + } + } + bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate); }; @@ -281,6 +305,8 @@ DelayedEventRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) mMessagePort->AssertCorrectThread(); MOZ_ASSERT(mEvents.Length()); + AutoNoJSAPI nojsapi; + bool ignored; for (uint32_t i = 0; i < mEvents.Length(); i++) { mMessagePort->DispatchEvent(mEvents[i], &ignored); diff --git a/dom/workers/test/bug998474_worker.js b/dom/workers/test/bug998474_worker.js new file mode 100644 index 00000000000..a14ed281052 --- /dev/null +++ b/dom/workers/test/bug998474_worker.js @@ -0,0 +1,6 @@ +self.addEventListener("connect", function(e) { + var port = e.ports[0]; + port.onmessage = function(e) { + port.postMessage(eval(e.data)); + }; +}); diff --git a/dom/workers/test/mochitest.ini b/dom/workers/test/mochitest.ini index 4c58b7546e3..b5fd7e7b656 100644 --- a/dom/workers/test/mochitest.ini +++ b/dom/workers/test/mochitest.ini @@ -7,6 +7,7 @@ support-files = bug1014466_worker.js bug1020226_worker.js bug1020226_frame.html + bug998474_worker.js clearTimeouts_worker.js closeOnGC_server.sjs closeOnGC_worker.js @@ -85,6 +86,7 @@ support-files = [test_bug1010784.html] [test_bug1014466.html] [test_bug1020226.html] +[test_bug998474.html] [test_chromeWorker.html] [test_clearTimeouts.html] [test_close.html] diff --git a/dom/workers/test/test_bug998474.html b/dom/workers/test/test_bug998474.html new file mode 100644 index 00000000000..39e5aca0df3 --- /dev/null +++ b/dom/workers/test/test_bug998474.html @@ -0,0 +1,39 @@ + + + + + Test for bug 998474 + + + + +

+ +

+
+
+
+