2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-05-27 04:50:49 -07:00
|
|
|
#include "jsapi.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-14 23:32:39 -08:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
#include "nsString.h"
|
|
|
|
#else
|
|
|
|
#include "nsStringAPI.h"
|
|
|
|
#endif
|
|
|
|
|
2012-06-03 23:30:26 -07:00
|
|
|
void
|
|
|
|
nsScriptObjectTracer::NoteJSChild(void *aScriptThing, const char *name,
|
|
|
|
void *aClosure)
|
2007-10-29 06:45:07 -07:00
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback *cb =
|
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
|
2011-02-02 07:30:03 -08:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, name);
|
2012-05-03 12:28:10 -07:00
|
|
|
cb->NoteJSChild(aScriptThing);
|
2007-10-29 06:45:07 -07:00
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPCOMCycleCollectionParticipant::Root(void *p)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsISupports *s = static_cast<nsISupports*>(p);
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_ADDREF(s);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPCOMCycleCollectionParticipant::Unroot(void *p)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsISupports *s = static_cast<nsISupports*>(p);
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_RELEASE(s);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-24 09:50:06 -07:00
|
|
|
// We define a default trace function because some participants don't need
|
|
|
|
// to trace anything, so it is okay for them not to define one.
|
2007-10-29 06:45:07 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2013-08-01 18:29:05 -07:00
|
|
|
nsXPCOMCycleCollectionParticipant::Trace(void *p, const TraceCallbacks &cb,
|
|
|
|
void *closure)
|
2007-10-29 06:45:07 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-05-24 07:10:02 -07:00
|
|
|
nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports *s)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-11-11 14:52:30 -08:00
|
|
|
nsISupports* foo;
|
2007-03-22 10:30:00 -07:00
|
|
|
s->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
|
2010-11-11 14:52:30 -08:00
|
|
|
reinterpret_cast<void**>(&foo));
|
2007-03-22 10:30:00 -07:00
|
|
|
return s == foo;
|
|
|
|
}
|
2012-11-14 23:32:39 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback,
|
|
|
|
const char* aName,
|
2012-11-14 23:32:39 -08:00
|
|
|
uint32_t aFlags)
|
2012-11-14 23:32:39 -08:00
|
|
|
{
|
|
|
|
nsAutoCString arrayEdgeName(aName);
|
|
|
|
if (aFlags & CycleCollectionEdgeNameArrayFlag) {
|
|
|
|
arrayEdgeName.AppendLiteral("[i]");
|
|
|
|
}
|
|
|
|
aCallback.NoteNextEdgeName(arrayEdgeName.get());
|
|
|
|
}
|
2013-05-27 04:50:49 -07:00
|
|
|
|
|
|
|
void
|
2013-06-18 03:00:37 -07:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JS::Value>* p, const char* name, void* closure) const
|
2013-05-27 04:50:49 -07:00
|
|
|
{
|
2013-06-18 03:00:37 -07:00
|
|
|
mCallback(JSVAL_TO_TRACEABLE(p->get()), name, closure);
|
2013-05-27 04:50:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-18 03:00:38 -07:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<jsid>* p, const char* name, void* closure) const
|
2013-05-27 04:50:49 -07:00
|
|
|
{
|
|
|
|
void *thing = JSID_TO_GCTHING(*p);
|
|
|
|
if (thing) {
|
|
|
|
mCallback(thing, name, closure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-18 03:00:38 -07:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JSObject*>* p, const char* name, void* closure) const
|
2013-05-27 04:50:49 -07:00
|
|
|
{
|
|
|
|
mCallback(*p, name, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-18 03:00:38 -07:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JSString*>* p, const char* name, void* closure) const
|
2013-05-27 04:50:49 -07:00
|
|
|
{
|
|
|
|
mCallback(*p, name, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-18 03:00:37 -07:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JSScript*>* p, const char* name, void* closure) const
|
2013-05-27 04:50:49 -07:00
|
|
|
{
|
2013-06-18 03:00:37 -07:00
|
|
|
mCallback(p->get(), name, closure);
|
2013-05-27 04:50:49 -07:00
|
|
|
}
|