本文整理汇总了C++中XPCWrappedNative::GetScope方法的典型用法代码示例。如果您正苦于以下问题:C++ XPCWrappedNative::GetScope方法的具体用法?C++ XPCWrappedNative::GetScope怎么用?C++ XPCWrappedNative::GetScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XPCWrappedNative
的用法示例。
在下文中一共展示了XPCWrappedNative::GetScope方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ccx
static bool
XPC_WN_TearOff_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvedp)
{
XPCCallContext ccx(cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
XPCWrappedNativeTearOff* to = ccx.GetTearOff();
XPCNativeInterface* iface;
if (!to || nullptr == (iface = to->GetInterface()))
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
return DefinePropertyIfFound(ccx, obj, id, nullptr, iface, nullptr,
wrapper->GetScope(),
true, nullptr, nullptr, nullptr,
JSPROP_READONLY |
JSPROP_PERMANENT |
JSPROP_ENUMERATE, resolvedp);
}
示例2: CheckWindow
JSBool
WrapObject(JSContext *cx, JSObject *parent, jsval *vp, XPCWrappedNative* wn)
{
NS_ASSERTION(XPCPerThreadData::IsMainThread(cx),
"Can't do this off the main thread!");
// Our argument should be a wrapped native object, but the caller may have
// passed it in as an optimization.
JSObject *wrappedObj;
if (JSVAL_IS_PRIMITIVE(*vp) ||
!(wrappedObj = JSVAL_TO_OBJECT(*vp)) ||
wrappedObj->getClass() == &XOWClass) {
return JS_TRUE;
}
if (!wn &&
!(wn = XPCWrappedNative::GetAndMorphWrappedNativeOfJSObject(cx, wrappedObj))) {
return JS_TRUE;
}
CheckWindow(wn);
// The parent must be the inner global object for its scope.
parent = JS_GetGlobalForObject(cx, parent);
OBJ_TO_INNER_OBJECT(cx, parent);
if (!parent) {
return JS_FALSE;
}
XPCWrappedNativeWithXOW *wnxow = nsnull;
if (wn->NeedsXOW()) {
JSObject *innerWrappedObj = wrappedObj;
OBJ_TO_INNER_OBJECT(cx, innerWrappedObj);
if (!innerWrappedObj) {
return JS_FALSE;
}
if (innerWrappedObj == parent) {
wnxow = static_cast<XPCWrappedNativeWithXOW *>(wn);
JSObject *xow = wnxow->GetXOW();
if (xow) {
*vp = OBJECT_TO_JSVAL(xow);
return JS_TRUE;
}
}
}
XPCWrappedNative *parentwn =
XPCWrappedNative::GetWrappedNativeOfJSObject(cx, parent);
XPCWrappedNativeScope *parentScope;
if (NS_LIKELY(parentwn)) {
parentScope = parentwn->GetScope();
} else {
parentScope = XPCWrappedNativeScope::FindInJSObjectScope(cx, parent);
}
JSObject *outerObj = nsnull;
WrappedNative2WrapperMap *map = parentScope->GetWrapperMap();
outerObj = map->Find(wrappedObj);
if (outerObj) {
NS_ASSERTION(outerObj->getClass() == &XOWClass,
"What crazy object are we getting here?");
*vp = OBJECT_TO_JSVAL(outerObj);
if (wnxow) {
// NB: wnxow->GetXOW() must have returned false.
SetFlags(cx, outerObj, AddFlags(GetFlags(cx, outerObj), FLAG_IS_CACHED));
wnxow->SetXOW(outerObj);
}
return JS_TRUE;
}
outerObj = JS_NewObjectWithGivenProto(cx, js::Jsvalify(&XOWClass), nsnull,
parent);
if (!outerObj) {
return JS_FALSE;
}
jsval flags = INT_TO_JSVAL(wnxow ? FLAG_IS_CACHED : 0);
if (!JS_SetReservedSlot(cx, outerObj, sWrappedObjSlot, *vp) ||
!JS_SetReservedSlot(cx, outerObj, sFlagsSlot, flags) ||
!JS_SetReservedSlot(cx, outerObj, XPC_XOW_ScopeSlot,
PRIVATE_TO_JSVAL(parentScope))) {
return JS_FALSE;
}
*vp = OBJECT_TO_JSVAL(outerObj);
map->Add(wn->GetScope()->GetWrapperMap(), wrappedObj, outerObj);
if(wnxow) {
wnxow->SetXOW(outerObj);
}
return JS_TRUE;
}