本文整理汇总了C++中JSObject2WrappedJSMap类的典型用法代码示例。如果您正苦于以下问题:C++ JSObject2WrappedJSMap类的具体用法?C++ JSObject2WrappedJSMap怎么用?C++ JSObject2WrappedJSMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSObject2WrappedJSMap类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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);
}
}
}
示例3: 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;
}
示例4: 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) {
XPCAutoLock lock(rt->GetMapLock());
map->Remove(this);
}
}
Unlink();
}
示例5: 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);
}
}
}
示例6: MOZ_CRASH
// static
nsresult
nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
REFNSIID aIID,
nsISupports* aOuter,
nsXPCWrappedJS** wrapperResult)
{
// Do a release-mode assert against accessing nsXPCWrappedJS off-main-thread.
if (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
MOZ_CRASH();
AutoJSContext cx;
JSObject2WrappedJSMap* map;
nsXPCWrappedJS* root = nullptr;
nsXPCWrappedJS* wrapper = nullptr;
nsXPCWrappedJSClass* clazz = nullptr;
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
bool release_root = false;
map = rt->GetWrappedJSMap();
if (!map) {
NS_ASSERTION(map,"bad map");
return NS_ERROR_FAILURE;
}
nsXPCWrappedJSClass::GetNewOrUsed(cx, aIID, &clazz);
if (!clazz)
return NS_ERROR_FAILURE;
// from here on we need to return through 'return_wrapper'
// always find the root JSObject
JS::RootedObject rootJSObj(cx, clazz->GetRootJSObject(cx, jsObj));
if (!rootJSObj)
goto return_wrapper;
// look for the root wrapper, and if found, hold the map lock until
// we've added our ref to prevent another thread from destroying it
// under us
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
root = map->Find(rootJSObj);
if (root) {
if ((nullptr != (wrapper = root->Find(aIID))) ||
(nullptr != (wrapper = root->FindInherited(aIID)))) {
NS_ADDREF(wrapper);
goto return_wrapper;
}
}
}
if (!root) {
// build the root wrapper
if (rootJSObj == jsObj) {
// the root will do double duty as the interface wrapper
wrapper = root = new nsXPCWrappedJS(cx, jsObj, clazz, nullptr,
aOuter);
if (!root)
goto return_wrapper;
{ // scoped lock
#if DEBUG_xpc_leaks
printf("Created nsXPCWrappedJS %p, JSObject is %p\n",
(void*)wrapper, (void*)jsObj);
#endif
XPCAutoLock lock(rt->GetMapLock());
map->Add(cx, root);
}
if (!CheckMainThreadOnly(root)) {
XPCAutoLock lock(rt->GetMapLock());
map->Remove(root);
wrapper = NULL;
}
goto return_wrapper;
} else {
// just a root wrapper
nsXPCWrappedJSClass* rootClazz = nullptr;
nsXPCWrappedJSClass::GetNewOrUsed(cx, NS_GET_IID(nsISupports),
&rootClazz);
if (!rootClazz)
goto return_wrapper;
root = new nsXPCWrappedJS(cx, rootJSObj, rootClazz, nullptr, aOuter);
NS_RELEASE(rootClazz);
if (!root)
goto return_wrapper;
release_root = true;
{ // scoped lock
#if DEBUG_xpc_leaks
printf("Created nsXPCWrappedJS %p, JSObject is %p\n",
(void*)root, (void*)rootJSObj);
#endif
XPCAutoLock lock(rt->GetMapLock());
map->Add(cx, root);
}
//.........这里部分代码省略.........