Bug 1052052 - Hoist Auto*JSContext into nsContentUtils and kill nsCxPusher.{cpp,h}. r=gabor

This commit is contained in:
Bobby Holley 2014-08-14 18:47:15 -07:00
parent 850fc35028
commit e70ddb7476
93 changed files with 196 additions and 279 deletions

View File

@ -19,9 +19,9 @@
#include "nsIClassInfoImpl.h"
#include "nsError.h"
#include "nsIContentSecurityPolicy.h"
#include "nsCxPusher.h"
#include "jswrapper.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/Preferences.h"
#include "mozilla/HashFunctions.h"

View File

@ -61,10 +61,10 @@
#include "mozilla/Preferences.h"
#include "mozilla/dom/BindingUtils.h"
#include <stdint.h>
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/StaticPtr.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsJSUtils.h"
#include "nsILoadInfo.h"

View File

@ -24,11 +24,11 @@
#include "mozilla/GuardObjects.h"
#include "mozilla/TimeStamp.h"
#include "nsContentListDeclarations.h"
#include "nsCxPusher.h"
#include "nsMathUtils.h"
#include "nsTArrayForwardDeclare.h"
#include "Units.h"
#include "mozilla/dom/AutocompleteInfoBinding.h"
#include "mozilla/dom/ScriptSettings.h"
#if defined(XP_WIN)
// Undefine LoadImage to prevent naming conflict with Windows.

View File

@ -12,7 +12,6 @@
#include <math.h>
#include "prprf.h"
#include "nsCxPusher.h"
#include "DecoderTraits.h"
#include "harfbuzz/hb.h"
#include "imgICache.h"

View File

@ -39,7 +39,6 @@
#include "nsIDocShellTreeItem.h"
#include "nsCOMArray.h"
#include "nsDOMClassInfo.h"
#include "nsCxPusher.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/BasicEvents.h"

View File

@ -10,7 +10,6 @@
#include "AppProcessChecker.h"
#include "ContentChild.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsError.h"
#include "nsIXPConnect.h"
#include "jsapi.h"
@ -33,6 +32,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/dom/nsIContentParent.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/dom/PBlobChild.h"
#include "mozilla/dom/PBlobParent.h"

View File

@ -6,7 +6,6 @@
#include "nsNodeUtils.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsINode.h"
#include "nsIContent.h"
#include "mozilla/dom/Element.h"

View File

@ -48,7 +48,6 @@
#include "nsCURILoader.h"
#include "nsContentPolicyUtils.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsDocShellCID.h"
#include "nsGkAtoms.h"
#include "nsThreadUtils.h"

View File

@ -33,7 +33,6 @@
#include "nsIDOMHTMLScriptElement.h"
#include "nsIDocShell.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsUnicharUtils.h"
#include "nsAutoPtr.h"
#include "nsIXPConnect.h"

View File

@ -41,7 +41,6 @@
#include "nsIStreamConverterService.h"
#include "nsICachingChannel.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIContentPolicy.h"
#include "nsContentPolicyUtils.h"

View File

@ -23,7 +23,6 @@
#ifdef MOZ_WIDGET_GONK
#include "nsJSUtils.h"
#include "nsCxPusher.h"
#include "nsIAudioManager.h"
#include "SpeakerManagerService.h"
#define NS_AUDIOMANAGER_CONTRACTID "@mozilla.org/telephony/audiomanager;1"

View File

@ -7,7 +7,6 @@
#include "DOMRequest.h"
#include "DOMError.h"
#include "nsCxPusher.h"
#include "nsThreadUtils.h"
#include "DOMCursor.h"
#include "nsIDOMEvent.h"

View File

