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 "nsIJSContextStack.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
|
|
|
{
|
|
|
|
JSObject* obj = GetJSObject();
|
|
|
|
if (obj) {
|
|
|
|
JS_CALL_OBJECT_TRACER(aTrc, obj, "cached wrapper");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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*
|
|
|
|
DOMBindingBase::GetJSContextFromContextStack() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
MOZ_ASSERT(!mJSContext);
|
|
|
|
|
|
|
|
if (!mContextStack) {
|
|
|
|
mContextStack = nsContentUtils::ThreadJSContextStack();
|
|
|
|
MOZ_ASSERT(mContextStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext* cx;
|
|
|
|
if (NS_FAILED(mContextStack->Peek(&cx))) {
|
|
|
|
MOZ_NOT_REACHED("This should never fail!");
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(cx);
|
|
|
|
return cx;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSObject*
|
|
|
|
DOMBindingBase::GetJSObject() const
|
|
|
|
{
|
|
|
|
// Make sure that the public method results in the same bits as our private
|
|
|
|
// method.
|
|
|
|
MOZ_ASSERT(GetJSObjectFromBits() == GetWrapperPreserveColor());
|
|
|
|
return GetJSObjectFromBits();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMBindingBase::SetJSObject(JSObject* aObject)
|
|
|
|
{
|
|
|
|
// Make sure that the public method results in the same bits as our private
|
|
|
|
// method.
|
|
|
|
SetWrapper(aObject);
|
|
|
|
|
2012-10-02 01:24:11 -07:00
|
|
|
uintptr_t oldWrapperPtrBits = mWrapperPtrBits;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
SetWrapperBits(aObject);
|
|
|
|
|
|
|
|
MOZ_ASSERT(oldWrapperPtrBits == mWrapperPtrBits);
|
|
|
|
}
|
|
|
|
#endif
|