本文整理汇总了C++中XPCJSRuntime类的典型用法代码示例。如果您正苦于以下问题:C++ XPCJSRuntime类的具体用法?C++ XPCJSRuntime怎么用?C++ XPCJSRuntime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XPCJSRuntime类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: lock
// static
void
XPCWrappedNativeScope::FinishedFinalizationPhaseOfGC()
{
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
// FIXME The lock may not be necessary since we are inside
// JSGC_FINALIZE_END callback and at this point GC still serializes access
// to JS runtime. See bug 380139.
XPCAutoLock lock(rt->GetMapLock());
KillDyingScopes();
}
开发者ID:,项目名称:,代码行数:12,代码来源:
示例2: RemoveFromRootSet
void
nsXPCWrappedJS::Unlink()
{
nsXPConnect::GetRuntimeInstance()->AssertInvalidWrappedJSNotInTable(this);
if (IsValid()) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt) {
if (IsRootWrapper())
rt->RemoveWrappedJS(this);
if (mRefCnt > 1)
RemoveFromRootSet();
}
mJSObj = nullptr;
}
if (IsRootWrapper()) {
ClearWeakReferences();
} else if (mRoot) {
// unlink this wrapper
nsXPCWrappedJS* cur = mRoot;
while (1) {
if (cur->mNext == this) {
cur->mNext = mNext;
break;
}
cur = cur->mNext;
MOZ_ASSERT(cur, "failed to find wrapper in its own chain");
}
// Note: unlinking this wrapper may have changed us from a multi-
// compartment wrapper chain to a single-compartment wrapper chain. We
// leave the wrapper in the multi-compartment table as it is likely to
// need to be multi-compartment again in the future and, moreover, we
// cannot get a JSContext here.
// let the root go
NS_RELEASE(mRoot);
}
mClass = nullptr;
if (mOuter) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt->GCIsRunning()) {
DeferredFinalize(mOuter.forget().take());
} else {
mOuter = nullptr;
}
}
}
开发者ID:cstipkovic,项目名称:gecko-dev,代码行数:52,代码来源:XPCWrappedJS.cpp
示例3: NS_PRECONDITION
nsXPCWrappedJS::~nsXPCWrappedJS()
{
NS_PRECONDITION(0 == mRefCnt, "refcounting error");
if (mRoot == this) {
// Remove this root wrapper from the map
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (map)
map->Remove(this);
}
Unlink();
}
开发者ID:iHaD,项目名称:Spidermonkey,代码行数:13,代码来源:XPCWrappedJS.cpp
示例4: NS_AtomicIncrementRefcnt
nsrefcnt
nsXPCWrappedJS::AddRef(void)
{
nsrefcnt cnt = NS_AtomicIncrementRefcnt(mRefCnt);
NS_LOG_ADDREF(this, cnt, "nsXPCWrappedJS", sizeof(*this));
if (2 == cnt && IsValid()) {
XPCJSRuntime* rt = mClass->GetRuntime();
rt->AddWrappedJSRoot(this);
}
return cnt;
}
开发者ID:krad-radio,项目名称:mozilla-krad,代码行数:13,代码来源:XPCWrappedJS.cpp
示例5: MOZ_ASSERT
void
nsXPCWrappedJS::Destroy()
{
MOZ_ASSERT(1 == int32_t(mRefCnt), "should be stabilized for deletion");
if (IsRootWrapper()) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (map)
map->Remove(this);
}
Unlink();
}
开发者ID:,项目名称:,代码行数:13,代码来源:
示例6: MOZ_CRASH
// static
nsresult
nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
REFNSIID aIID,
nsXPCWrappedJS** wrapperResult)
{
// Do a release-mode assert against accessing nsXPCWrappedJS off-main-thread.
if (!MOZ_LIKELY(NS_IsMainThread()))
MOZ_CRASH();
AutoJSContext cx;
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (!map) {
MOZ_ASSERT(map,"bad map");
return NS_ERROR_FAILURE;
}
bool allowNonScriptable = mozilla::jsipc::IsWrappedCPOW(jsObj);
nsRefPtr<nsXPCWrappedJSClass> clasp = nsXPCWrappedJSClass::GetNewOrUsed(cx, aIID,
allowNonScriptable);
if (!clasp)
return NS_ERROR_FAILURE;
JS::RootedObject rootJSObj(cx, clasp->GetRootJSObject(cx, jsObj));
if (!rootJSObj)
return NS_ERROR_FAILURE;
nsRefPtr<nsXPCWrappedJS> root = map->Find(rootJSObj);
if (root) {
nsRefPtr<nsXPCWrappedJS> wrapper = root->FindOrFindInherited(aIID);
if (wrapper) {
wrapper.forget(wrapperResult);
return NS_OK;
}
} else if (rootJSObj != jsObj) {
// Make a new root wrapper, because there is no existing
// root wrapper, and the wrapper we are trying to make isn't
// a root.
nsRefPtr<nsXPCWrappedJSClass> rootClasp = nsXPCWrappedJSClass::GetNewOrUsed(cx, NS_GET_IID(nsISupports));
if (!rootClasp)
return NS_ERROR_FAILURE;
root = new nsXPCWrappedJS(cx, rootJSObj, rootClasp, nullptr);
}
nsRefPtr<nsXPCWrappedJS> wrapper = new nsXPCWrappedJS(cx, jsObj, clasp, root);
wrapper.forget(wrapperResult);
return NS_OK;
}
开发者ID:ckerschb,项目名称:gecko-dev,代码行数:51,代码来源:XPCWrappedJS.cpp
示例7: set
// static
XPCNativeSet*
XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, const nsIID* iid)
{
AutoMarkingNativeSetPtr set(ccx);
AutoMarkingNativeInterfacePtr iface(ccx);
iface = XPCNativeInterface::GetNewOrUsed(ccx, iid);
if(!iface)
return nsnull;
XPCNativeSetKey key(nsnull, iface, 0);
XPCJSRuntime* rt = ccx.GetRuntime();
NativeSetMap* map = rt->GetNativeSetMap();
if(!map)
return nsnull;
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
set = map->Find(&key);
}
if(set)
return set;
// hacky way to get a XPCNativeInterface** using the AutoPtr
XPCNativeInterface* temp[] = {iface};
set = NewInstance(ccx, temp, 1);
if(!set)
return nsnull;
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
XPCNativeSet* set2 = map->Add(&key, set);
if(!set2)
{
NS_ERROR("failed to add our set!");
DestroyInstance(set);
set = nsnull;
}
else if(set2 != set)
{
DestroyInstance(set);
set = set2;
}
}
return set;
}
开发者ID:jdahlin,项目名称:jslint,代码行数:50,代码来源:xpcwrappednativeinfo.cpp
示例8: MOZ_CRASH
nsrefcnt
nsXPCWrappedJS::Release(void)
{
if (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
MOZ_CRASH();
NS_PRECONDITION(0 != mRefCnt, "dup release");
if (mMainThreadOnly && !NS_IsMainThread()) {
// We'd like to abort here, but this can happen if someone uses a proxy
// for the nsXPCWrappedJS.
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
// If we can't get the main thread anymore we just leak, but this really
// shouldn't happen.
NS_ASSERTION(mainThread,
"Can't get main thread, leaking nsXPCWrappedJS!");
if (mainThread) {
NS_ProxyRelease(mainThread,
static_cast<nsIXPConnectWrappedJS*>(this));
}
return mRefCnt;
}
// need to take the map lock here to prevent GetNewOrUsed from trying
// to reuse a wrapper on one thread while it's being destroyed on another
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
XPCAutoLock lock(rt->GetMapLock());
do_decrement:
nsrefcnt cnt = --mRefCnt;
NS_LOG_RELEASE(this, cnt, "nsXPCWrappedJS");
if (0 == cnt) {
delete this; // also unlinks us from chain
return 0;
}
if (1 == cnt) {
if (IsValid())
RemoveFromRootSet(rt->GetMapLock());
// If we are not the root wrapper or if we are not being used from a
// weak reference, then this extra ref is not needed and we can let
// ourself be deleted.
// Note: HasWeakReferences() could only return true for the root.
if (!HasWeakReferences())
goto do_decrement;
}
return cnt;
}
开发者ID:hahajung,项目名称:mozilla-central,代码行数:49,代码来源:XPCWrappedJS.cpp
示例9: RemoveFromRootSet
void
nsXPCWrappedJS::Unlink()
{
if (IsValid()) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt) {
if (mRoot == this) {
// remove this root wrapper from the map
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (map)
map->Remove(this);
}
if (mRefCnt > 1)
RemoveFromRootSet();
}
mJSObj = nullptr;
}
if (mRoot == this) {
ClearWeakReferences();
} else if (mRoot) {
// unlink this wrapper
nsXPCWrappedJS* cur = mRoot;
while (1) {
if (cur->mNext == this) {
cur->mNext = mNext;
break;
}
cur = cur->mNext;
MOZ_ASSERT(cur, "failed to find wrapper in its own chain");
}
// let the root go
NS_RELEASE(mRoot);
}
NS_IF_RELEASE(mClass);
if (mOuter) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt->GCIsRunning()) {
nsContentUtils::DeferredFinalize(mOuter);
mOuter = nullptr;
} else {
NS_RELEASE(mOuter);
}
}
}
开发者ID:iHaD,项目名称:Spidermonkey,代码行数:48,代码来源:XPCWrappedJS.cpp
示例10: iface
// static
XPCNativeInterface*
XPCNativeInterface::GetNewOrUsed(XPCCallContext& ccx, const nsIID* iid)
{
AutoMarkingNativeInterfacePtr iface(ccx);
XPCJSRuntime* rt = ccx.GetRuntime();
IID2NativeInterfaceMap* map = rt->GetIID2NativeInterfaceMap();
if(!map)
return nsnull;
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
iface = map->Find(*iid);
}
if(iface)
return iface;
nsCOMPtr<nsIInterfaceInfo> info;
ccx.GetXPConnect()->GetInfoForIID(iid, getter_AddRefs(info));
if(!info)
return nsnull;
iface = NewInstance(ccx, info);
if(!iface)
return nsnull;
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
XPCNativeInterface* iface2 = map->Add(iface);
if(!iface2)
{
NS_ERROR("failed to add our interface!");
DestroyInstance(ccx, rt, iface);
iface = nsnull;
}
else if(iface2 != iface)
{
DestroyInstance(ccx, rt, iface);
iface = iface2;
}
}
return iface;
}
开发者ID:jdahlin,项目名称:jslint,代码行数:46,代码来源:xpcwrappednativeinfo.cpp
示例11: ccx
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
NS_IMETHODIMP
nsJSCID::Construct(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * obj,
PRUint32 argc, jsval * argv, jsval * vp,
PRBool *_retval)
{
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if(!rt)
return NS_ERROR_FAILURE;
// 'push' a call context and call on it
XPCCallContext ccx(JS_CALLER, cx, obj, nsnull,
rt->GetStringID(XPCJSRuntime::IDX_CREATE_INSTANCE),
argc, argv, vp);
*_retval = XPCWrappedNative::CallMethod(ccx);
return NS_OK;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:19,代码来源:xpcjsid.cpp
示例12: ContextCallback
// GCCallback calls are chained
static JSBool
ContextCallback(JSContext *cx, uintN operation)
{
XPCJSRuntime* self = nsXPConnect::GetRuntimeInstance();
if(self)
{
if(operation == JSCONTEXT_NEW)
{
if(!self->OnJSContextNew(cx))
return JS_FALSE;
}
else if(operation == JSCONTEXT_DESTROY)
{
delete XPCContext::GetXPCContext(cx);
}
}
return JS_TRUE;
}
开发者ID:,项目名称:,代码行数:19,代码来源:
示例13: obj
NS_IMETHODIMP
nsJSCID::Construct(nsIXPConnectWrappedNative* wrapper,
JSContext* cx, JSObject* objArg,
const CallArgs& args, bool* _retval)
{
RootedObject obj(cx, objArg);
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (!rt)
return NS_ERROR_FAILURE;
// 'push' a call context and call on it
RootedId name(cx, rt->GetStringID(XPCJSRuntime::IDX_CREATE_INSTANCE));
XPCCallContext ccx(JS_CALLER, cx, obj, nullptr, name, args.length(), args.array(),
args.rval().address());
*_retval = XPCWrappedNative::CallMethod(ccx);
return NS_OK;
}
开发者ID:,项目名称:,代码行数:18,代码来源:
示例14: iface
// static
XPCNativeInterface*
XPCNativeInterface::GetNewOrUsed(const nsIID* iid)
{
AutoJSContext cx;
AutoMarkingNativeInterfacePtr iface(cx);
XPCJSRuntime* rt = XPCJSRuntime::Get();
IID2NativeInterfaceMap* map = rt->GetIID2NativeInterfaceMap();
if (!map)
return nullptr;
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
iface = map->Find(*iid);
}
if (iface)
return iface;
nsCOMPtr<nsIInterfaceInfo> info;
XPTInterfaceInfoManager::GetSingleton()->GetInfoForIID(iid, getter_AddRefs(info));
if (!info)
return nullptr;
iface = NewInstance(info);
if (!iface)
return nullptr;
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
XPCNativeInterface* iface2 = map->Add(iface);
if (!iface2) {
NS_ERROR("failed to add our interface!");
DestroyInstance(iface);
iface = nullptr;
} else if (iface2 != iface) {
DestroyInstance(iface);
iface = iface2;
}
}
return iface;
}
开发者ID:hahajung,项目名称:mozilla-central,代码行数:44,代码来源:XPCWrappedNativeInfo.cpp
示例15: TraceJS
// static
void XPCJSRuntime::TraceJS(JSTracer* trc, void* data)
{
XPCJSRuntime* self = (XPCJSRuntime*)data;
// Skip this part if XPConnect is shutting down. We get into
// bad locking problems with the thread iteration otherwise.
if(!self->GetXPConnect()->IsShuttingDown())
{
PRLock* threadLock = XPCPerThreadData::GetLock();
if(threadLock)
{ // scoped lock
nsAutoLock lock(threadLock);
XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread;
while(nsnull != (thread =
XPCPerThreadData::IterateThreads(&iterp)))
{
// Trace those AutoMarkingPtr lists!
thread->TraceJS(trc);
}
}
}
// XPCJSObjectHolders don't participate in cycle collection, so always trace
// them here.
for(XPCRootSetElem *e = self->mObjectHolderRoots; e ; e = e->GetNextRoot())
static_cast<XPCJSObjectHolder*>(e)->TraceJS(trc);
// Mark these roots as gray so the CC can walk them later.
js::GCMarker *gcmarker = NULL;
if (IS_GC_MARKING_TRACER(trc)) {
gcmarker = static_cast<js::GCMarker *>(trc);
JS_ASSERT(gcmarker->getMarkColor() == XPC_GC_COLOR_BLACK);
gcmarker->setMarkColor(XPC_GC_COLOR_GRAY);
}
self->TraceXPConnectRoots(trc);
if (gcmarker)
gcmarker->setMarkColor(XPC_GC_COLOR_BLACK);
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:42,代码来源:xpcjsruntime.cpp
示例16: set
// static
XPCNativeSet*
XPCNativeSet::GetNewOrUsed(const nsIID* iid)
{
AutoJSContext cx;
AutoMarkingNativeSetPtr set(cx);
AutoMarkingNativeInterfacePtr iface(cx);
iface = XPCNativeInterface::GetNewOrUsed(iid);
if (!iface)
return nullptr;
XPCNativeSetKey key(nullptr, iface, 0);
XPCJSRuntime* rt = XPCJSRuntime::Get();
NativeSetMap* map = rt->GetNativeSetMap();
if (!map)
return nullptr;
set = map->Find(&key);
if (set)
return set;
// hacky way to get a XPCNativeInterface** using the AutoPtr
XPCNativeInterface* temp[] = {iface};
set = NewInstance(temp, 1);
if (!set)
return nullptr;
XPCNativeSet* set2 = map->Add(&key, set);
if (!set2) {
NS_ERROR("failed to add our set!");
DestroyInstance(set);
set = nullptr;
} else if (set2 != set) {
DestroyInstance(set);
set = set2;
}
return set;
}
开发者ID:Nazi-Nigger,项目名称:gecko-dev,代码行数:42,代码来源:XPCWrappedNativeInfo.cpp
示例17: TraceJS
// static
void XPCJSRuntime::TraceJS(JSTracer* trc, void* data)
{
XPCJSRuntime* self = (XPCJSRuntime*)data;
// Skip this part if XPConnect is shutting down. We get into
// bad locking problems with the thread iteration otherwise.
if(!self->GetXPConnect()->IsShuttingDown())
{
PRLock* threadLock = XPCPerThreadData::GetLock();
if(threadLock)
{ // scoped lock
nsAutoLock lock(threadLock);
XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread;
while(nsnull != (thread =
XPCPerThreadData::IterateThreads(&iterp)))
{
// Trace those AutoMarkingPtr lists!
thread->TraceJS(trc);
}
}
}
// XPCJSObjectHolders don't participate in cycle collection, so always trace
// them here.
for(XPCRootSetElem *e = self->mObjectHolderRoots; e ; e = e->GetNextRoot())
static_cast<XPCJSObjectHolder*>(e)->TraceJS(trc);
if(self->GetXPConnect()->ShouldTraceRoots())
{
// Only trace these if we're not cycle-collecting, the cycle collector
// will do that if we are.
self->TraceXPConnectRoots(trc);
}
}
开发者ID:,项目名称:,代码行数:38,代码来源:
示例18: WrapperMoved
JSBool
WrapperMoved(JSContext *cx, XPCWrappedNative *innerObj,
XPCWrappedNativeScope *newScope)
{
typedef WrappedNative2WrapperMap::Link Link;
XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance();
WrappedNative2WrapperMap *map = innerObj->GetScope()->GetWrapperMap();
Link *link;
{ // Scoped lock
XPCAutoLock al(rt->GetMapLock());
link = map->FindLink(innerObj->GetFlatJSObject());
}
if (!link) {
// No link here means that there were no XOWs for this object.
return JS_TRUE;
}
JSObject *xow = link->obj;
{ // Scoped lock.
XPCAutoLock al(rt->GetMapLock());
if (!newScope->GetWrapperMap()->AddLink(innerObj->GetFlatJSObject(), link))
return JS_FALSE;
map->Remove(innerObj->GetFlatJSObject());
}
if (!xow) {
// Nothing else to do.
return JS_TRUE;
}
return JS_SetReservedSlot(cx, xow, XPC_XOW_ScopeSlot,
PRIVATE_TO_JSVAL(newScope)) &&
JS_SetParent(cx, xow, newScope->GetGlobalJSObject());
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:37,代码来源:XPCCrossOriginWrapper.cpp
示例19: iface
// static
XPCNativeInterface*
XPCNativeInterface::GetNewOrUsed(nsIInterfaceInfo* info)
{
AutoJSContext cx;
AutoMarkingNativeInterfacePtr iface(cx);
const nsIID* iid;
if (NS_FAILED(info->GetIIDShared(&iid)) || !iid)
return nullptr;
XPCJSRuntime* rt = XPCJSRuntime::Get();
IID2NativeInterfaceMap* map = rt->GetIID2NativeInterfaceMap();
if (!map)
return nullptr;
iface = map->Find(*iid);
if (iface)
return iface;
iface = NewInstance(info);
if (!iface)
return nullptr;
XPCNativeInterface* iface2 = map->Add(iface);
if (!iface2) {
NS_ERROR("failed to add our interface!");
DestroyInstance(iface);
iface = nullptr;
} else if (iface2 != iface) {
DestroyInstance(iface);
iface = iface2;
}
return iface;
}
开发者ID:Nazi-Nigger,项目名称:gecko-dev,代码行数:38,代码来源:XPCWrappedNativeInfo.cpp
示例20: lock
void
nsXPCWrappedJS::Unlink()
{
if (IsValid()) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt) {
if (mRoot == this) {
// remove this root wrapper from the map
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (map) {
XPCAutoLock lock(rt->GetMapLock());
map->Remove(this);
}
}
if (mRefCnt > 1)
RemoveFromRootSet(rt->GetMapLock());
}
mJSObj = nsnull;
}
if (mRoot == this) {
ClearWeakReferences();
} else if (mRoot) {
// unlink this wrapper
nsXPCWrappedJS* cur = mRoot;
while (1) {
if (cur->mNext == this) {
cur->mNext = mNext;
break;
}
cur = cur->mNext;
NS_ASSERTION(cur, "failed to find wrapper in its own chain");
}
// let the root go
NS_RELEASE(mRoot);
}
NS_IF_RELEASE(mClass);
if (mOuter) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt->GetThreadRunningGC()) {
rt->DeferredRelease(mOuter);
mOuter = nsnull;
} else {
NS_RELEASE(mOuter);
}
}
}
开发者ID:krad-radio,项目名称:mozilla-krad,代码行数:50,代码来源:XPCWrappedJS.cpp
注:本文中的XPCJSRuntime类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论