@ -20,6 +20,7 @@
#include "nsTArray.h"
#include "nsJSUtils.h"
#include "nsDOMJSUtils.h"
#include "WorkerPrivate.h"
namespace mozilla {
namespace dom {
@ -437,4 +438,91 @@ danger::AutoCxPusher::IsStackTop() const
}
} // namespace dom
AutoJSContext::AutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
: mCx(nullptr)
{
Init(false MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT);
}
AutoJSContext::AutoJSContext(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
: mCx(nullptr)
{
Init(aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT);
}
void
AutoJSContext::Init(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
{
JS::AutoSuppressGCAnalysis nogc;
MOZ_ASSERT(!mCx, "mCx should not be initialized!");
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
nsXPConnect *xpc = nsXPConnect::XPConnect();
if (!aSafe) {
mCx = xpc->GetCurrentJSContext();
}
if (!mCx) {
mCx = xpc->GetSafeJSContext();
mPusher.emplace(mCx);
}
}
AutoJSContext::operator JSContext*() const
{
return mCx;
}
ThreadsafeAutoJSContext::ThreadsafeAutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (NS_IsMainThread()) {
mCx = nullptr;
mAutoJSContext.emplace();
} else {
mCx = mozilla::dom::workers::GetCurrentThreadJSContext();
mRequest.emplace(mCx);
}
}
ThreadsafeAutoJSContext::operator JSContext*() const
{
if (mCx) {
return mCx;
} else {
return *mAutoJSContext;
}
}
AutoSafeJSContext::AutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
: AutoJSContext(true MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT)
, mAc(mCx, XPCJSRuntime::Get()->GetJSContextStack()->GetSafeJSContextGlobal())
{
}
ThreadsafeAutoSafeJSContext::ThreadsafeAutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (NS_IsMainThread()) {
mCx = nullptr;
mAutoSafeJSContext.emplace();
} else {
mCx = mozilla::dom::workers::GetCurrentThreadJSContext();
mRequest.emplace(mCx);
}
}
ThreadsafeAutoSafeJSContext::operator JSContext*() const
{
if (mCx) {
return mCx;
} else {
return *mAutoSafeJSContext;
}
}
} // namespace mozilla

View File

