2014-06-30 19:39:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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-01-05 01:31:26 +03:00
|
|
|
|
2007-02-18 17:38:04 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-05-27 15:50:49 +04:00
|
|
|
#include "jsapi.h"
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2012-11-15 11:32:39 +04:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
#include "nsString.h"
|
|
|
|
#else
|
|
|
|
#include "nsStringAPI.h"
|
|
|
|
#endif
|
|
|
|
|
2012-06-04 10:30:26 +04:00
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
nsScriptObjectTracer::NoteJSChild(void* aScriptThing, const char* aName,
|
|
|
|
void* aClosure)
|
2007-10-29 16:45:07 +03:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
nsCycleCollectionTraversalCallback* cb =
|
2007-10-29 16:45:07 +03:00
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, aName);
|
2012-05-03 23:28:10 +04:00
|
|
|
cb->NoteJSChild(aScriptThing);
|
2007-10-29 16:45:07 +03:00
|
|
|
}
|
|
|
|
|
2013-09-12 05:57:53 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-27 05:35:39 +04:00
|
|
|
nsXPCOMCycleCollectionParticipant::Root(void* aPtr)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
nsISupports* s = static_cast<nsISupports*>(aPtr);
|
|
|
|
NS_ADDREF(s);
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2013-09-12 05:57:53 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-27 05:35:39 +04:00
|
|
|
nsXPCOMCycleCollectionParticipant::Unroot(void* aPtr)
|
2007-03-08 14:31:14 +03:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
nsISupports* s = static_cast<nsISupports*>(aPtr);
|
|
|
|
NS_RELEASE(s);
|
2007-03-08 14:31:14 +03:00
|
|
|
}
|
|
|
|
|
2012-08-24 20:50:06 +04: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 16:45:07 +03:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-27 05:35:39 +04:00
|
|
|
nsXPCOMCycleCollectionParticipant::Trace(void* aPtr, const TraceCallbacks& aCb,
|
|
|
|
void* aClosure)
|
2007-10-29 16:45:07 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-06-27 05:35:39 +04:00
|
|
|
nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports* aSupports)
|
2007-02-18 17:38:04 +03:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
nsISupports* foo;
|
|
|
|
aSupports->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
|
|
|
|
reinterpret_cast<void**>(&foo));
|
|
|
|
return aSupports == foo;
|
2007-02-18 17:38:04 +03:00
|
|
|
}
|
2012-11-15 11:32:39 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback,
|
|
|
|
const char* aName,
|
2012-11-15 11:32:39 +04:00
|
|
|
uint32_t aFlags)
|
2012-11-15 11:32:39 +04:00
|
|
|
{
|
|
|
|
nsAutoCString arrayEdgeName(aName);
|
|
|
|
if (aFlags & CycleCollectionEdgeNameArrayFlag) {
|
|
|
|
arrayEdgeName.AppendLiteral("[i]");
|
|
|
|
}
|
|
|
|
aCallback.NoteNextEdgeName(arrayEdgeName.get());
|
|
|
|
}
|
2013-05-27 15:50:49 +04:00
|
|
|
|
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JS::Value>* aPtr, const char* aName,
|
|
|
|
void* aClosure) const
|
2013-05-27 15:50:49 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
if (aPtr->isMarkable()) {
|
|
|
|
mCallback(aPtr->toGCThing(), aName, aClosure);
|
2014-04-09 23:42:48 +04:00
|
|
|
}
|
2013-05-27 15:50:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<jsid>* aPtr, const char* aName,
|
|
|
|
void* aClosure) const
|
2013-05-27 15:50:49 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
void* thing = JSID_TO_GCTHING(*aPtr);
|
2013-05-27 15:50:49 +04:00
|
|
|
if (thing) {
|
2014-06-27 05:35:39 +04:00
|
|
|
mCallback(thing, aName, aClosure);
|
2013-05-27 15:50:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JSObject*>* aPtr, const char* aName,
|
|
|
|
void* aClosure) const
|
2013-05-27 15:50:49 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
mCallback(*aPtr, aName, aClosure);
|
2013-05-27 15:50:49 +04:00
|
|
|
}
|
|
|
|
|
2014-03-03 20:53:42 +04:00
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
TraceCallbackFunc::Trace(JS::TenuredHeap<JSObject*>* aPtr, const char* aName,
|
|
|
|
void* aClosure) const
|
2014-03-03 20:53:42 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
mCallback(*aPtr, aName, aClosure);
|
2014-03-03 20:53:42 +04:00
|
|
|
}
|
|
|
|
|
2014-01-08 04:53:17 +04:00
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JSFunction*>* aPtr, const char* aName,
|
|
|
|
void* aClosure) const
|
2014-01-08 04:53:17 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
mCallback(*aPtr, aName, aClosure);
|
2014-01-08 04:53:17 +04:00
|
|
|
}
|
|
|
|
|
2013-05-27 15:50:49 +04:00
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JSString*>* aPtr, const char* aName,
|
|
|
|
void* aClosure) const
|
2013-05-27 15:50:49 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
mCallback(*aPtr, aName, aClosure);
|
2013-05-27 15:50:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
TraceCallbackFunc::Trace(JS::Heap<JSScript*>* aPtr, const char* aName,
|
|
|
|
void* aClosure) const
|
2013-05-27 15:50:49 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
mCallback(aPtr->get(), aName, aClosure);
|
2013-05-27 15:50:49 +04:00
|
|
|
}
|