diff --git a/dom/base/Console.cpp b/dom/base/Console.cpp index c285831cb34..8e32ce44b55 100644 --- a/dom/base/Console.cpp +++ b/dom/base/Console.cpp @@ -6,9 +6,7 @@ #include "mozilla/dom/Console.h" #include "mozilla/dom/ConsoleBinding.h" -#include "mozilla/dom/BlobBinding.h" #include "mozilla/dom/Exceptions.h" -#include "mozilla/dom/File.h" #include "mozilla/dom/ToJSValue.h" #include "mozilla/Maybe.h" #include "nsCycleCollectionParticipant.h" @@ -43,10 +41,9 @@ // console.trace(). #define DEFAULT_MAX_STACKTRACE_DEPTH 200 -// This tags are used in the Structured Clone Algorithm to move js values from +// This tag is used in the Structured Clone Algorithm to move js values from // worker thread to main thread -#define CONSOLE_TAG_STRING JS_SCTAG_USER_MIN -#define CONSOLE_TAG_BLOB JS_SCTAG_USER_MIN + 1 +#define CONSOLE_TAG JS_SCTAG_USER_MIN using namespace mozilla::dom::exceptions; using namespace mozilla::dom::workers; @@ -54,14 +51,6 @@ using namespace mozilla::dom::workers; namespace mozilla { namespace dom { -struct -ConsoleStructuredCloneData -{ - nsCOMPtr mParent; - nsTArray mStrings; - nsTArray> mFiles; -}; - /** * Console API in workers uses the Structured Clone Algorithm to move any value * from the worker thread to the main-thread. Some object cannot be moved and, @@ -74,41 +63,29 @@ ConsoleStructuredCloneData static JSObject* ConsoleStructuredCloneCallbacksRead(JSContext* aCx, JSStructuredCloneReader* /* unused */, - uint32_t aTag, uint32_t aIndex, + uint32_t aTag, uint32_t aData, void* aClosure) { AssertIsOnMainThread(); - ConsoleStructuredCloneData* data = - static_cast(aClosure); - MOZ_ASSERT(data); - MOZ_ASSERT(data->mParent); - if (aTag == CONSOLE_TAG_STRING) { - MOZ_ASSERT(data->mStrings.Length() > aIndex); - - JS::Rooted value(aCx); - if (!xpc::StringToJsval(aCx, data->mStrings.ElementAt(aIndex), &value)) { - return nullptr; - } - - JS::Rooted obj(aCx); - if (!JS_ValueToObject(aCx, value, &obj)) { - return nullptr; - } - - return obj; + if (aTag != CONSOLE_TAG) { + return nullptr; } - if (aTag == CONSOLE_TAG_BLOB) { - MOZ_ASSERT(data->mFiles.Length() > aIndex); + nsTArray* strings = static_cast*>(aClosure); + MOZ_ASSERT(strings->Length() > aData); - nsRefPtr file = - new File(data->mParent, data->mFiles.ElementAt(aIndex)); - return file->WrapObject(aCx); + JS::Rooted value(aCx); + if (!xpc::StringToJsval(aCx, strings->ElementAt(aData), &value)) { + return nullptr; } - MOZ_CRASH("No other tags are supported."); - return nullptr; + JS::Rooted obj(aCx); + if (!JS_ValueToObject(aCx, value, &obj)) { + return nullptr; + } + + return obj; } // This method is called by the Structured Clone Algorithm when some data has @@ -119,21 +96,6 @@ ConsoleStructuredCloneCallbacksWrite(JSContext* aCx, JS::Handle aObj, void* aClosure) { - ConsoleStructuredCloneData* data = - static_cast(aClosure); - MOZ_ASSERT(data); - - nsRefPtr file; - if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, file)) && - file->Impl()->MayBeClonedToOtherThreads()) { - if (!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_BLOB, data->mFiles.Length())) { - return false; - } - - data->mFiles.AppendElement(file->Impl()); - return true; - } - JS::Rooted value(aCx, JS::ObjectOrNullValue(aObj)); JS::Rooted jsString(aCx, JS::ToString(aCx, value)); if (!jsString) { @@ -145,12 +107,14 @@ ConsoleStructuredCloneCallbacksWrite(JSContext* aCx, return false; } - if (!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_STRING, - data->mStrings.Length())) { + nsTArray* strings = static_cast*>(aClosure); + + if (!JS_WriteUint32Pair(aWriter, CONSOLE_TAG, strings->Length())) { return false; } - data->mStrings.AppendElement(string); + strings->AppendElement(string); + return true; } @@ -450,7 +414,7 @@ private: JS::Rooted value(aCx, JS::ObjectValue(*arguments)); - if (!mArguments.write(aCx, value, &gConsoleCallbacks, &mData)) { + if (!mArguments.write(aCx, value, &gConsoleCallbacks, &mStrings)) { return false; } @@ -487,13 +451,8 @@ private: mCallData->SetIDs(id, frame.mFilename); } - // Now we could have the correct window (if we are not window-less). - mData.mParent = aInnerWindow; - ProcessCallData(aCx); mCallData->CleanupJSObjects(); - - mData.mParent = nullptr; } private: @@ -503,7 +462,7 @@ private: ClearException ce(aCx); JS::Rooted argumentsValue(aCx); - if (!mArguments.read(aCx, &argumentsValue, &gConsoleCallbacks, &mData)) { + if (!mArguments.read(aCx, &argumentsValue, &gConsoleCallbacks, &mStrings)) { return; } @@ -535,7 +494,7 @@ private: ConsoleCallData* mCallData; JSAutoStructuredCloneBuffer mArguments; - ConsoleStructuredCloneData mData; + nsTArray mStrings; }; // This runnable calls ProfileMethod() on the console on the main-thread. @@ -580,7 +539,7 @@ private: JS::Rooted value(aCx, JS::ObjectValue(*arguments)); - if (!mBuffer.write(aCx, value, &gConsoleCallbacks, &mData)) { + if (!mBuffer.write(aCx, value, &gConsoleCallbacks, &mStrings)) { return false; } @@ -593,14 +552,8 @@ private: { ClearException ce(aCx); - // Now we could have the correct window (if we are not window-less). - mData.mParent = aInnerWindow; - JS::Rooted argumentsValue(aCx); - bool ok = mBuffer.read(aCx, &argumentsValue, &gConsoleCallbacks, &mData); - mData.mParent = nullptr; - - if (!ok) { + if (!mBuffer.read(aCx, &argumentsValue, &gConsoleCallbacks, &mStrings)) { return; } @@ -632,7 +585,7 @@ private: Sequence mArguments; JSAutoStructuredCloneBuffer mBuffer; - ConsoleStructuredCloneData mData; + nsTArray mStrings; }; NS_IMPL_CYCLE_COLLECTION_CLASS(Console) diff --git a/dom/workers/test/mochitest.ini b/dom/workers/test/mochitest.ini index 5e9edc000df..4049bd4f566 100644 --- a/dom/workers/test/mochitest.ini +++ b/dom/workers/test/mochitest.ini @@ -97,7 +97,6 @@ support-files = bug1062920_worker.js webSocket_sharedWorker.js bug1104064_worker.js - worker_consoleAndBlobs.js [test_404.html] [test_atob.html] @@ -198,4 +197,3 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #bug 982828 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #bug 982828 [test_websocket_pref.html] [test_bug1104064.html] -[test_consoleAndBlobs.html] diff --git a/dom/workers/test/test_consoleAndBlobs.html b/dom/workers/test/test_consoleAndBlobs.html deleted file mode 100644 index ed8c818d6e5..00000000000 --- a/dom/workers/test/test_consoleAndBlobs.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - Test for console API and blobs - - - - - - - diff --git a/dom/workers/test/worker_consoleAndBlobs.js b/dom/workers/test/worker_consoleAndBlobs.js deleted file mode 100644 index 4c5537c99d8..00000000000 --- a/dom/workers/test/worker_consoleAndBlobs.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ -"use strict"; - -var b = new Blob(['123'], { type: 'foo/bar'}); -console.log(b);