2012-01-24 02:03:37 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=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 "IDBWrapperCache.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-08-16 13:10:17 -07:00
|
|
|
#include "nsCycleCollector.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#endif
|
2012-01-24 02:03:37 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
2012-01-24 02:03:37 -08:00
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBWrapperCache)
|
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBWrapperCache,
|
2014-03-31 23:13:50 -07:00
|
|
|
DOMEventTargetHelper)
|
2012-01-24 02:03:37 -08:00
|
|
|
// Don't need NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS because
|
2014-03-31 23:13:50 -07:00
|
|
|
// DOMEventTargetHelper does it for us.
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBWrapperCache,
|
2014-03-31 23:13:50 -07:00
|
|
|
DOMEventTargetHelper)
|
2012-02-27 08:52:19 -08:00
|
|
|
if (tmp->mScriptOwner) {
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mScriptOwner = nullptr;
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::DropJSObjects(tmp);
|
2012-02-27 08:52:19 -08:00
|
|
|
}
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(IDBWrapperCache,
|
2014-03-31 23:13:50 -07:00
|
|
|
DOMEventTargetHelper)
|
2012-01-24 02:03:37 -08:00
|
|
|
// Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
|
2014-03-31 23:13:50 -07:00
|
|
|
// DOMEventTargetHelper does it for us.
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScriptOwner)
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBWrapperCache)
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2012-01-24 02:03:37 -08:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBWrapperCache, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBWrapperCache, DOMEventTargetHelper)
|
2012-02-27 08:52:19 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBWrapperCache::IDBWrapperCache(DOMEventTargetHelper* aOwner)
|
|
|
|
: DOMEventTargetHelper(aOwner), mScriptOwner(nullptr)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
IDBWrapperCache::IDBWrapperCache(nsPIDOMWindow* aOwner)
|
|
|
|
: DOMEventTargetHelper(aOwner), mScriptOwner(nullptr)
|
|
|
|
{ }
|
|
|
|
|
2012-02-27 08:52:19 -08:00
|
|
|
IDBWrapperCache::~IDBWrapperCache()
|
|
|
|
{
|
2012-11-27 17:37:57 -08:00
|
|
|
mScriptOwner = nullptr;
|
2013-08-02 00:04:01 -07:00
|
|
|
ReleaseWrapper(this);
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::DropJSObjects(this);
|
2012-02-27 08:52:19 -08:00
|
|
|
}
|
|
|
|
|
2012-11-29 14:54:14 -08:00
|
|
|
void
|
2012-02-27 08:52:19 -08:00
|
|
|
IDBWrapperCache::SetScriptOwner(JSObject* aScriptOwner)
|
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(aScriptOwner);
|
2012-02-27 08:52:19 -08:00
|
|
|
|
|
|
|
mScriptOwner = aScriptOwner;
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::HoldJSObjects(this);
|
2012-02-27 08:52:19 -08:00
|
|
|
}
|
2012-07-06 10:28:51 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
IDBWrapperCache::AssertIsRooted() const
|
|
|
|
{
|
2013-08-16 13:10:17 -07:00
|
|
|
MOZ_ASSERT(cyclecollector::IsJSHolder(const_cast<IDBWrapperCache*>(this)),
|
|
|
|
"Why aren't we rooted?!");
|
2012-07-06 10:28:51 -07:00
|
|
|
}
|
|
|
|
#endif
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|