JSBool XPCWrappedNativeProto::Init(XPCCallContext& ccx, const XPCNativeScriptableCreateInfo* scriptableCreateInfo, bool callPostCreatePrototype) { nsIXPCScriptable *callback = scriptableCreateInfo ? scriptableCreateInfo->GetCallback() : nullptr; if (callback) { mScriptableInfo = XPCNativeScriptableInfo::Construct(ccx, scriptableCreateInfo); if (!mScriptableInfo) return false; } js::Class* jsclazz; if (mScriptableInfo) { const XPCNativeScriptableFlags& flags(mScriptableInfo->GetFlags()); if (flags.AllowPropModsToPrototype()) { jsclazz = flags.WantCall() ? &XPC_WN_ModsAllowed_WithCall_Proto_JSClass : &XPC_WN_ModsAllowed_NoCall_Proto_JSClass; } else { jsclazz = flags.WantCall() ? &XPC_WN_NoMods_WithCall_Proto_JSClass : &XPC_WN_NoMods_NoCall_Proto_JSClass; } } else { jsclazz = &XPC_WN_NoMods_NoCall_Proto_JSClass; } JSObject *parent = mScope->GetGlobalJSObject(); mJSProtoObject = xpc_NewSystemInheritingJSObject(ccx, js::Jsvalify(jsclazz), mScope->GetPrototypeJSObject(), true, parent); bool success = !!mJSProtoObject; if (success) { JS_SetPrivate(mJSProtoObject, this); if (callPostCreatePrototype) success = CallPostCreatePrototype(ccx); } DEBUG_ReportShadowedMembers(mSet, nullptr, this); return success; }
JSBool XPCWrappedNativeProto::Init( XPCCallContext& ccx, JSBool isGlobal, const XPCNativeScriptableCreateInfo* scriptableCreateInfo) { if(scriptableCreateInfo && scriptableCreateInfo->GetCallback()) { mScriptableInfo = XPCNativeScriptableInfo::Construct(ccx, isGlobal, scriptableCreateInfo); if(!mScriptableInfo) return JS_FALSE; } JSClass* jsclazz; if(mScriptableInfo) { const XPCNativeScriptableFlags& flags(mScriptableInfo->GetFlags()); if(flags.AllowPropModsToPrototype()) { jsclazz = flags.WantCall() ? &XPC_WN_ModsAllowed_WithCall_Proto_JSClass : &XPC_WN_ModsAllowed_NoCall_Proto_JSClass; } else { jsclazz = flags.WantCall() ? &XPC_WN_NoMods_WithCall_Proto_JSClass : &XPC_WN_NoMods_NoCall_Proto_JSClass; } } else { jsclazz = &XPC_WN_NoMods_NoCall_Proto_JSClass; } JSObject *parent = mScope->GetGlobalJSObject(); mJSProtoObject = xpc_NewSystemInheritingJSObject(ccx, jsclazz, mScope->GetPrototypeJSObject(), parent); JSBool ok = mJSProtoObject && JS_SetPrivate(ccx, mJSProtoObject, this); DEBUG_ReportShadowedMembers(mSet, nsnull, this); return ok; }
JSObject * XPCWrappedNativeScope::GetPrototypeNoHelper(XPCCallContext& ccx) { // We could create this prototype in SetGlobal(), but all scopes // don't need one, so we save ourselves a bit of space if we // create these when they're needed. if(!mPrototypeNoHelper) { mPrototypeNoHelper = xpc_NewSystemInheritingJSObject(ccx, &XPC_WN_NoHelper_Proto_JSClass, mPrototypeJSObject, mGlobalJSObject); NS_ASSERTION(mPrototypeNoHelper, "Failed to create prototype for wrappers w/o a helper"); } return mPrototypeNoHelper; }
JSBool XPCWrappedNativeProto::Init( XPCCallContext& ccx, JSBool isGlobal, const XPCNativeScriptableCreateInfo* scriptableCreateInfo) { nsIXPCScriptable *callback = scriptableCreateInfo ? scriptableCreateInfo->GetCallback() : nsnull; if(callback) { mScriptableInfo = XPCNativeScriptableInfo::Construct(ccx, isGlobal, scriptableCreateInfo); if(!mScriptableInfo) return JS_FALSE; } js::Class* jsclazz; if(mScriptableInfo) { const XPCNativeScriptableFlags& flags(mScriptableInfo->GetFlags()); if(flags.AllowPropModsToPrototype()) { jsclazz = flags.WantCall() ? &XPC_WN_ModsAllowed_WithCall_Proto_JSClass : &XPC_WN_ModsAllowed_NoCall_Proto_JSClass; } else { jsclazz = flags.WantCall() ? &XPC_WN_NoMods_WithCall_Proto_JSClass : &XPC_WN_NoMods_NoCall_Proto_JSClass; } } else { jsclazz = &XPC_WN_NoMods_NoCall_Proto_JSClass; } JSObject *parent = mScope->GetGlobalJSObject(); mJSProtoObject = xpc_NewSystemInheritingJSObject(ccx, js::Jsvalify(jsclazz), mScope->GetPrototypeJSObject(), parent); JSBool ok = mJSProtoObject && JS_SetPrivate(ccx, mJSProtoObject, this); if(ok && callback) { nsresult rv = callback->PostCreatePrototype(ccx, mJSProtoObject); if(NS_FAILED(rv)) { JS_SetPrivate(ccx, mJSProtoObject, nsnull); mJSProtoObject = nsnull; XPCThrower::Throw(rv, ccx); return JS_FALSE; } } DEBUG_ReportShadowedMembers(mSet, nsnull, this); return ok; }