diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -15,16 +15,17 @@ #include "mozilla/dom/DOMJSClass.h" #include "mozilla/dom/DOMJSProxyHandler.h" #include "mozilla/dom/Exceptions.h" #include "mozilla/dom/NonRefcountedDOMObject.h" #include "mozilla/dom/Nullable.h" #include "mozilla/dom/RootedDictionary.h" #include "mozilla/dom/workers/Workers.h" #include "mozilla/ErrorResult.h" +#include "mozilla/HoldDropJSObjects.h" #include "mozilla/Likely.h" #include "mozilla/Util.h" #include "nsCycleCollector.h" #include "nsIXPConnect.h" #include "MainThreadUtils.h" #include "nsTraceRefcnt.h" #include "qsObjectHelper.h" #include "xpcpublic.h" @@ -2318,15 +2319,17 @@ CreateGlobal(JSContext* aCx, T* aObject, JS::Handle proto = ProtoGetter(aCx, global); NS_ENSURE_TRUE(proto, nullptr); if (!JS_SetPrototype(aCx, global, proto)) { NS_WARNING("Failed to set proto"); return nullptr; } + mozilla::HoldJSObjects(aObject); + return global; } } // namespace dom } // namespace mozilla #endif /* mozilla_dom_BindingUtils_h__ */ diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -36,16 +36,18 @@ WorkerGlobalScope::WorkerGlobalScope(Wor { mWorkerPrivate->AssertIsOnWorkerThread(); SetIsDOMBinding(); } WorkerGlobalScope::~WorkerGlobalScope() { + // Matches the HoldJSObjects in CreateGlobal. + mozilla::DropJSObjects(this); } NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerGlobalScope) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(WorkerGlobalScope, nsDOMEventTargetHelper) tmp->mWorkerPrivate->AssertIsOnWorkerThread(); NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END diff --git a/dom/workers/test/mochitest.ini b/dom/workers/test/mochitest.ini --- a/dom/workers/test/mochitest.ini +++ b/dom/workers/test/mochitest.ini @@ -40,16 +40,17 @@ support-files = terminate_worker.js testXHR.txt threadErrors_worker1.js threadErrors_worker2.js threadErrors_worker3.js threadErrors_worker4.js threadTimeouts_worker.js throwingOnerror_worker.js + timeoutTracing_worker.js transferable_worker.js urlApi_worker.js url_worker.js workersDisabled_worker.js xhr2_worker.js xhrAbort_worker.js xhr_implicit_cancel_worker.js xhr_worker.js @@ -91,16 +92,17 @@ support-files = [test_rvals.html] [test_sharedWorker.html] [test_simpleThread.html] [test_suspend.html] [test_terminate.html] [test_threadErrors.html] [test_threadTimeouts.html] [test_throwingOnerror.html] +[test_timeoutTracing.html] [test_transferable.html] [test_url.html] [test_urlApi.html] [test_workersDisabled.html] [test_xhr.html] [test_xhr2.html] [test_xhrAbort.html] [test_xhr_implicit_cancel.html] diff --git a/dom/workers/test/test_timeoutTracing.html b/dom/workers/test/test_timeoutTracing.html new file mode 100644 --- /dev/null +++ b/dom/workers/test/test_timeoutTracing.html @@ -0,0 +1,44 @@ + + + + + + Test for DOM Worker Threads + + + + +
+
+
+ + + diff --git a/dom/workers/test/timeoutTracing_worker.js b/dom/workers/test/timeoutTracing_worker.js new file mode 100644 --- /dev/null +++ b/dom/workers/test/timeoutTracing_worker.js @@ -0,0 +1,12 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +onmessage = function(event) { + throw "No messages should reach me!"; +} + +setInterval(function() { postMessage("Still alive!"); }, 100); + +postMessage("Begin!");