Bug 1078744 - Replace SetIsDOMBinding with SetIsNonDOMBinding, invert the flag for dom bindings in nsWrapperCache and add SetIsNotDOMBinding. r=bz.

--HG--
extra : rebase_source : 6ca1903658d3d6fe2634409cd39fa68c6b1219bd
This commit is contained in:
Peter Van der Beken 2014-10-07 11:44:48 +02:00
Родитель a0f306343e
Коммит 962c9a5742
7 изменённых файлов: 38 добавлений и 25 удалений

Просмотреть файл

@ -103,6 +103,7 @@ nsInProcessTabChildGlobal::nsInProcessTabChildGlobal(nsIDocShell* aShell,
: mDocShell(aShell), mInitialized(false), mLoadingScript(false),
mOwner(aOwner), mChromeMessageManager(aChrome)
{
SetIsNotDOMBinding();
mozilla::HoldJSObjects(this);
// If owner corresponds to an <iframe mozbrowser> or <iframe mozapp>, we'll

Просмотреть файл

@ -1721,8 +1721,7 @@ Navigator::GetConnection(ErrorResult& aRv)
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
mConnection = new network::Connection();
mConnection->Init(mWindow);
mConnection = new network::Connection(mWindow);
}
return mConnection;

Просмотреть файл

@ -33,6 +33,7 @@ using namespace mozilla::dom;
nsWindowRoot::nsWindowRoot(nsPIDOMWindow* aWindow)
{
mWindow = aWindow;
SetIsNotDOMBinding();
}
nsWindowRoot::~nsWindowRoot()

Просмотреть файл

@ -14,6 +14,14 @@
#include "js/RootingAPI.h"
#include "js/TracingAPI.h"
namespace mozilla {
namespace dom {
class TabChildGlobal;
} // namespace dom
} // namespace mozilla
class SandboxPrivate;
class nsInProcessTabChildGlobal;
class nsWindowRoot;
class XPCWrappedNativeScope;
#define NS_WRAPPERCACHE_IID \
@ -37,10 +45,10 @@ class XPCWrappedNativeScope;
*
* The cache can store 2 types of objects:
*
* If WRAPPER_IS_DOM_BINDING is not set (IsDOMBinding() returns false):
* - a slim wrapper or the JSObject of an XPCWrappedNative wrapper
* If WRAPPER_IS_NOT_DOM_BINDING is set (IsDOMBinding() returns false):
* - the JSObject of an XPCWrappedNative wrapper
*
* If WRAPPER_IS_DOM_BINDING is set (IsDOMBinding() returns true):
* If WRAPPER_IS_NOT_DOM_BINDING is not set (IsDOMBinding() returns true):
* - a DOM binding object (regular JS object or proxy)
*
* The finalizer for the wrapper clears the cache.
@ -136,14 +144,14 @@ public:
void SetIsDOMBinding()
{
MOZ_ASSERT(!mWrapper && !(GetWrapperFlags() & ~WRAPPER_IS_DOM_BINDING),
MOZ_ASSERT(!mWrapper && !(GetWrapperFlags() & ~WRAPPER_IS_NOT_DOM_BINDING),
"This flag should be set before creating any wrappers.");
SetWrapperFlags(WRAPPER_IS_DOM_BINDING);
UnsetWrapperFlags(WRAPPER_IS_NOT_DOM_BINDING);
}
bool IsDOMBinding() const
{
return HasWrapperFlag(WRAPPER_IS_DOM_BINDING);
return !HasWrapperFlag(WRAPPER_IS_NOT_DOM_BINDING);
}
/**
@ -261,6 +269,17 @@ protected:
}
private:
friend class mozilla::dom::TabChildGlobal;
friend class SandboxPrivate;
friend class nsInProcessTabChildGlobal;
friend class nsWindowRoot;
void SetIsNotDOMBinding()
{
MOZ_ASSERT(!mWrapper && !(GetWrapperFlags() & ~WRAPPER_IS_NOT_DOM_BINDING),
"This flag should be set before creating any wrappers.");
SetWrapperFlags(WRAPPER_IS_NOT_DOM_BINDING);
}
JSObject *GetWrapperJSObject() const
{
return mWrapper;
@ -269,7 +288,7 @@ private:
void SetWrapperJSObject(JSObject* aWrapper)
{
mWrapper = aWrapper;
UnsetWrapperFlags(kWrapperFlagsMask & ~WRAPPER_IS_DOM_BINDING);
UnsetWrapperFlags(kWrapperFlagsMask & ~WRAPPER_IS_NOT_DOM_BINDING);
}
void TraceWrapperJSObject(JSTracer* aTrc, const char* aName);
@ -319,12 +338,12 @@ private:
enum { WRAPPER_BIT_PRESERVED = 1 << 0 };
/**
* If this bit is set then the wrapper for the native object is a DOM binding
* (regular JS object or proxy).
* If this bit is set then the wrapper for the native object is not a DOM
* binding.
*/
enum { WRAPPER_IS_DOM_BINDING = 1 << 1 };
enum { WRAPPER_IS_NOT_DOM_BINDING = 1 << 1 };
enum { kWrapperFlagsMask = (WRAPPER_BIT_PRESERVED | WRAPPER_IS_DOM_BINDING) };
enum { kWrapperFlagsMask = (WRAPPER_BIT_PRESERVED | WRAPPER_IS_NOT_DOM_BINDING) };
JS::Heap<JSObject*> mWrapper;
FlagsType mFlags;

Просмотреть файл

@ -28,19 +28,12 @@ NS_IMPL_QUERY_INTERFACE_INHERITED(Connection, DOMEventTargetHelper,
NS_IMPL_ADDREF_INHERITED(dom::network::Connection, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(dom::network::Connection, DOMEventTargetHelper)
Connection::Connection()
: mType(static_cast<ConnectionType>(kDefaultType))
Connection::Connection(nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow)
, mType(static_cast<ConnectionType>(kDefaultType))
, mIsWifi(kDefaultIsWifi)
, mDHCPGateway(kDefaultDHCPGateway)
{
SetIsDOMBinding();
}
void
Connection::Init(nsPIDOMWindow* aWindow)
{
BindToOwner(aWindow);
hal::RegisterNetworkObserver(this);
hal::NetworkInformation networkInfo;

Просмотреть файл

@ -32,9 +32,8 @@ public:
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
Connection();
Connection(nsPIDOMWindow *aWindow);
void Init(nsPIDOMWindow *aWindow);
void Shutdown();
// For IObserver

Просмотреть файл

@ -27,6 +27,7 @@ public:
SandboxPrivate(nsIPrincipal *principal, JSObject *global)
: mPrincipal(principal)
{
SetIsNotDOMBinding();
SetWrapper(global);
}