зеркало из https://github.com/mozilla/gecko-dev.git
Bug 413447, backing out to see if unit tests pass.
This commit is contained in:
Родитель
b9a1e2a23d
Коммит
d7657b85ae
|
@ -368,6 +368,12 @@ nsXBLPrototypeBinding::UnlinkJSObjects()
|
|||
{
|
||||
if (mImplementation)
|
||||
mImplementation->UnlinkJSObjects();
|
||||
|
||||
nsXBLPrototypeHandler* curr = mPrototypeHandler;
|
||||
while (curr) {
|
||||
curr->UnlinkJSObjects();
|
||||
curr = curr->GetNextHandler();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -375,6 +381,12 @@ nsXBLPrototypeBinding::Trace(TraceCallback aCallback, void *aClosure) const
|
|||
{
|
||||
if (mImplementation)
|
||||
mImplementation->Trace(aCallback, aClosure);
|
||||
|
||||
nsXBLPrototypeHandler* curr = mPrototypeHandler;
|
||||
while (curr) {
|
||||
curr->Trace(aCallback, aClosure);
|
||||
curr = curr->GetNextHandler();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -118,6 +118,7 @@ nsXBLPrototypeHandler::nsXBLPrototypeHandler(const PRUnichar* aEvent,
|
|||
PRUint32 aLineNumber)
|
||||
: mHandlerText(nsnull),
|
||||
mLineNumber(aLineNumber),
|
||||
mCachedHandler(nsnull),
|
||||
mNextHandler(nsnull),
|
||||
mPrototypeBinding(aBinding)
|
||||
{
|
||||
|
@ -134,6 +135,7 @@ nsXBLPrototypeHandler::nsXBLPrototypeHandler(const PRUnichar* aEvent,
|
|||
nsXBLPrototypeHandler::nsXBLPrototypeHandler(nsIContent* aHandlerElement)
|
||||
: mHandlerElement(nsnull),
|
||||
mLineNumber(0),
|
||||
mCachedHandler(nsnull),
|
||||
mNextHandler(nsnull),
|
||||
mPrototypeBinding(nsnull)
|
||||
{
|
||||
|
@ -159,6 +161,19 @@ nsXBLPrototypeHandler::~nsXBLPrototypeHandler()
|
|||
delete mNextHandler;
|
||||
}
|
||||
|
||||
void
|
||||
nsXBLPrototypeHandler::Trace(TraceCallback aCallback, void *aClosure) const
|
||||
{
|
||||
if (mCachedHandler)
|
||||
aCallback(nsIProgrammingLanguage::JAVASCRIPT, mCachedHandler, aClosure);
|
||||
}
|
||||
|
||||
void
|
||||
nsXBLPrototypeHandler::UnlinkJSObjects()
|
||||
{
|
||||
ForgetCachedHandler();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIContent>
|
||||
nsXBLPrototypeHandler::GetHandlerElement()
|
||||
{
|
||||
|
@ -181,9 +196,11 @@ nsXBLPrototypeHandler::AppendHandlerText(const nsAString& aText)
|
|||
mHandlerText = ToNewUnicode(nsDependentString(temp) + aText);
|
||||
nsMemory::Free(temp);
|
||||
}
|
||||
else {
|
||||
else
|
||||
mHandlerText = ToNewUnicode(aText);
|
||||
}
|
||||
|
||||
// Remove our cached handler
|
||||
ForgetCachedHandler();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -352,12 +369,15 @@ nsXBLPrototypeHandler::EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
|
|||
nsScriptObjectHolder &aHandler)
|
||||
{
|
||||
// Check to see if we've already compiled this
|
||||
nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(aGlobal);
|
||||
if (pWindow) {
|
||||
void* cachedHandler = pWindow->GetCachedXBLPrototypeHandler(this);
|
||||
if (cachedHandler) {
|
||||
aHandler.set(cachedHandler);
|
||||
return aHandler ? NS_OK : NS_ERROR_FAILURE;
|
||||
if (mCachedHandler) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> cachedGlobal =
|
||||
do_QueryReferent(mGlobalForCachedHandler);
|
||||
if (cachedGlobal == aGlobal) {
|
||||
aHandler.set(mCachedHandler);
|
||||
if (!aHandler)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -378,9 +398,8 @@ nsXBLPrototypeHandler::EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
|
|||
mLineNumber, aHandler);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (pWindow) {
|
||||
pWindow->CacheXBLPrototypeHandler(this, aHandler);
|
||||
}
|
||||
mCachedHandler = aHandler;
|
||||
mGlobalForCachedHandler = do_GetWeakReference(aGlobal);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -852,6 +871,7 @@ nsXBLPrototypeHandler::ConstructPrototype(nsIContent* aKeyElement,
|
|||
mMisc = 0;
|
||||
mKeyMask = 0;
|
||||
mPhase = NS_PHASE_BUBBLING;
|
||||
ForgetCachedHandler();
|
||||
|
||||
if (aAction)
|
||||
mHandlerText = ToNewUnicode(nsDependentString(aAction));
|
||||
|
|
|
@ -153,6 +153,9 @@ public:
|
|||
return (mType & NS_HANDLER_ALLOW_UNTRUSTED) != 0;
|
||||
}
|
||||
|
||||
void Trace(TraceCallback aCallback, void *aClosure) const;
|
||||
void UnlinkJSObjects();
|
||||
|
||||
public:
|
||||
static PRUint32 gRefCnt;
|
||||
|
||||
|
@ -177,6 +180,11 @@ protected:
|
|||
nsresult EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
|
||||
nsIScriptContext *aBoundContext, nsIAtom *aName,
|
||||
nsScriptObjectHolder &aHandler);
|
||||
void ForgetCachedHandler()
|
||||
{
|
||||
mCachedHandler = nsnull;
|
||||
mGlobalForCachedHandler = nsnull;
|
||||
}
|
||||
static PRInt32 KeyToMask(PRInt32 key);
|
||||
|
||||
static PRInt32 kAccelKey;
|
||||
|
@ -222,6 +230,10 @@ protected:
|
|||
PRInt32 mDetail; // For key events, contains a charcode or keycode. For
|
||||
// mouse events, stores the button info.
|
||||
|
||||
// cache a handler to avoid compiling each time
|
||||
void *mCachedHandler;
|
||||
nsWeakPtr mGlobalForCachedHandler;
|
||||
|
||||
// Prototype handlers are chained. We own the next handler in the chain.
|
||||
nsXBLPrototypeHandler* mNextHandler;
|
||||
nsCOMPtr<nsIAtom> mEventName; // The type of the event, e.g., "keypress"
|
||||
|
|
|
@ -70,8 +70,6 @@ class nsIDocument;
|
|||
class nsIScriptTimeoutHandler;
|
||||
class nsPresContext;
|
||||
struct nsTimeout;
|
||||
class nsScriptObjectHolder;
|
||||
class nsXBLPrototypeHandler;
|
||||
|
||||
#define NS_PIDOMWINDOW_IID \
|
||||
{ 0x909852b5, 0xb9e6, 0x4d94, \
|
||||
|
@ -381,10 +379,6 @@ public:
|
|||
*/
|
||||
virtual void InitJavaProperties() = 0;
|
||||
|
||||
virtual void* GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey) = 0;
|
||||
virtual void CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey,
|
||||
nsScriptObjectHolder& aHandler) = 0;
|
||||
|
||||
protected:
|
||||
// The nsPIDOMWindow constructor. The aOuterWindow argument should
|
||||
// be null if and only if the created window itself is an outer
|
||||
|
|
|
@ -580,6 +580,7 @@ nsTimeout::~nsTimeout()
|
|||
MOZ_COUNT_DTOR(nsTimeout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//*** nsGlobalWindow: Object Management
|
||||
|
@ -752,23 +753,6 @@ nsGlobalWindow::ShutDown()
|
|||
NS_IF_RELEASE(sComputedDOMStyleFactory);
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
nsGlobalWindow::CleanupCachedXBLHandlers(nsGlobalWindow* aWindow)
|
||||
{
|
||||
if (aWindow->mCachedXBLPrototypeHandlers.IsInitialized() &&
|
||||
aWindow->mCachedXBLPrototypeHandlers.Count() > 0) {
|
||||
aWindow->mCachedXBLPrototypeHandlers.Clear();
|
||||
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
aWindow->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
|
||||
getter_AddRefs(supports));
|
||||
NS_ASSERTION(supports, "Failed to QI to nsCycleCollectionISupports?!");
|
||||
|
||||
nsContentUtils::DropJSObjects(supports);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::CleanUp()
|
||||
{
|
||||
|
@ -814,8 +798,6 @@ nsGlobalWindow::CleanUp()
|
|||
mArguments = nsnull;
|
||||
mArgumentsLast = nsnull;
|
||||
|
||||
CleanupCachedXBLHandlers(this);
|
||||
|
||||
#ifdef DEBUG
|
||||
nsCycleCollector_DEBUG_shouldBeFreed(static_cast<nsIScriptGlobalObject*>(this));
|
||||
#endif
|
||||
|
@ -900,8 +882,6 @@ nsGlobalWindow::FreeInnerObjects(PRBool aClearScope)
|
|||
}
|
||||
#endif
|
||||
|
||||
CleanupCachedXBLHandlers(this);
|
||||
|
||||
#ifdef DEBUG
|
||||
nsCycleCollector_DEBUG_shouldBeFreed(static_cast<nsIScriptGlobalObject*>(this));
|
||||
#endif
|
||||
|
@ -1008,33 +988,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
struct TraceData
|
||||
{
|
||||
TraceData(TraceCallback& aCallback, void* aClosure) :
|
||||
callback(aCallback), closure(aClosure) {}
|
||||
|
||||
TraceCallback& callback;
|
||||
void* closure;
|
||||
};
|
||||
|
||||
PR_STATIC_CALLBACK(PLDHashOperator)
|
||||
TraceXBLHandlers(const void* aKey, void* aData, void* aClosure)
|
||||
{
|
||||
TraceData* data = static_cast<TraceData*>(aClosure);
|
||||
data->callback(nsIProgrammingLanguage::JAVASCRIPT, aData, data->closure);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsGlobalWindow)
|
||||
if (tmp->mCachedXBLPrototypeHandlers.IsInitialized()) {
|
||||
TraceData data(aCallback, aClosure);
|
||||
tmp->mCachedXBLPrototypeHandlers.EnumerateRead(TraceXBLHandlers, &data);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(nsGlobalWindow)
|
||||
nsGlobalWindow::CleanupCachedXBLHandlers(tmp);
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_END
|
||||
|
||||
//*****************************************************************************
|
||||
// nsGlobalWindow::nsIScriptGlobalObject
|
||||
|
@ -5583,49 +5536,6 @@ nsGlobalWindow::InitJavaProperties()
|
|||
#endif
|
||||
}
|
||||
|
||||
void*
|
||||
nsGlobalWindow::GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey)
|
||||
{
|
||||
void* handler = nsnull;
|
||||
if (mCachedXBLPrototypeHandlers.IsInitialized()) {
|
||||
mCachedXBLPrototypeHandlers.Get(aKey, &handler);
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey,
|
||||
nsScriptObjectHolder& aHandler)
|
||||
{
|
||||
if (!mCachedXBLPrototypeHandlers.IsInitialized() &&
|
||||
!mCachedXBLPrototypeHandlers.Init()) {
|
||||
NS_ERROR("Failed to initiailize hashtable!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mCachedXBLPrototypeHandlers.Count()) {
|
||||
// Can't use macros to get the participant because nsGlobalChromeWindow also
|
||||
// runs through this code. Use QueryInterface to get the correct objects.
|
||||
nsXPCOMCycleCollectionParticipant* participant;
|
||||
CallQueryInterface(this, &participant);
|
||||
NS_ASSERTION(participant,
|
||||
"Failed to QI to nsXPCOMCycleCollectionParticipant!");
|
||||
|
||||
nsCOMPtr<nsISupports> thisSupports;
|
||||
QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
|
||||
getter_AddRefs(thisSupports));
|
||||
NS_ASSERTION(thisSupports, "Failed to QI to nsCycleCollectionISupports!");
|
||||
|
||||
nsresult rv = nsContentUtils::HoldJSObjects(thisSupports, participant);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsContentUtils::HoldJSObjects failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mCachedXBLPrototypeHandlers.Put(aKey, aHandler);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalWindow::GetFrameElement(nsIDOMElement** aFrameElement)
|
||||
{
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include "nsHashtable.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsDOMScriptObjectHolder.h"
|
||||
|
||||
// Interfaces Needed
|
||||
#include "nsDOMWindowList.h"
|
||||
|
@ -411,7 +410,6 @@ public:
|
|||
const PRUnichar* aData);
|
||||
|
||||
static void ShutDown();
|
||||
static void CleanupCachedXBLHandlers(nsGlobalWindow* aWindow);
|
||||
static PRBool IsCallerChrome();
|
||||
static void CloseBlockScriptTerminationFunc(nsISupports *aRef);
|
||||
|
||||
|
@ -420,19 +418,11 @@ public:
|
|||
|
||||
friend class WindowStateHolder;
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsGlobalWindow,
|
||||
nsIScriptGlobalObject)
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGlobalWindow,
|
||||
nsIScriptGlobalObject)
|
||||
|
||||
void InitJavaProperties();
|
||||
|
||||
virtual NS_HIDDEN_(void*)
|
||||
GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey);
|
||||
|
||||
virtual NS_HIDDEN_(void)
|
||||
CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey,
|
||||
nsScriptObjectHolder& aHandler);
|
||||
|
||||
|
||||
protected:
|
||||
// Object Management
|
||||
virtual ~nsGlobalWindow();
|
||||
|
@ -732,8 +722,6 @@ protected:
|
|||
|
||||
nsCOMPtr<nsIDOMOfflineResourceList> mApplicationCache;
|
||||
|
||||
nsDataHashtable<nsVoidPtrHashKey, void*> mCachedXBLPrototypeHandlers;
|
||||
|
||||
friend class nsDOMScriptableHelper;
|
||||
friend class nsDOMWindowUtils;
|
||||
static nsIFactory *sComputedDOMStyleFactory;
|
||||
|
|
Загрузка…
Ссылка в новой задаче