1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/glue/nsCycleCollectionParticipant.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsCycleCollectionParticipant.h" 1.10 +#include "nsCOMPtr.h" 1.11 +#include "jsapi.h" 1.12 + 1.13 +#ifdef MOZILLA_INTERNAL_API 1.14 +#include "nsString.h" 1.15 +#else 1.16 +#include "nsStringAPI.h" 1.17 +#endif 1.18 + 1.19 +void 1.20 +nsScriptObjectTracer::NoteJSChild(void *aScriptThing, const char *name, 1.21 + void *aClosure) 1.22 +{ 1.23 + nsCycleCollectionTraversalCallback *cb = 1.24 + static_cast<nsCycleCollectionTraversalCallback*>(aClosure); 1.25 + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, name); 1.26 + cb->NoteJSChild(aScriptThing); 1.27 +} 1.28 + 1.29 +NS_IMETHODIMP_(void) 1.30 +nsXPCOMCycleCollectionParticipant::Root(void *p) 1.31 +{ 1.32 + nsISupports *s = static_cast<nsISupports*>(p); 1.33 + NS_ADDREF(s); 1.34 +} 1.35 + 1.36 +NS_IMETHODIMP_(void) 1.37 +nsXPCOMCycleCollectionParticipant::Unroot(void *p) 1.38 +{ 1.39 + nsISupports *s = static_cast<nsISupports*>(p); 1.40 + NS_RELEASE(s); 1.41 +} 1.42 + 1.43 +// We define a default trace function because some participants don't need 1.44 +// to trace anything, so it is okay for them not to define one. 1.45 +NS_IMETHODIMP_(void) 1.46 +nsXPCOMCycleCollectionParticipant::Trace(void *p, const TraceCallbacks &cb, 1.47 + void *closure) 1.48 +{ 1.49 +} 1.50 + 1.51 +bool 1.52 +nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports *s) 1.53 +{ 1.54 + nsISupports* foo; 1.55 + s->QueryInterface(NS_GET_IID(nsCycleCollectionISupports), 1.56 + reinterpret_cast<void**>(&foo)); 1.57 + return s == foo; 1.58 +} 1.59 + 1.60 +void 1.61 +CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback, 1.62 + const char* aName, 1.63 + uint32_t aFlags) 1.64 +{ 1.65 + nsAutoCString arrayEdgeName(aName); 1.66 + if (aFlags & CycleCollectionEdgeNameArrayFlag) { 1.67 + arrayEdgeName.AppendLiteral("[i]"); 1.68 + } 1.69 + aCallback.NoteNextEdgeName(arrayEdgeName.get()); 1.70 +} 1.71 + 1.72 +void 1.73 +TraceCallbackFunc::Trace(JS::Heap<JS::Value>* p, const char* name, void* closure) const 1.74 +{ 1.75 + if (p->isMarkable()) { 1.76 + mCallback(p->toGCThing(), name, closure); 1.77 + } 1.78 +} 1.79 + 1.80 +void 1.81 +TraceCallbackFunc::Trace(JS::Heap<jsid>* p, const char* name, void* closure) const 1.82 +{ 1.83 + void *thing = JSID_TO_GCTHING(*p); 1.84 + if (thing) { 1.85 + mCallback(thing, name, closure); 1.86 + } 1.87 +} 1.88 + 1.89 +void 1.90 +TraceCallbackFunc::Trace(JS::Heap<JSObject*>* p, const char* name, void* closure) const 1.91 +{ 1.92 + mCallback(*p, name, closure); 1.93 +} 1.94 + 1.95 +void 1.96 +TraceCallbackFunc::Trace(JS::TenuredHeap<JSObject*>* p, const char* name, void* closure) const 1.97 +{ 1.98 + mCallback(*p, name, closure); 1.99 +} 1.100 + 1.101 +void 1.102 +TraceCallbackFunc::Trace(JS::Heap<JSFunction*>* p, const char* name, void* closure) const 1.103 +{ 1.104 + mCallback(*p, name, closure); 1.105 +} 1.106 + 1.107 +void 1.108 +TraceCallbackFunc::Trace(JS::Heap<JSString*>* p, const char* name, void* closure) const 1.109 +{ 1.110 + mCallback(*p, name, closure); 1.111 +} 1.112 + 1.113 +void 1.114 +TraceCallbackFunc::Trace(JS::Heap<JSScript*>* p, const char* name, void* closure) const 1.115 +{ 1.116 + mCallback(p->get(), name, closure); 1.117 +}