From 492d0e235cb44e4981f6a95acab564e0a5178624 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Tue, 19 Nov 2013 14:05:41 +0800 Subject: [PATCH] Bug 936327. r=bent --- dom/bindings/BindingUtils.h | 3 ++ dom/workers/WorkerPrivate.cpp | 5 +++ dom/workers/WorkerScope.cpp | 2 + dom/workers/test/mochitest.ini | 2 + dom/workers/test/test_timeoutTracing.html | 47 +++++++++++++++++++++++ dom/workers/test/timeoutTracing_worker.js | 13 +++++++ 6 files changed, 72 insertions(+) create mode 100644 dom/workers/test/test_timeoutTracing.html create mode 100644 dom/workers/test/timeoutTracing_worker.js diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index dcbb3f8b5945..e3cff87c0628 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -20,6 +20,7 @@ #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" @@ -2323,6 +2324,8 @@ CreateGlobal(JSContext* aCx, T* aObject, nsWrapperCache* aCache, return nullptr; } + mozilla::HoldJSObjects(aObject); + return global; } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 9a4d2297d6bf..33f945724630 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -4240,6 +4240,11 @@ WorkerPrivate::TraceTimeouts(const TraceCallbacks& aCallbacks, for (uint32_t index = 0; index < mTimeouts.Length(); index++) { TimeoutInfo* info = mTimeouts[index]; + + if (info->mTimeoutCallable.isUndefined()) { + continue; + } + aCallbacks.Trace(&info->mTimeoutCallable, "mTimeoutCallable", aClosure); for (uint32_t index2 = 0; index2 < info->mExtraArgVals.Length(); index2++) { aCallbacks.Trace(&info->mExtraArgVals[index2], "mExtraArgVals[i]", aClosure); diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index ecc5e7459cd1..9a7f9f2d5c2a 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -41,6 +41,8 @@ WorkerGlobalScope::WorkerGlobalScope(WorkerPrivate* aWorkerPrivate) WorkerGlobalScope::~WorkerGlobalScope() { + // Matches the HoldJSObjects in CreateGlobal. + mozilla::DropJSObjects(this); } NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerGlobalScope) diff --git a/dom/workers/test/mochitest.ini b/dom/workers/test/mochitest.ini index ce42a9cb05d8..4c60ab35ba48 100644 --- a/dom/workers/test/mochitest.ini +++ b/dom/workers/test/mochitest.ini @@ -45,6 +45,7 @@ support-files = threadErrors_worker4.js threadTimeouts_worker.js throwingOnerror_worker.js + timeoutTracing_worker.js transferable_worker.js urlApi_worker.js url_worker.js @@ -96,6 +97,7 @@ support-files = [test_threadErrors.html] [test_threadTimeouts.html] [test_throwingOnerror.html] +[test_timeoutTracing.html] [test_transferable.html] [test_url.html] [test_urlApi.html] diff --git a/dom/workers/test/test_timeoutTracing.html b/dom/workers/test/test_timeoutTracing.html new file mode 100644 index 000000000000..b995f487908e --- /dev/null +++ b/dom/workers/test/test_timeoutTracing.html @@ -0,0 +1,47 @@ + + + + + + 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 index 000000000000..d62cc50c5429 --- /dev/null +++ b/dom/workers/test/timeoutTracing_worker.js @@ -0,0 +1,13 @@ +/** + * 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!"); }, 20); +setInterval(";", 20); + +postMessage("Begin!");