From 4842331722307793ecc91f22233bec30961e1716 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 23 Jun 2013 09:15:10 +0200 Subject: [PATCH] Bug 884268 - Part a: Move nsContentUtils::CheckCCWrapperTraversal to nsWrapperCache; r=smaug --- content/base/public/nsContentUtils.h | 6 +- content/base/src/nsContentUtils.cpp | 77 ------------------------ dom/base/moz.build | 3 +- dom/base/nsWrapperCache.cpp | 88 ++++++++++++++++++++++++++++ dom/base/nsWrapperCache.h | 5 ++ 5 files changed, 96 insertions(+), 83 deletions(-) create mode 100644 dom/base/nsWrapperCache.cpp diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 2bf54e8b46f0..19c4fa2f66eb 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -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 } } diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index c7c8f47c2726..df0251c0aefe 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -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(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) diff --git a/dom/base/moz.build b/dom/base/moz.build index f8457653aee3..7d8fb890b100 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -94,7 +94,8 @@ CPP_SOURCES += [ 'nsScriptNameSpaceManager.cpp', 'nsStructuredCloneContainer.cpp', 'nsWindowMemoryReporter.cpp', - 'nsWindowRoot.cpp' + 'nsWindowRoot.cpp', + 'nsWrapperCache.cpp', ] EXTRA_COMPONENTS += [ diff --git a/dom/base/nsWrapperCache.cpp b/dom/base/nsWrapperCache.cpp new file mode 100644 index 000000000000..094e75904365 --- /dev/null +++ b/dom/base/nsWrapperCache.cpp @@ -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(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 diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 44d3c054afcd..4f3b540618c8 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -214,6 +214,11 @@ public: mFlags &= ~aFlagsToUnset; } +#ifdef DEBUG + void CheckCCWrapperTraversal(void* aScriptObjectHolder, + nsScriptObjectTracer* aTracer); +#endif // DEBUG + private: JSObject *GetWrapperJSObject() const {