Bug 720580 - Stop passing isGlobal everywhere and use the nsIXPCScriptable flags instead. r=mrbkap

This commit is contained in:
Bobby Holley 2012-03-05 15:22:44 -08:00
parent ccb745bc93
commit fe4872737f
12 changed files with 30 additions and 78 deletions

View File

@ -4223,8 +4223,7 @@ nsXPCComponents::AttachNewComponentsObject(XPCCallContext& ccx,
nsCOMPtr<XPCWrappedNative> wrapper;
xpcObjectHelper helper(cholder);
XPCWrappedNative::GetNewOrUsed(ccx, helper, aScope, iface,
OBJ_IS_NOT_GLOBAL, getter_AddRefs(wrapper));
XPCWrappedNative::GetNewOrUsed(ccx, helper, aScope, iface, getter_AddRefs(wrapper));
if (!wrapper)
return false;

View File

@ -348,16 +348,9 @@ XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s,
pErr, d);
}
// else...
// XXX The OBJ_IS_NOT_GLOBAL here is not really right. In
// fact, this code is depending on the fact that the
// global object will not have been collected, and
// therefore this NativeInterface2JSObject will not end up
// creating a new XPCNativeScriptableShared.
xpcObjectHelper helper(iface);
if (!NativeInterface2JSObject(lccx, d, nsnull, helper, iid,
nsnull, true,
OBJ_IS_NOT_GLOBAL, pErr))
nsnull, true, pErr))
return false;
#ifdef DEBUG
@ -876,7 +869,6 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
const nsID* iid,
XPCNativeInterface** Interface,
bool allowNativeWrapper,
bool isGlobal,
nsresult* pErr)
{
NS_ASSERTION(!Interface || iid,
@ -1016,7 +1008,6 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
return false;
rv = XPCWrappedNative::GetNewOrUsed(ccx, aHelper, xpcscope, iface,
isGlobal,
getter_AddRefs(strongWrapper));
wrapper = strongWrapper;

View File

@ -622,7 +622,6 @@ XPCNativeScriptableSharedMap::~XPCNativeScriptableSharedMap()
JSBool
XPCNativeScriptableSharedMap::GetNewOrUsed(uint32_t flags,
char* name,
bool isGlobal,
PRUint32 interfacesBitmap,
XPCNativeScriptableInfo* si)
{
@ -643,7 +642,7 @@ XPCNativeScriptableSharedMap::GetNewOrUsed(uint32_t flags,
interfacesBitmap);
if (!shared)
return false;
shared->PopulateJSClass(isGlobal);
shared->PopulateJSClass();
}
si->SetScriptableShared(shared);
return true;

View File

@ -580,8 +580,8 @@ public:
static XPCNativeScriptableSharedMap* newMap(int size);
JSBool GetNewOrUsed(uint32_t flags, char* name, bool isGlobal,
PRUint32 interfacesBitmap, XPCNativeScriptableInfo* si);
JSBool GetNewOrUsed(uint32_t flags, char* name, PRUint32 interfacesBitmap,
XPCNativeScriptableInfo* si);
inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Enumerate(JSDHashEnumerator f, void *arg)

View File

@ -1111,16 +1111,10 @@ xpc_qsXPCOMObjectToJsval(XPCLazyCallContext &lccx, qsObjectHelper &aHelper,
JSContext *cx = lccx.GetJSContext();
// XXX The OBJ_IS_NOT_GLOBAL here is not really right. In
// fact, this code is depending on the fact that the
// global object will not have been collected, and
// therefore this NativeInterface2JSObject will not end up
// creating a new XPCNativeScriptableShared.
nsresult rv;
if (!XPCConvert::NativeInterface2JSObject(lccx, rval, nsnull,
aHelper, iid, iface,
true, OBJ_IS_NOT_GLOBAL, &rv)) {
true, &rv)) {
// I can't tell if NativeInterface2JSObject throws JS exceptions
// or not. This is a sloppy stab at the right semantics; the
// method really ought to be fixed to behave consistently.

View File

@ -1315,8 +1315,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
JSBool ok =
XPCConvert::NativeInterface2JSObject(ccx,
&v, nsnull, helper, newWrapperIID,
nsnull, false, false,
nsnull);
nsnull, false, nsnull);
if (newWrapperIID)
nsMemory::Free(newWrapperIID);
if (!ok) {

View File

@ -331,7 +331,6 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
xpcObjectHelper& helper,
XPCWrappedNativeScope* Scope,
XPCNativeInterface* Interface,
JSBool isGlobal,
XPCWrappedNative** resultWrapper)
{
nsWrapperCache *cache = helper.GetWrapperCache();
@ -452,8 +451,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
XPCWrappedNativeScope* betterScope =
XPCWrappedNativeScope::FindInJSObjectScope(ccx, parent);
if (betterScope != Scope)
return GetNewOrUsed(ccx, helper, betterScope, Interface,
isGlobal, resultWrapper);
return GetNewOrUsed(ccx, helper, betterScope, Interface, resultWrapper);
newParentVal = OBJECT_TO_JSVAL(parent);
}
@ -522,7 +520,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
// wrapper is actually created, but before JS code can see it.
if (info && !isClassInfo) {
proto = XPCWrappedNativeProto::GetNewOrUsed(ccx, Scope, info, &sciProto, isGlobal);
proto = XPCWrappedNativeProto::GetNewOrUsed(ccx, Scope, info, &sciProto);
if (!proto)
return NS_ERROR_FAILURE;
@ -558,7 +556,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
NS_ASSERTION(!xpc::WrapperFactory::IsXrayWrapper(parent),
"Xray wrapper being used to parent XPCWrappedNative?");
if (!wrapper->Init(ccx, parent, isGlobal, &sciWrapper)) {
if (!wrapper->Init(ccx, parent, &sciWrapper)) {
NS_RELEASE(wrapper);
return NS_ERROR_FAILURE;
}
@ -1062,8 +1060,7 @@ static PRUint32 sMorphedSlimWrappers;
#endif
JSBool
XPCWrappedNative::Init(XPCCallContext& ccx,
JSObject* parent, JSBool isGlobal,
XPCWrappedNative::Init(XPCCallContext& ccx, JSObject* parent,
const XPCNativeScriptableCreateInfo* sci)
{
// setup our scriptable info...
@ -1076,7 +1073,7 @@ XPCWrappedNative::Init(XPCCallContext& ccx,
}
if (!mScriptableInfo) {
mScriptableInfo =
XPCNativeScriptableInfo::Construct(ccx, isGlobal, sci);
XPCNativeScriptableInfo::Construct(ccx, sci);
if (!mScriptableInfo)
return false;
@ -1088,7 +1085,7 @@ XPCWrappedNative::Init(XPCCallContext& ccx,
JSClass* jsclazz = si ? si->GetJSClass() : Jsvalify(&XPC_WN_NoHelper_JSClass.base);
if (isGlobal) {
if (si && si->GetFlags().IsGlobalObject()) {
// Resolving a global object's class can cause us to create a global's
// JS class without the proper global flags. Notice that here and fix
// the problem.
@ -1458,9 +1455,7 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
newProto =
XPCWrappedNativeProto::GetNewOrUsed(ccx, aNewScope,
oldProto->GetClassInfo(),
&ci,
(info->GetJSClass()->flags & JSCLASS_IS_GLOBAL),
oldProto->GetOffsetsMasked());
&ci, oldProto->GetOffsetsMasked());
if (!newProto) {
return NS_ERROR_FAILURE;
}
@ -2999,9 +2994,7 @@ NS_IMETHODIMP XPCWrappedNative::RefreshPrototype()
XPCNativeScriptableInfo *info = oldProto->GetScriptableInfo();
XPCNativeScriptableCreateInfo ci(*info);
newProto = XPCWrappedNativeProto::GetNewOrUsed(ccx, oldProto->GetScope(),
oldProto->GetClassInfo(),
&ci,
(info->GetJSClass()->flags & JSCLASS_IS_GLOBAL),
oldProto->GetClassInfo(), &ci,
oldProto->GetOffsetsMasked());
if (!newProto)
return UnexpectedFailure(NS_ERROR_FAILURE);
@ -3686,10 +3679,8 @@ ConstructSlimWrapper(XPCCallContext &ccx,
sciProto(aHelper.forgetXPCClassInfo(), flags, interfacesBitmap);
AutoMarkingWrappedNativeProtoPtr xpcproto(ccx);
JSBool isGlobal = false;
xpcproto = XPCWrappedNativeProto::GetNewOrUsed(ccx, xpcScope,
classInfoHelper, &sciProto,
isGlobal);
classInfoHelper, &sciProto);
if (!xpcproto)
return false;

View File

@ -1349,7 +1349,6 @@ XPC_WN_JSOp_ThisObject(JSContext *cx, JSObject *obj)
// static
XPCNativeScriptableInfo*
XPCNativeScriptableInfo::Construct(XPCCallContext& ccx,
JSBool isGlobal,
const XPCNativeScriptableCreateInfo* sci)
{
NS_ASSERTION(sci, "bad param");
@ -1372,7 +1371,7 @@ XPCNativeScriptableInfo::Construct(XPCCallContext& ccx,
XPCNativeScriptableSharedMap* map = rt->GetNativeScriptableSharedMap();
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
success = map->GetNewOrUsed(sci->GetFlags(), name, isGlobal,
success = map->GetNewOrUsed(sci->GetFlags(), name,
sci->GetInterfacesBitmap(), newObj);
}
@ -1385,7 +1384,7 @@ XPCNativeScriptableInfo::Construct(XPCCallContext& ccx,
}
void
XPCNativeScriptableShared::PopulateJSClass(JSBool isGlobal)
XPCNativeScriptableShared::PopulateJSClass()
{
NS_ASSERTION(mJSClass.base.name, "bad state!");
@ -1393,7 +1392,7 @@ XPCNativeScriptableShared::PopulateJSClass(JSBool isGlobal)
JSCLASS_PRIVATE_IS_NSISUPPORTS |
JSCLASS_NEW_RESOLVE;
if (isGlobal)
if (mFlags.IsGlobalObject())
mJSClass.base.flags |= XPCONNECT_GLOBAL_FLAGS;
JSPropertyOp addProperty;

View File

@ -89,7 +89,6 @@ XPCWrappedNativeProto::~XPCWrappedNativeProto()
JSBool
XPCWrappedNativeProto::Init(XPCCallContext& ccx,
JSBool isGlobal,
const XPCNativeScriptableCreateInfo* scriptableCreateInfo)
{
nsIXPCScriptable *callback = scriptableCreateInfo ?
@ -97,7 +96,7 @@ XPCWrappedNativeProto::Init(XPCCallContext& ccx,
nsnull;
if (callback) {
mScriptableInfo =
XPCNativeScriptableInfo::Construct(ccx, isGlobal, scriptableCreateInfo);
XPCNativeScriptableInfo::Construct(ccx, scriptableCreateInfo);
if (!mScriptableInfo)
return false;
}
@ -195,7 +194,6 @@ XPCWrappedNativeProto::GetNewOrUsed(XPCCallContext& ccx,
XPCWrappedNativeScope* scope,
nsIClassInfo* classInfo,
const XPCNativeScriptableCreateInfo* scriptableCreateInfo,
JSBool isGlobal,
QITableEntry* offsets)
{
NS_ASSERTION(scope, "bad param");
@ -226,7 +224,7 @@ XPCWrappedNativeProto::GetNewOrUsed(XPCCallContext& ccx,
proto = new XPCWrappedNativeProto(scope, classInfo, ciFlags, set, offsets);
if (!proto || !proto->Init(ccx, isGlobal, scriptableCreateInfo)) {
if (!proto || !proto->Init(ccx, scriptableCreateInfo)) {
delete proto.get();
return nsnull;
}

View File

@ -106,17 +106,11 @@ static bool
XPCOMObjectToJsval(JSContext *cx, JSObject *scope, xpcObjectHelper &helper,
bool allowNativeWrapper, jsval *rval)
{
// XXX The OBJ_IS_NOT_GLOBAL here is not really right. In
// fact, this code is depending on the fact that the
// global object will not have been collected, and
// therefore this NativeInterface2JSObject will not end up
// creating a new XPCNativeScriptableShared.
XPCLazyCallContext lccx(JS_CALLER, cx, scope);
nsresult rv;
if (!XPCConvert::NativeInterface2JSObject(lccx, rval, NULL, helper, NULL, NULL,
allowNativeWrapper, OBJ_IS_NOT_GLOBAL, &rv)) {
allowNativeWrapper, &rv)) {
// I can't tell if NativeInterface2JSObject throws JS exceptions
// or not. This is a sloppy stab at the right semantics; the
// method really ought to be fixed to behave consistently.

View File

@ -1271,7 +1271,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
if (!XPCConvert::NativeInterface2JSObject(ccx, &v,
getter_AddRefs(holder),
helper, &NS_GET_IID(nsISupports), nsnull,
false, OBJ_IS_GLOBAL, &rv))
false, &rv))
return UnexpectedFailure(rv);
NS_ASSERTION(NS_SUCCEEDED(rv) && holder, "Didn't wrap properly");
@ -1372,8 +1372,7 @@ NativeInterface2JSObject(XPCLazyCallContext & lccx,
nsresult rv;
xpcObjectHelper helper(aCOMObj, aCache);
if (!XPCConvert::NativeInterface2JSObject(lccx, aVal, aHolder, helper, aIID,
nsnull, aAllowWrapping,
OBJ_IS_NOT_GLOBAL, &rv))
nsnull, aAllowWrapping, &rv))
return rv;
#ifdef DEBUG
@ -2120,8 +2119,7 @@ nsXPConnect::GetWrappedNativePrototype(JSContext * aJSContext,
XPCWrappedNative::GatherProtoScriptableCreateInfo(aClassInfo, sciProto);
AutoMarkingWrappedNativeProtoPtr proto(ccx);
proto = XPCWrappedNativeProto::GetNewOrUsed(ccx, scope, aClassInfo,
&sciProto, OBJ_IS_NOT_GLOBAL);
proto = XPCWrappedNativeProto::GetNewOrUsed(ccx, scope, aClassInfo, &sciProto);
if (!proto)
return UnexpectedFailure(NS_ERROR_FAILURE);

View File

@ -459,9 +459,6 @@ AddToCCKind(JSGCTraceKind kind)
return kind == JSTRACE_OBJECT || kind == JSTRACE_XML || kind == JSTRACE_SCRIPT;
}
const bool OBJ_IS_GLOBAL = true;
const bool OBJ_IS_NOT_GLOBAL = false;
class nsXPConnect : public nsIXPConnect,
public nsIThreadObserver,
public nsSupportsWeakReference,
@ -2076,7 +2073,7 @@ public:
{char* name=(char*)mJSClass.base.name; mJSClass.base.name = nsnull;
return name;}
void PopulateJSClass(JSBool isGlobal);
void PopulateJSClass();
void Mark() {mFlags.Mark();}
void Unmark() {mFlags.Unmark();}
@ -2096,8 +2093,7 @@ class XPCNativeScriptableInfo
{
public:
static XPCNativeScriptableInfo*
Construct(XPCCallContext& ccx, JSBool isGlobal,
const XPCNativeScriptableCreateInfo* sci);
Construct(XPCCallContext& ccx, const XPCNativeScriptableCreateInfo* sci);
nsIXPCScriptable*
GetCallback() const {return mCallback;}
@ -2208,7 +2204,6 @@ public:
XPCWrappedNativeScope* scope,
nsIClassInfo* classInfo,
const XPCNativeScriptableCreateInfo* scriptableCreateInfo,
JSBool isGlobal,
QITableEntry* offsets = UNKNOWN_OFFSETS);
XPCWrappedNativeScope*
@ -2336,7 +2331,7 @@ protected:
XPCNativeSet* Set,
QITableEntry* offsets);
JSBool Init(XPCCallContext& ccx, JSBool isGlobal,
JSBool Init(XPCCallContext& ccx,
const XPCNativeScriptableCreateInfo* scriptableCreateInfo);
private:
@ -2590,7 +2585,6 @@ public:
xpcObjectHelper& helper,
XPCWrappedNativeScope* Scope,
XPCNativeInterface* Interface,
JSBool isGlobal,
XPCWrappedNative** wrapper);
static nsresult
@ -2791,8 +2785,7 @@ private:
private:
JSBool Init(XPCCallContext& ccx, JSObject* parent, JSBool isGlobal,
const XPCNativeScriptableCreateInfo* sci);
JSBool Init(XPCCallContext& ccx, JSObject* parent, const XPCNativeScriptableCreateInfo* sci);
JSBool Init(XPCCallContext &ccx, JSObject *existingJSObject);
JSBool FinishInit(XPCCallContext &ccx);
@ -3278,7 +3271,6 @@ public:
* will be QI'ed to get the cache)
* @param allowNativeWrapper if true, this method may wrap the resulting
* JSObject in an XPCNativeWrapper and return that, as needed.
* @param isGlobal
* @param pErr [out] relevant error code, if any.
* @param src_is_identity optional performance hint. Set to true only
* if src is the identity pointer.
@ -3290,12 +3282,11 @@ public:
const nsID* iid,
XPCNativeInterface** Interface,
bool allowNativeWrapper,
bool isGlobal,
nsresult* pErr)
{
XPCLazyCallContext lccx(ccx);
return NativeInterface2JSObject(lccx, d, dest, aHelper, iid, Interface,
allowNativeWrapper, isGlobal, pErr);
allowNativeWrapper, pErr);
}
static JSBool NativeInterface2JSObject(XPCLazyCallContext& lccx,
jsval* d,
@ -3304,7 +3295,6 @@ public:
const nsID* iid,
XPCNativeInterface** Interface,
bool allowNativeWrapper,
bool isGlobal,
nsresult* pErr);
static JSBool GetNativeInterfaceFromJSObject(XPCCallContext& ccx,