Bug 884268 - Part a: Move nsContentUtils::CheckCCWrapperTraversal to nsWrapperCache; r=smaug

This commit is contained in:
Ms2ger 2013-06-23 09:15:10 +02:00
parent 1fd9d74232
commit 4842331722
5 changed files with 96 additions and 83 deletions

View File

@ -1261,10 +1261,6 @@ public:
#ifdef DEBUG
static bool AreJSObjectsHeld(void* aScriptObjectHolder);
static void CheckCCWrapperTraversal(void* aScriptObjectHolder,
nsWrapperCache* aCache,
nsScriptObjectTracer* aTracer);
#endif
static void PreserveWrapper(nsISupports* aScriptObjectHolder,
@ -1289,7 +1285,7 @@ public:
aCache->SetPreservingWrapper(true);
#ifdef DEBUG
// Make sure the cycle collector will be able to traverse to the wrapper.
CheckCCWrapperTraversal(aScriptObjectHolder, aCache, aTracer);
aCache->CheckCCWrapperTraversal(aScriptObjectHolder, aTracer);
#endif
}
}

View File

@ -5773,83 +5773,6 @@ nsContentUtils::AllocClassMatchingInfo(nsINode* aRootNode,
return info;
}
#ifdef DEBUG
class DebugWrapperTraversalCallback : public nsCycleCollectionTraversalCallback
{
public:
DebugWrapperTraversalCallback(void* aWrapper) : mFound(false),
mWrapper(aWrapper)
{
mFlags = WANT_ALL_TRACES;
}
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refCount,
const char *objName)
{
}
NS_IMETHOD_(void) DescribeGCedNode(bool isMarked,
const char *objName)
{
}
NS_IMETHOD_(void) NoteJSChild(void* child)
{
if (child == mWrapper) {
mFound = true;
}
}
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child)
{
}
NS_IMETHOD_(void) NoteNativeChild(void* child,
nsCycleCollectionParticipant* helper)
{
}
NS_IMETHOD_(void) NoteNextEdgeName(const char* name)
{
}
bool mFound;
private:
void* mWrapper;
};
static void
DebugWrapperTraceCallback(void *p, const char *name, void *closure)
{
DebugWrapperTraversalCallback* callback =
static_cast<DebugWrapperTraversalCallback*>(closure);
callback->NoteJSChild(p);
}
// static
void
nsContentUtils::CheckCCWrapperTraversal(void* aScriptObjectHolder,
nsWrapperCache* aCache,
nsScriptObjectTracer* aTracer)
{
JSObject* wrapper = aCache->GetWrapper();
if (!wrapper) {
return;
}
DebugWrapperTraversalCallback callback(wrapper);
aTracer->Traverse(aScriptObjectHolder, callback);
MOZ_ASSERT(callback.mFound,
"Cycle collection participant didn't traverse to preserved "
"wrapper! This will probably crash.");
callback.mFound = false;
aTracer->Trace(aScriptObjectHolder, TraceCallbackFunc(DebugWrapperTraceCallback), &callback);
MOZ_ASSERT(callback.mFound,
"Cycle collection participant didn't trace preserved wrapper! "
"This will probably crash.");
}
#endif
// static
bool
nsContentUtils::IsFocusedContent(const nsIContent* aContent)

View File

@ -94,7 +94,8 @@ CPP_SOURCES += [
'nsScriptNameSpaceManager.cpp',
'nsStructuredCloneContainer.cpp',
'nsWindowMemoryReporter.cpp',
'nsWindowRoot.cpp'
'nsWindowRoot.cpp',
'nsWrapperCache.cpp',
]
EXTRA_COMPONENTS += [

View File

@ -0,0 +1,88 @@
/* -*- 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 "nsWrapperCacheInlines.h"
#include "nsCycleCollectionTraversalCallback.h"
#ifdef DEBUG
class DebugWrapperTraversalCallback : public nsCycleCollectionTraversalCallback
{
public:
DebugWrapperTraversalCallback(void* aWrapper)
: mFound(false)
, mWrapper(aWrapper)
{
mFlags = WANT_ALL_TRACES;
}
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt aRefCount,
const char* aObjName)
{
}
NS_IMETHOD_(void) DescribeGCedNode(bool aIsMarked,
const char* aObjName)
{
}
NS_IMETHOD_(void) NoteJSChild(void* aChild)
{
if (aChild == mWrapper) {
mFound = true;
}
}
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild)
{
}
NS_IMETHOD_(void) NoteNativeChild(void* aChild,
nsCycleCollectionParticipant* aHelper)
{
}
NS_IMETHOD_(void) NoteNextEdgeName(const char* aName)
{
}
bool mFound;
private:
void* mWrapper;
};
static void
DebugWrapperTraceCallback(void* aP, const char* aName, void* aClosure)
{
DebugWrapperTraversalCallback* callback =
static_cast<DebugWrapperTraversalCallback*>(aClosure);
callback->NoteJSChild(aP);
}
void
nsWrapperCache::CheckCCWrapperTraversal(void* aScriptObjectHolder,
nsScriptObjectTracer* aTracer)
{
JSObject* wrapper = GetWrapper();
if (!wrapper) {
return;
}
DebugWrapperTraversalCallback callback(wrapper);
aTracer->Traverse(aScriptObjectHolder, callback);
MOZ_ASSERT(callback.mFound,
"Cycle collection participant didn't traverse to preserved "
"wrapper! This will probably crash.");
callback.mFound = false;
aTracer->Trace(aScriptObjectHolder,
TraceCallbackFunc(DebugWrapperTraceCallback), &callback);
MOZ_ASSERT(callback.mFound,
"Cycle collection participant didn't trace preserved wrapper! "
"This will probably crash.");
}
#endif // DEBUG

View File

@ -214,6 +214,11 @@ public:
mFlags &= ~aFlagsToUnset;
}
#ifdef DEBUG
void CheckCCWrapperTraversal(void* aScriptObjectHolder,
nsScriptObjectTracer* aTracer);
#endif // DEBUG
private:
JSObject *GetWrapperJSObject() const
{