michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "jsapi.h" michael@0: michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: #include "nsString.h" michael@0: #else michael@0: #include "nsStringAPI.h" michael@0: #endif michael@0: michael@0: void michael@0: nsScriptObjectTracer::NoteJSChild(void *aScriptThing, const char *name, michael@0: void *aClosure) michael@0: { michael@0: nsCycleCollectionTraversalCallback *cb = michael@0: static_cast(aClosure); michael@0: NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, name); michael@0: cb->NoteJSChild(aScriptThing); michael@0: } michael@0: michael@0: NS_IMETHODIMP_(void) michael@0: nsXPCOMCycleCollectionParticipant::Root(void *p) michael@0: { michael@0: nsISupports *s = static_cast(p); michael@0: NS_ADDREF(s); michael@0: } michael@0: michael@0: NS_IMETHODIMP_(void) michael@0: nsXPCOMCycleCollectionParticipant::Unroot(void *p) michael@0: { michael@0: nsISupports *s = static_cast(p); michael@0: NS_RELEASE(s); michael@0: } michael@0: michael@0: // We define a default trace function because some participants don't need michael@0: // to trace anything, so it is okay for them not to define one. michael@0: NS_IMETHODIMP_(void) michael@0: nsXPCOMCycleCollectionParticipant::Trace(void *p, const TraceCallbacks &cb, michael@0: void *closure) michael@0: { michael@0: } michael@0: michael@0: bool michael@0: nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports *s) michael@0: { michael@0: nsISupports* foo; michael@0: s->QueryInterface(NS_GET_IID(nsCycleCollectionISupports), michael@0: reinterpret_cast(&foo)); michael@0: return s == foo; michael@0: } michael@0: michael@0: void michael@0: CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback, michael@0: const char* aName, michael@0: uint32_t aFlags) michael@0: { michael@0: nsAutoCString arrayEdgeName(aName); michael@0: if (aFlags & CycleCollectionEdgeNameArrayFlag) { michael@0: arrayEdgeName.AppendLiteral("[i]"); michael@0: } michael@0: aCallback.NoteNextEdgeName(arrayEdgeName.get()); michael@0: } michael@0: michael@0: void michael@0: TraceCallbackFunc::Trace(JS::Heap* p, const char* name, void* closure) const michael@0: { michael@0: if (p->isMarkable()) { michael@0: mCallback(p->toGCThing(), name, closure); michael@0: } michael@0: } michael@0: michael@0: void michael@0: TraceCallbackFunc::Trace(JS::Heap* p, const char* name, void* closure) const michael@0: { michael@0: void *thing = JSID_TO_GCTHING(*p); michael@0: if (thing) { michael@0: mCallback(thing, name, closure); michael@0: } michael@0: } michael@0: michael@0: void michael@0: TraceCallbackFunc::Trace(JS::Heap* p, const char* name, void* closure) const michael@0: { michael@0: mCallback(*p, name, closure); michael@0: } michael@0: michael@0: void michael@0: TraceCallbackFunc::Trace(JS::TenuredHeap* p, const char* name, void* closure) const michael@0: { michael@0: mCallback(*p, name, closure); michael@0: } michael@0: michael@0: void michael@0: TraceCallbackFunc::Trace(JS::Heap* p, const char* name, void* closure) const michael@0: { michael@0: mCallback(*p, name, closure); michael@0: } michael@0: michael@0: void michael@0: TraceCallbackFunc::Trace(JS::Heap* p, const char* name, void* closure) const michael@0: { michael@0: mCallback(*p, name, closure); michael@0: } michael@0: michael@0: void michael@0: TraceCallbackFunc::Trace(JS::Heap* p, const char* name, void* closure) const michael@0: { michael@0: mCallback(p->get(), name, closure); michael@0: }