diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index ff37cf75cc3b..383fb37651f6 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -53,11 +53,13 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerGlobalScope) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(WorkerGlobalScope, DOMEventTargetHelper) tmp->mWorkerPrivate->AssertIsOnWorkerThread(); + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsole) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(WorkerGlobalScope, DOMEventTargetHelper) tmp->mWorkerPrivate->AssertIsOnWorkerThread(); + NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsole) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(WorkerGlobalScope, @@ -80,17 +82,16 @@ WorkerGlobalScope::WrapObject(JSContext* aCx) MOZ_CRASH("We should never get here!"); } -already_AddRefed +Console* WorkerGlobalScope::GetConsole() { mWorkerPrivate->AssertIsOnWorkerThread(); if (!mConsole) { mConsole = new Console(nullptr); - MOZ_ASSERT(mConsole); } - return mConsole.forget(); + return mConsole; } already_AddRefed diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h index 2d5541af1048..d5abe644deba 100644 --- a/dom/workers/WorkerScope.h +++ b/dom/workers/WorkerScope.h @@ -60,7 +60,7 @@ public: return nsRefPtr(this).forget(); } - already_AddRefed + Console* GetConsole(); already_AddRefed diff --git a/dom/workers/test/consoleReplaceable_worker.js b/dom/workers/test/consoleReplaceable_worker.js index 87ae6af6bec4..aaf104af1365 100644 --- a/dom/workers/test/consoleReplaceable_worker.js +++ b/dom/workers/test/consoleReplaceable_worker.js @@ -5,6 +5,12 @@ onmessage = function(event) { postMessage({event: 'console exists', status: !!console, last : false}); + var logCalled = false; + console.log = function() { + logCalled = true; + } + console.log("foo"); + postMessage({event: 'console.log is replaceable', status: logCalled, last: false}); console = 42; postMessage({event: 'console is replaceable', status: console === 42, last : true}); } diff --git a/dom/workers/test/console_worker.js b/dom/workers/test/console_worker.js index 1ef9211251c8..4e0d68defdc5 100644 --- a/dom/workers/test/console_worker.js +++ b/dom/workers/test/console_worker.js @@ -7,6 +7,8 @@ onmessage = function(event) { // TEST: does console exist? postMessage({event: 'console exists', status: !!console, last : false}); + postMessage({event: 'console is the same object', status: console === console, last: false}); + postMessage({event: 'trace without function', status: true, last : false}); for (var i = 0; i < 10; ++i) {