2012-03-30 21:42:20 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* 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 "DOMBindingBase.h"
|
|
|
|
|
|
|
|
#include "jsfriendapi.h"
|
2012-05-02 21:35:38 -07:00
|
|
|
#include "mozilla/dom/DOMJSClass.h"
|
2012-03-30 21:42:20 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsWrapperCacheInlines.h"
|
|
|
|
|
2012-11-10 07:45:52 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2012-03-30 21:42:20 -07:00
|
|
|
USING_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
DOMBindingBase::DOMBindingBase(JSContext* aCx)
|
|
|
|
: mJSContext(aCx)
|
|
|
|
{
|
|
|
|
if (!aCx) {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMBindingBase::~DOMBindingBase()
|
|
|
|
{
|
|
|
|
if (!mJSContext) {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 19:47:47 -07:00
|
|
|
NS_IMPL_ADDREF(DOMBindingBase)
|
|
|
|
NS_IMPL_RELEASE(DOMBindingBase)
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DOMBindingBase)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2012-04-26 13:57:33 -07:00
|
|
|
DOMBindingBase::_trace(JSTracer* aTrc)
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
2013-03-28 13:37:22 -07:00
|
|
|
TraceJSObject(aTrc, "cached wrapper");
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-04-26 13:57:33 -07:00
|
|
|
DOMBindingBase::_finalize(JSFreeOp* aFop)
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
ClearWrapper();
|
|
|
|
NS_RELEASE_THIS();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext*
|
2013-04-18 08:36:03 -07:00
|
|
|
DOMBindingBase::GetJSContext() const {
|
|
|
|
return mJSContext ? mJSContext : nsContentUtils::GetCurrentJSContext();
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSObject*
|
|
|
|
DOMBindingBase::GetJSObject() const
|
|
|
|
{
|
|
|
|
// Make sure that the public method results in the same bits as our private
|
|
|
|
// method.
|
2013-06-08 01:53:21 -07:00
|
|
|
MOZ_ASSERT(GetWrapperJSObject() == GetWrapperPreserveColor());
|
|
|
|
return GetWrapperJSObject();
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMBindingBase::SetJSObject(JSObject* aObject)
|
|
|
|
{
|
|
|
|
// Make sure that the public method results in the same bits as our private
|
|
|
|
// method.
|
|
|
|
SetWrapper(aObject);
|
|
|
|
|
2013-06-08 01:53:21 -07:00
|
|
|
uint8_t oldFlags = mFlags;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-06-08 01:53:21 -07:00
|
|
|
SetWrapperJSObject(aObject);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-06-08 01:53:21 -07:00
|
|
|
MOZ_ASSERT(oldFlags == mFlags && aObject == mWrapper);
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
|
|
|
#endif
|