@ -24,6 +24,7 @@ class nsIScriptContext;
namespace mozilla {
namespace dom {
// For internal use only - use AutoJSAPI instead.
namespace danger {
/**
@ -279,6 +280,75 @@ private:
};
} // namespace dom
/**
* Use AutoJSContext when you need a JS context on the stack but don't have one
* passed as a parameter. AutoJSContext will take care of finding the most
* appropriate JS context and release it when leaving the stack.
*/
class MOZ_STACK_CLASS AutoJSContext {
public:
explicit AutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
operator JSContext*() const;
protected:
explicit AutoJSContext(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
// We need this Init() method because we can't use delegating constructor for
// the moment. It is a C++11 feature and we do not require C++11 to be
// supported to be able to compile Gecko.
void Init(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
JSContext* mCx;
Maybe<dom::danger::AutoCxPusher> mPusher;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/**
* Use ThreadsafeAutoJSContext when you want an AutoJSContext but might be
* running on a worker thread.
*/
class MOZ_STACK_CLASS ThreadsafeAutoJSContext {
public:
explicit ThreadsafeAutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
operator JSContext*() const;
private:
JSContext* mCx; // Used on workers. Null means mainthread.
Maybe<JSAutoRequest> mRequest; // Used on workers.
Maybe<AutoJSContext> mAutoJSContext; // Used on main thread.
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/**
* AutoSafeJSContext is similar to AutoJSContext but will only return the safe
* JS context. That means it will never call nsContentUtils::GetCurrentJSContext().
*
* Note - This is deprecated. Please use AutoJSAPI instead.
*/
class MOZ_STACK_CLASS AutoSafeJSContext : public AutoJSContext {
public:
explicit AutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
private:
JSAutoCompartment mAc;
};
/**
* Like AutoSafeJSContext but can be used safely on worker threads.
*/
class MOZ_STACK_CLASS ThreadsafeAutoSafeJSContext {
public:
explicit ThreadsafeAutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
operator JSContext*() const;
private:
JSContext* mCx; // Used on workers. Null means mainthread.
Maybe<JSAutoRequest> mRequest; // Used on workers.
Maybe<AutoSafeJSContext> mAutoSafeJSContext; // Used on main thread.
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
} // namespace mozilla
#endif // mozilla_dom_ScriptSettings_h

View File

@ -21,7 +21,6 @@
#include "nsArrayUtils.h"
#include "nsIMutableArray.h"
#include "nsContentPermissionHelper.h"
#include "nsCxPusher.h"
#include "nsJSUtils.h"
#include "nsISupportsPrimitives.h"
#include "nsServiceManagerUtils.h"

View File

@ -48,7 +48,6 @@
#include "nsIDOMEvent.h"
#include "nsIDOMEventListener.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIDOMGlobalPropertyInitializer.h"
#include "mozilla/Attributes.h"
#include "mozilla/Telemetry.h"

View File

@ -119,7 +119,6 @@
#include "nsGlobalWindowCommands.h"
#include "nsAutoPtr.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsCSSProps.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"

View File

@ -31,7 +31,6 @@
#include "nsITimer.h"
#include "nsIAtom.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "mozilla/EventDispatcher.h"
#include "nsIContent.h"
#include "nsCycleCollector.h"

View File

@ -14,7 +14,6 @@
#include "nsIScriptContext.h"
#include "nsPIDOMWindow.h"
#include "nsJSUtils.h"
#include "nsCxPusher.h"
#include "nsIScriptSecurityManager.h"
#include "xpcprivate.h"
#include "WorkerPrivate.h"

View File

@ -11831,7 +11831,6 @@ class CGBindingRoot(CGThing):
bindingHeaders["nsThreadUtils.h"] = hasWorkerStuff
dictionaries = config.getDictionaries(webIDLFile=webIDLFile)
bindingHeaders["nsCxPusher.h"] = dictionaries
hasNonEmptyDictionaries = any(
len(dict.members) > 0 for dict in dictionaries)
mainCallbacks = config.getCallbacks(webIDLFile=webIDLFile,

View File

@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "BluetoothReplyRunnable.h"
#include "DOMRequest.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "nsServiceManagerUtils.h"

View File

@ -28,7 +28,6 @@
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/ipc/UnixSocket.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIObserverService.h"
#include "nsISettingsService.h"
#include "nsISystemMessagesInternal.h"

View File

@ -14,7 +14,6 @@
#include "mozilla/Scoped.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIScriptContext.h"
#include "nsISystemMessagesInternal.h"
#include "nsString.h"

View File

@ -13,7 +13,6 @@
#include "mozilla/Scoped.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIScriptContext.h"
#include "nsISystemMessagesInternal.h"
#include "nsString.h"

View File

@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "BluetoothReplyRunnable.h"
#include "DOMRequest.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/dom/Promise.h"
#include "nsServiceManagerUtils.h"

View File

@ -27,7 +27,6 @@
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIObserverService.h"
#include "nsISettingsService.h"
#include "nsISystemMessagesInternal.h"

View File

@ -12,9 +12,9 @@
#include "BluetoothUtils.h"
#include "jsapi.h"
#include "mozilla/Scoped.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIScriptContext.h"
#include "nsISystemMessagesInternal.h"
#include "nsString.h"

View File

@ -11,9 +11,9 @@
#include "BluetoothUtils.h"
#include "jsapi.h"
#include "mozilla/Scoped.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIScriptContext.h"
#include "nsISystemMessagesInternal.h"
#include "nsString.h"

View File

@ -19,7 +19,6 @@
#include "nsIInterfaceRequestorUtils.h"
#include "nsVariant.h"
#include "mozilla/dom/BrowserElementDictionariesBinding.h"
#include "nsCxPusher.h"
#include "mozilla/dom/CustomEvent.h"
using namespace mozilla;

View File

@ -10,7 +10,6 @@
#include "GLContext.h"
#include "jsapi.h"
#include "mozilla/Preferences.h"
#include "nsCxPusher.h"
#include "nsIDOMDataContainerEvent.h"
#include "nsIDOMEvent.h"
#include "nsIScriptSecurityManager.h"
@ -24,6 +23,8 @@
#include "WebGLTexture.h"
#include "WebGLVertexArray.h"
#include "mozilla/dom/ScriptSettings.h"
namespace mozilla {
using namespace gl;

View File

@ -43,7 +43,6 @@
#include "nsIPrincipal.h"
#include "nsJSUtils.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsXULAppAPI.h"
#include "DeviceStorageFileDescriptor.h"
#include "DeviceStorageRequestChild.h"

View File

@ -10,7 +10,6 @@
#include "mozilla/JSEventHandler.h"
#include "mozilla/Maybe.h"
#include "nsCOMArray.h"
#include "nsCxPusher.h"
#include "nsDOMClassInfoID.h"
#include "nsIXPConnect.h"
#include "nsJSUtils.h"

View File

@ -12,10 +12,10 @@
#include "nsDOMClassInfo.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/FMRadioChild.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsIObserverService.h"
#include "nsISettingsService.h"
#include "nsJSUtils.h"
#include "nsCxPusher.h"
#define BAND_87500_108000_kHz 1
#define BAND_76000_108000_kHz 2

View File

@ -26,7 +26,6 @@
#include "nsComponentManagerUtils.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsDOMClassInfoID.h"
#include "nsGlobalWindow.h"
#include "nsHashKeys.h"

View File

@ -16,7 +16,6 @@
#include "mozilla/dom/ProgressEvent.h"
#include "mozilla/EventDispatcher.h"
#include "nsCOMPtr.h"
#include "nsCxPusher.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsIDOMEvent.h"

View File

@ -18,7 +18,6 @@
#include "nsDOMClassInfoID.h"
#include "nsDOMJSUtils.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsJSUtils.h"
#include "nsPIDOMWindow.h"
#include "nsString.h"

View File

@ -17,7 +17,6 @@
#include "mozilla/dom/ipc/Blob.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/unused.h"
#include "nsCxPusher.h"
#include "AsyncConnectionHelper.h"
#include "DatabaseInfo.h"

View File

@ -8,10 +8,10 @@
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsIPropertyBag2.h"
#include "ProcessPriorityManager.h"
#include "nsServiceManagerUtils.h"
#include "nsCxPusher.h"
#ifdef MOZ_NUWA_PROCESS
#include "ipc/Nuwa.h"

View File

@ -34,7 +34,6 @@
#include "mozilla/unused.h"
#include "mozIApplication.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsEmbedCID.h"
#include <algorithm>
#ifdef MOZ_CRASHREPORTER

View File

@ -8,7 +8,6 @@
#include "mozilla/dom/GetUserMediaRequestBinding.h"
#include "nsIScriptGlobalObject.h"
#include "nsPIDOMWindow.h"
#include "nsCxPusher.h"
namespace mozilla {
namespace dom {

View File

@ -6,7 +6,6 @@
#include "MediaPermissionGonk.h"
#include "nsCOMPtr.h"
#include "nsCxPusher.h"
#include "nsIContentPermissionPrompt.h"
#include "nsIDocument.h"
#include "nsIDOMNavigatorUserMedia.h"

View File

@ -6,8 +6,9 @@
#include "MobileConnectionInfo.h"
#include "mozilla/dom/ScriptSettings.h"
#include "jsapi.h"
#include "nsCxPusher.h"
#define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum) \
{ \

View File

@ -14,9 +14,9 @@
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
#include "mozilla/dom/mobilemessage/SmsTypes.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsDOMFile.h"
#include "nsCxPusher.h"
using namespace mozilla::dom::mobilemessage;

View File

@ -6,7 +6,6 @@
#include "MobileMessageCallback.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIDOMMozSmsMessage.h"
#include "nsIDOMMozMmsMessage.h"
#include "nsIScriptGlobalObject.h"

View File

@ -10,7 +10,6 @@
#include "SmsMessage.h"
#include "SmsFilter.h"
#include "nsJSUtils.h"
#include "nsCxPusher.h"
#include "mozilla/dom/MozMobileMessageManagerBinding.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/Preferences.h"

View File

@ -22,7 +22,6 @@
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
#include "nsContentUtils.h"
#include "nsTArrayHelpers.h"
#include "nsCxPusher.h"
#include "xpcpublic.h"
#include "nsServiceManagerUtils.h"
#include "DeletedMessageInfo.h"

View File

@ -7,12 +7,12 @@
#include "jsfriendapi.h"
#include "nsJSUtils.h"
#include "nsIDOMTCPSocket.h"
#include "nsCxPusher.h"
#include "mozilla/unused.h"
#include "mozilla/AppProcessChecker.h"
#include "mozilla/net/NeckoCommon.h"
#include "mozilla/net/PNeckoParent.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/TabParent.h"
#include "nsIScriptSecurityManager.h"

View File

@ -9,7 +9,6 @@
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/RootedDictionary.h"
#include "nsAutoPtr.h"
#include "nsCxPusher.h"
#include "nsString.h"
#include "nsXULAppAPI.h"
#include "NfcOptions.h"

View File

@ -17,7 +17,6 @@
#include "nsIScriptContext.h"
#include "nsDOMJSUtils.h"
#include "nsJSUtils.h"
#include "nsCxPusher.h"
#include "nsIDocument.h"
#include "nsIJSRuntimeService.h"
#include "nsIXPConnect.h"

View File

@ -40,7 +40,6 @@
#include "nsIPrincipal.h"
#include "nsWildCard.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsIXPConnect.h"

View File

@ -10,8 +10,7 @@
#include "npfunctions.h"
#include "nsPluginHost.h"
#include "nsCxPusher.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/PluginLibrary.h"
#if defined(XP_WIN)

View File

@ -9,7 +9,6 @@
#include "nsNPAPIPlugin.h"
#include "nsServiceManagerUtils.h"
#include "PluginScriptableObjectUtils.h"
#include "nsCxPusher.h"
#include "mozilla/unused.h"
using namespace mozilla::plugins::parent;

View File

@ -9,7 +9,6 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/plugins/PluginIdentifierParent.h"
#include "mozilla/unused.h"
#include "nsCxPusher.h"
#include "nsNPAPIPlugin.h"
#include "PluginScriptableObjectUtils.h"

View File

@ -36,7 +36,6 @@
#include "nsIContentViewer.h"
#include "nsIXPConnect.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsJSUtils.h"
#include "nsThreadUtils.h"
#include "nsIScriptChannel.h"

View File

@ -30,13 +30,13 @@
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/ScriptSettings.h"
#include "base/message_loop.h"
#include "BluetoothCommon.h"
#include "BluetoothHfpManagerBase.h"
#include "nsJSUtils.h"
#include "nsCxPusher.h"
#include "nsThreadUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"

View File

@ -11,7 +11,6 @@
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsIObserverService.h"
#include "nsCxPusher.h"
#include "nsISettingsService.h"
#include "nsJSUtils.h"
#include "nsPrintfCString.h"
@ -19,6 +18,7 @@
#include "nsString.h"
#include "nsThreadUtils.h"
#include "xpcpublic.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/Attributes.h"
#undef LOG

View File

@ -7,9 +7,9 @@
#include <nsThreadUtils.h>
#include "mozilla/ModuleUtils.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsXULAppAPI.h"
#include "nsCxPusher.h"
#define NS_NETWORKWORKER_CID \
{ 0x6df093e1, 0x8127, 0x4fa7, {0x90, 0x13, 0xa3, 0xaa, 0xa7, 0x79, 0xbb, 0xdd} }

View File

@ -27,12 +27,12 @@
#include "AutoMounter.h"
#include "TimeZoneSettingObserver.h"
#include "AudioManager.h"
#include "mozilla/dom/ScriptSettings.h"
#ifdef MOZ_B2G_RIL
#include "mozilla/ipc/Ril.h"
#endif
#include "mozilla/ipc/KeyStore.h"
#include "nsIObserverService.h"
#include "nsCxPusher.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "nsRadioInterfaceLayer.h"

View File

@ -4,6 +4,7 @@
#include "base/message_loop.h"
#include "jsapi.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/Attributes.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Hal.h"
@ -20,7 +21,6 @@
#include "TimeZoneSettingObserver.h"
#include "xpcpublic.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsPrintfCString.h"
#undef LOG

View File

@ -17,7 +17,6 @@
#include "mozilla/Preferences.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsNetUtil.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"

View File

@ -6,10 +6,10 @@
#include "DateCacheCleaner.h"
#include "jsapi.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Hal.h"
#include "mozilla/StaticPtr.h"
#include "nsCxPusher.h"
using namespace mozilla::hal;

View File

@ -16,7 +16,6 @@
#include "cert.h"
#include "certdb.h"
#include "CryptoTask.h"
#include "nsCxPusher.h"
#include "nsIDOMFile.h"
#include "nsIWifiService.h"
#include "nsNetUtil.h"

View File

@ -9,7 +9,6 @@
#include "mozilla/dom/ToJSValue.h"
#include "nsXULAppAPI.h"
#include "WifiUtils.h"
#include "nsCxPusher.h"
#ifdef MOZ_TASK_TRACER
#include "GeckoTaskTracer.h"

View File

@ -15,7 +15,6 @@
#include "mozilla/dom/WifiOptionsBinding.h"
#include "mozilla/dom/network/NetUtils.h"
#include "WifiHotspotUtils.h"
#include "nsCxPusher.h"
// Needed to add a copy constructor to WifiCommandOptions.
struct CommandOptions

View File

@ -18,7 +18,6 @@
#include "mozilla/dom/PromiseNativeHandler.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsNetUtil.h"
#include "nsProxyRelease.h"
#include "nsTArray.h"

View File

@ -53,7 +53,6 @@
#include "mozilla/Preferences.h"
#include "nsAlgorithm.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsError.h"
#include "nsDOMJSUtils.h"
#include "nsHostObjectProtocolHandler.h"

View File

@ -18,7 +18,6 @@
#include "mozilla/dom/ProgressEvent.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsJSUtils.h"
#include "nsThreadUtils.h"

View File

@ -23,7 +23,6 @@
#include "nsJSPrincipals.h"
#include "nsIScriptSecurityManager.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsDOMJSUtils.h"
#include "mozilla/Services.h"
#include "xpcpublic.h"

View File

@ -9,7 +9,6 @@
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIXPConnect.h"
#include "nsIServiceManager.h"
#include "nsIDOMNode.h"

View File

@ -14,7 +14,6 @@
#include "nsXBLProtoImplMethod.h"
#include "nsJSUtils.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIScriptSecurityManager.h"
#include "nsIXPConnect.h"
#include "xpcpublic.h"

View File

@ -9,7 +9,6 @@
#include "nsIContent.h"
#include "nsXBLProtoImplProperty.h"
#include "nsUnicharUtils.h"
#include "nsCxPusher.h"
#include "nsReadableUtils.h"
#include "nsJSUtils.h"
#include "nsXBLPrototypeBinding.h"

View File

@ -9,7 +9,6 @@
#include "nsXBLPrototypeHandler.h"
#include "nsXBLPrototypeBinding.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsGlobalWindow.h"
#include "nsIContent.h"
#include "nsIAtom.h"

View File

@ -10,7 +10,6 @@
#include "nsXBLPrototypeBinding.h"
#include "nsIXPConnect.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
using namespace mozilla;

View File

@ -19,7 +19,6 @@
#include "mozilla/Attributes.h"
#include "mozilla/Maybe.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIScriptSecurityManager.h"
#include "nsJSPrincipals.h"
#include "jswrapper.h"

View File

@ -33,7 +33,6 @@
#include "nsIXPConnect.h"
#include "nsIXPCScriptable.h"
#include "nsCxPusher.h"
#include "nsJSUtils.h"
#include "nsJSPrincipals.h"
#include "nsThreadUtils.h"

View File

@ -12,7 +12,6 @@
#include "nsContentUtils.h"
#include "xpcprivate.h"
#include "jsfriendapi.h"
#include "nsCxPusher.h"
#include "AccessCheck.h"
using namespace JS;

View File

@ -12,7 +12,6 @@
#include "nsContentUtils.h"
#include "xpcprivate.h"
#include "jsfriendapi.h"
#include "nsCxPusher.h"
using namespace JS;
using namespace mozilla;

View File

@ -7,6 +7,7 @@
#ifndef mozJSComponentLoader_h
#define mozJSComponentLoader_h
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/ModuleLoader.h"
#include "nsISupports.h"
@ -14,7 +15,6 @@
#include "nsIURI.h"
#include "xpcIJSModuleLoader.h"
#include "nsClassHashtable.h"
#include "nsCxPusher.h"
#include "nsDataHashtable.h"
#include "jsapi.h"

View File

@ -14,7 +14,6 @@
#include "js/OldDebugAPI.h"
#include "js/StructuredClone.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsGlobalWindow.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectPrincipal.h"

View File

@ -29,7 +29,6 @@
#include "mozilla/Services.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsCCUncollectableMarker.h"
#include "nsCycleCollectionNoteRootCallback.h"
#include "nsScriptLoader.h"

View File

@ -9,7 +9,6 @@
#include "mozilla/Range.h"
#include "xpcprivate.h"
#include "nsCxPusher.h"
#include "jsfriendapi.h"
#include "jsprf.h"

View File

@ -9,7 +9,6 @@
#include "xpcprivate.h"
#include "jsprf.h"
#include "nsCCUncollectableMarker.h"
#include "nsCxPusher.h"
#include "nsContentUtils.h"
#include "nsThreadUtils.h"
#include "JavaScriptParent.h"

View File

@ -15,7 +15,6 @@
#include "XrayWrapper.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include <stdint.h>
#include "mozilla/Likely.h"

View File

@ -8,7 +8,6 @@
#include "xpcprivate.h"
#include "jswrapper.h"
#include "nsCxPusher.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/XPTInterfaceInfoManager.h"

View File

@ -7,7 +7,6 @@
/* Shared proto object for XPCWrappedNative. */
#include "xpcprivate.h"
#include "nsCxPusher.h"
#include "pratom.h"
using namespace mozilla;

View File

@ -6,7 +6,6 @@
EXPORTS += [
'BackstagePass.h',
'nsCxPusher.h',
'qsObjectHelper.h',
'XPCJSMemoryReporter.h',
'xpcObjectHelper.h',
@ -15,7 +14,6 @@ EXPORTS += [
UNIFIED_SOURCES += [
'ExportHelpers.cpp',
'nsCxPusher.cpp',
'nsScriptError.cpp',
'nsXPConnect.cpp',
'Sandbox.cpp',

View File

@ -1,104 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "nsCxPusher.h"
#include "nsIScriptContext.h"
#include "nsDOMJSUtils.h"
#include "xpcprivate.h"
#include "WorkerPrivate.h"
using mozilla::DebugOnly;
namespace mozilla {
AutoJSContext::AutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
: mCx(nullptr)
{
Init(false MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT);
}
AutoJSContext::AutoJSContext(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
: mCx(nullptr)
{
Init(aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT);
}
void
AutoJSContext::Init(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
{
JS::AutoSuppressGCAnalysis nogc;
MOZ_ASSERT(!mCx, "mCx should not be initialized!");
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
nsXPConnect *xpc = nsXPConnect::XPConnect();
if (!aSafe) {
mCx = xpc->GetCurrentJSContext();
}
if (!mCx) {
mCx = xpc->GetSafeJSContext();
mPusher.emplace(mCx);
}
}
AutoJSContext::operator JSContext*() const
{
return mCx;
}
ThreadsafeAutoJSContext::ThreadsafeAutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (NS_IsMainThread()) {
mCx = nullptr;
mAutoJSContext.emplace();
} else {
mCx = mozilla::dom::workers::GetCurrentThreadJSContext();
mRequest.emplace(mCx);
}
}
ThreadsafeAutoJSContext::operator JSContext*() const
{
if (mCx) {
return mCx;
} else {
return *mAutoJSContext;
}
}
AutoSafeJSContext::AutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
: AutoJSContext(true MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT)
, mAc(mCx, XPCJSRuntime::Get()->GetJSContextStack()->GetSafeJSContextGlobal())
{
}
ThreadsafeAutoSafeJSContext::ThreadsafeAutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (NS_IsMainThread()) {
mCx = nullptr;
mAutoSafeJSContext.emplace();
} else {
mCx = mozilla::dom::workers::GetCurrentThreadJSContext();
mRequest.emplace(mCx);
}
}
ThreadsafeAutoSafeJSContext::operator JSContext*() const
{
if (mCx) {
return mCx;
} else {
return *mAutoSafeJSContext;
}
}
} // namespace mozilla

View File

@ -1,86 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef nsCxPusher_h
#define nsCxPusher_h
#include "jsapi.h"
#include "mozilla/Maybe.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsCOMPtr.h"
class nsIScriptContext;
namespace mozilla {
/**
* Use AutoJSContext when you need a JS context on the stack but don't have one
* passed as a parameter. AutoJSContext will take care of finding the most
* appropriate JS context and release it when leaving the stack.
*/
class MOZ_STACK_CLASS AutoJSContext {
public:
explicit AutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
operator JSContext*() const;
protected:
explicit AutoJSContext(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
// We need this Init() method because we can't use delegating constructor for
// the moment. It is a C++11 feature and we do not require C++11 to be
// supported to be able to compile Gecko.
void Init(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
JSContext* mCx;
Maybe<mozilla::dom::danger::AutoCxPusher> mPusher;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/**
* Use ThreadsafeAutoJSContext when you want an AutoJSContext but might be
* running on a worker thread.
*/
class MOZ_STACK_CLASS ThreadsafeAutoJSContext {
public:
explicit ThreadsafeAutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
operator JSContext*() const;
private:
JSContext* mCx; // Used on workers. Null means mainthread.
Maybe<JSAutoRequest> mRequest; // Used on workers.
Maybe<AutoJSContext> mAutoJSContext; // Used on main thread.
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/**
* AutoSafeJSContext is similar to AutoJSContext but will only return the safe
* JS context. That means it will never call ::GetCurrentJSContext().
*/
class MOZ_STACK_CLASS AutoSafeJSContext : public AutoJSContext {
public:
explicit AutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
private:
JSAutoCompartment mAc;
};
/**
* Like AutoSafeJSContext but can be used safely on worker threads.
*/
class MOZ_STACK_CLASS ThreadsafeAutoSafeJSContext {
public:
explicit ThreadsafeAutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
operator JSContext*() const;
private:
JSContext* mCx; // Used on workers. Null means mainthread.
Maybe<JSAutoRequest> mRequest; // Used on workers.
Maybe<AutoSafeJSContext> mAutoSafeJSContext; // Used on main thread.
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
} // namespace mozilla
#endif /* nsCxPusher_h */

View File

@ -85,6 +85,8 @@
#include "mozilla/Preferences.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/ScriptSettings.h"
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
@ -157,7 +159,6 @@
#include "SandboxPrivate.h"
#include "BackstagePass.h"
#include "nsCxPusher.h"
#include "nsAXPCNativeCallContext.h"
#ifdef XP_WIN
@ -2833,6 +2834,14 @@ void PopJSContextNoScriptContext();
} /* namespace xpc */
namespace mozilla {
namespace dom {
namespace danger {
class AutoCxPusher;
}
}
}
class XPCJSContextStack
{
public:

View File

@ -6,7 +6,6 @@
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/net/Dashboard.h"
#include "mozilla/net/HttpInfo.h"
#include "nsCxPusher.h"
#include "nsHttp.h"
#include "nsICancelable.h"
#include "nsIDNSService.h"

View File

@ -10,9 +10,10 @@
#include "nsNetCID.h"
#include "nsIAppsService.h"
#include "nsILoadInfo.h"
#include "nsCxPusher.h"
#include "nsXULAppAPI.h"
#include "mozilla/dom/ScriptSettings.h"
/**
* This dummy channel implementation only provides enough functionality
* to return a fake 404 error when the caller asks for an app:// URL

View File

@ -9,7 +9,6 @@
#include "nsIURI.h"
#include "nsXULAppAPI.h"
#include "jsapi.h"
#include "nsCxPusher.h"
#include "nsServiceManagerUtils.h"
#include "nsLiteralString.h"
#include "nsThreadUtils.h"
@ -19,6 +18,7 @@
#include "nsIChromeRegistry.h"
#include "nsIJARURI.h"
#include "nsJSUtils.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/AddonPathService.h"
#include "mozilla/Omnijar.h"

View File

@ -6,10 +6,10 @@
/* Implementation of xptiInterfaceEntry and xptiInterfaceInfo. */
#include "xptiprivate.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/XPTInterfaceInfoManager.h"
#include "mozilla/PodOperations.h"
#include "nsCxPusher.h"
#include "jsapi.h"
using namespace mozilla;