diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -173,16 +173,60 @@ private: #ifdef DEBUG mDatabase = nullptr; #endif } }; } // anonymous namespace +class IDBDatabase::LogWarningRunnable MOZ_FINAL + : public nsRunnable +{ + nsCString mMessageName; + nsString mFilename; + uint32_t mLineNumber; + uint64_t mInnerWindowID; + bool mIsChrome; + bool mIsWindow; + +public: + LogWarningRunnable(const char* aMessageName, + const nsAString& aFilename, + uint32_t aLineNumber, + bool aIsChrome, + bool aIsWindow, + uint64_t aInnerWindowID) + : mMessageName(aMessageName) + , mFilename(aFilename) + , mLineNumber(aLineNumber) + , mInnerWindowID(aInnerWindowID) + , mIsChrome(aIsChrome) + , mIsWindow(aIsWindow) + { + MOZ_ASSERT(!NS_IsMainThread()); + } + + static void + LogWarning(const char* aMessageName, + const nsAString& aFilename, + uint32_t aLineNumber, + bool aIsChrome, + bool aIsWindow, + uint64_t aInnerWindowID); + + NS_DECL_ISUPPORTS_INHERITED + +private: + ~LogWarningRunnable() + { } + + NS_DECL_NSIRUNNABLE +}; + class IDBDatabase::Observer MOZ_FINAL : public nsIObserver { IDBDatabase* mWeakDatabase; const uint64_t mWindowId; public: Observer(IDBDatabase* aDatabase, uint64_t aWindowId) @@ -1224,73 +1268,44 @@ IDBDatabase::Invalidate() if (!mInvalidated) { mInvalidated = true; InvalidateInternal(); } } +// static void IDBDatabase::LogWarning(const char* aMessageName, const nsAString& aFilename, uint32_t aLineNumber) { AssertIsOnOwningThread(); MOZ_ASSERT(aMessageName); - // For now this is main-thread only. - MOZ_ASSERT(NS_IsMainThread()); + if (!NS_IsMainThread()) { + nsRefPtr runnable = + new LogWarningRunnable(aMessageName, + aFilename, + aLineNumber, + mFactory->IsChrome(), + !!mFactory->GetParentObject(), + mFactory->InnerWindowID()); + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable))); - nsXPIDLString localizedMessage; - if (NS_WARN_IF(NS_FAILED( - nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES, - aMessageName, - localizedMessage)))) { return; } - nsAutoCString category; - if (mFactory->IsChrome()) { - category.AssignLiteral("chrome "); - } else { - category.AssignLiteral("content "); - } - category.AppendLiteral("javascript"); - - nsCOMPtr consoleService = - do_GetService(NS_CONSOLESERVICE_CONTRACTID); - MOZ_ASSERT(consoleService); - - nsCOMPtr scriptError = - do_CreateInstance(NS_SCRIPTERROR_CONTRACTID); - MOZ_ASSERT(consoleService); - - if (mFactory->GetParentObject()) { - MOZ_ALWAYS_TRUE(NS_SUCCEEDED( - scriptError->InitWithWindowID(localizedMessage, - aFilename, - /* aSourceLine */ EmptyString(), - aLineNumber, - /* aColumnNumber */ 0, - nsIScriptError::warningFlag, - category, - mFactory->InnerWindowID()))); - } else { - MOZ_ALWAYS_TRUE(NS_SUCCEEDED( - scriptError->Init(localizedMessage, - aFilename, - /* aSourceLine */ EmptyString(), - aLineNumber, - /* aColumnNumber */ 0, - nsIScriptError::warningFlag, - category.get()))); - } - - MOZ_ALWAYS_TRUE(NS_SUCCEEDED(consoleService->LogMessage(scriptError))); + LogWarningRunnable::LogWarning(aMessageName, + aFilename, + aLineNumber, + mFactory->IsChrome(), + !!mFactory->GetParentObject(), + mFactory->InnerWindowID()); } NS_IMPL_ADDREF_INHERITED(IDBDatabase, IDBWrapperCache) NS_IMPL_RELEASE_INHERITED(IDBDatabase, IDBWrapperCache) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBDatabase) NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache) @@ -1545,16 +1560,96 @@ CreateFileHelper::Run() mResultCode = rv; } MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(this))); return NS_OK; } + +// static +void +IDBDatabase:: +LogWarningRunnable::LogWarning(const char* aMessageName, + const nsAString& aFilename, + uint32_t aLineNumber, + bool aIsChrome, + bool aIsWindow, + uint64_t aInnerWindowID) +{ + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(aMessageName); + + nsXPIDLString localizedMessage; + if (NS_WARN_IF(NS_FAILED( + nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES, + aMessageName, + localizedMessage)))) { + return; + } + + nsAutoCString category; + if (aIsChrome) { + category.AssignLiteral("chrome "); + } else { + category.AssignLiteral("content "); + } + category.AppendLiteral("javascript"); + + nsCOMPtr consoleService = + do_GetService(NS_CONSOLESERVICE_CONTRACTID); + MOZ_ASSERT(consoleService); + + nsCOMPtr scriptError = + do_CreateInstance(NS_SCRIPTERROR_CONTRACTID); + MOZ_ASSERT(consoleService); + + if (aIsWindow) { + MOZ_ALWAYS_TRUE(NS_SUCCEEDED( + scriptError->InitWithWindowID(localizedMessage, + aFilename, + /* aSourceLine */ EmptyString(), + aLineNumber, + /* aColumnNumber */ 0, + nsIScriptError::warningFlag, + category, + aInnerWindowID))); + } else { + MOZ_ALWAYS_TRUE(NS_SUCCEEDED( + scriptError->Init(localizedMessage, + aFilename, + /* aSourceLine */ EmptyString(), + aLineNumber, + /* aColumnNumber */ 0, + nsIScriptError::warningFlag, + category.get()))); + } + + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(consoleService->LogMessage(scriptError))); +} + +NS_IMPL_ISUPPORTS_INHERITED0(IDBDatabase::LogWarningRunnable, nsRunnable) + +NS_IMETHODIMP +IDBDatabase:: +LogWarningRunnable::Run() +{ + MOZ_ASSERT(NS_IsMainThread()); + + LogWarning(mMessageName.get(), + mFilename, + mLineNumber, + mIsChrome, + mIsWindow, + mInnerWindowID); + + return NS_OK; +} + NS_IMPL_ISUPPORTS(IDBDatabase::Observer, nsIObserver) NS_IMETHODIMP IDBDatabase:: Observer::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { diff --git a/dom/indexedDB/IDBDatabase.h b/dom/indexedDB/IDBDatabase.h --- a/dom/indexedDB/IDBDatabase.h +++ b/dom/indexedDB/IDBDatabase.h @@ -47,16 +47,19 @@ class IDBTransaction; class PBackgroundIDBDatabaseFileChild; class IDBDatabase MOZ_FINAL : public IDBWrapperCache { typedef mozilla::dom::StorageType StorageType; typedef mozilla::dom::quota::PersistenceType PersistenceType; + class LogWarningRunnable; + friend class LogWarningRunnable; + class Observer; friend class Observer; // The factory must be kept alive when IndexedDB is used in multiple // processes. If it dies then the entire actor tree will be destroyed with it // and the world will explode. nsRefPtr mFactory; diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -981,19 +981,16 @@ IDBObjectStore::ClearCloneReadInfo(Struc { // This is kind of tricky, we only want to release stuff on the main thread, // but we can end up being called on other threads if we have already been // cleared on the main thread. if (!aReadInfo.mCloneBuffer.data() && !aReadInfo.mFiles.Length()) { return; } - // If there's something to clear, we should be on the main thread. - NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - ClearStructuredCloneBuffer(aReadInfo.mCloneBuffer); aReadInfo.mFiles.Clear(); } // static bool IDBObjectStore::DeserializeValue(JSContext* aCx, StructuredCloneReadInfo& aCloneReadInfo, @@ -1522,18 +1519,16 @@ IDBObjectStore::GetParentObject() const return mTransaction->GetParentObject(); } void IDBObjectStore::GetKeyPath(JSContext* aCx, JS::MutableHandle aResult, ErrorResult& aRv) { - NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - if (!mCachedKeyPath.isUndefined()) { JS::ExposeValueToActiveJS(mCachedKeyPath); aResult.set(mCachedKeyPath); return; } aRv = GetKeyPath().ToJSVal(aCx, mCachedKeyPath); if (NS_WARN_IF(aRv.Failed())) { diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -3,16 +3,17 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WorkerScope.h" #include "jsapi.h" #include "mozilla/EventListenerManager.h" +#include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/Console.h" #include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h" #include "mozilla/dom/Fetch.h" #include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h" #include "mozilla/dom/SharedWorkerGlobalScopeBinding.h" #include "mozilla/dom/indexedDB/IDBFactory.h" @@ -330,20 +331,26 @@ WorkerGlobalScope::GetIndexedDB(ErrorRes JSContext* cx = mWorkerPrivate->GetJSContext(); MOZ_ASSERT(cx); JS::Rooted owningObject(cx, GetGlobalJSObject()); MOZ_ASSERT(owningObject); const PrincipalInfo& principalInfo = mWorkerPrivate->GetPrincipalInfo(); + Optional optionalWindowID; + if (uint64_t windowID = mWorkerPrivate->WindowID()) { + optionalWindowID.Construct(windowID); + } + nsresult rv = IDBFactory::CreateForWorker(cx, owningObject, principalInfo, + optionalWindowID, getter_AddRefs(indexedDB)); if (NS_WARN_IF(NS_FAILED(rv))) { aErrorResult = rv; return nullptr; } mIndexedDB = indexedDB; }