Bug 821850 - Remove unused arguments from InstallMember and simplify calling convention. r=bz

Let's just pass a JSContext and do Requests/Compartments in the caller.
This commit is contained in:
Bobby Holley 2013-02-08 14:24:21 +00:00
parent 61955f5559
commit a332edb8a1
6 changed files with 25 additions and 68 deletions

View File

@ -87,15 +87,15 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
holder->GetJSObject(&targetScriptObject);
JSContext *cx = context->GetNativeContext();
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, targetClassObject);
AutoVersionChecker avc(cx);
// Walk our member list and install each one in turn.
for (nsXBLProtoImplMember* curr = mMembers;
curr;
curr = curr->GetNext())
curr->InstallMember(context, aBinding->GetBoundElement(), targetScriptObject,
targetClassObject, mClassName);
curr->InstallMember(cx, targetClassObject);
return NS_OK;
}

View File

@ -71,11 +71,8 @@ public:
nsXBLProtoImplMember* GetNext() { return mNext; }
void SetNext(nsXBLProtoImplMember* aNext) { mNext = aNext; }
virtual nsresult InstallMember(nsIScriptContext* aContext,
nsIContent* aBoundElement,
JSObject* aScriptObject, // Unused
JSObject* aTargetClassObject,
const nsCString& aClassStr) = 0;
virtual nsresult InstallMember(JSContext* aCx,
JSObject* aTargetClassObject) = 0;
virtual nsresult CompileMember(nsIScriptContext* aContext,
const nsCString& aClassStr,
JSObject* aClassObject) = 0;

View File

@ -92,40 +92,25 @@ nsXBLProtoImplMethod::SetLineNumber(uint32_t aLineNumber)
}
nsresult
nsXBLProtoImplMethod::InstallMember(nsIScriptContext* aContext,
nsIContent* aBoundElement,
JSObject* aScriptObject,
JSObject* aTargetClassObject,
const nsCString& aClassStr)
nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
JSObject* aTargetClassObject)
{
NS_PRECONDITION(IsCompiled(),
"Should not be installing an uncompiled method");
JSContext* cx = aContext->GetNativeContext();
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
nsIScriptGlobalObject* sgo = aBoundElement->OwnerDoc()->GetScopeObject();
if (!sgo) {
return NS_ERROR_UNEXPECTED;
}
NS_ASSERTION(aScriptObject, "uh-oh, script Object should NOT be null or bad things will happen");
if (!aScriptObject)
return NS_ERROR_FAILURE;
JSObject* globalObject = sgo->GetGlobalJSObject();
JSObject* globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
// now we want to reevaluate our property using aContext and the script object for this window...
if (mJSMethodObject) {
nsDependentString name(mName);
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, globalObject);
JSObject * method = ::JS_CloneFunctionObject(cx, mJSMethodObject, globalObject);
JSObject * method = ::JS_CloneFunctionObject(aCx, mJSMethodObject, globalObject);
if (!method) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!::JS_DefineUCProperty(cx, aTargetClassObject,
if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
static_cast<const jschar*>(mName),
name.Length(), OBJECT_TO_JSVAL(method),
NULL, NULL, JSPROP_ENUMERATE)) {

View File

@ -87,11 +87,8 @@ public:
void SetLineNumber(uint32_t aLineNumber);
virtual nsresult InstallMember(nsIScriptContext* aContext,
nsIContent* aBoundElement,
JSObject* aScriptObject,
JSObject* aTargetClassObject,
const nsCString& aClassStr);
virtual nsresult InstallMember(JSContext* aCx,
JSObject* aTargetClassObject);
virtual nsresult CompileMember(nsIScriptContext* aContext,
const nsCString& aClassStr,
JSObject* aClassObject);
@ -139,11 +136,8 @@ public:
// Override InstallMember; these methods never get installed as members on
// binding instantiations (though they may hang out in mMembers on the
// prototype implementation).
virtual nsresult InstallMember(nsIScriptContext* aContext,
nsIContent* aBoundElement,
JSObject* aScriptObject,
JSObject* aTargetClassObject,
const nsCString& aClassStr) {
virtual nsresult InstallMember(JSContext* aCx,
JSObject* aTargetClassObject) {
return NS_OK;
}

View File

@ -135,45 +135,29 @@ nsXBLProtoImplProperty::SetSetterLineNumber(uint32_t aLineNumber)
const char* gPropertyArgs[] = { "val" };
nsresult
nsXBLProtoImplProperty::InstallMember(nsIScriptContext* aContext,
nsIContent* aBoundElement,
JSObject* aScriptObject,
JSObject* aTargetClassObject,
const nsCString& aClassStr)
nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
JSObject* aTargetClassObject)
{
NS_PRECONDITION(mIsCompiled,
"Should not be installing an uncompiled property");
JSContext* cx = aContext->GetNativeContext();
nsIScriptGlobalObject* sgo = aBoundElement->OwnerDoc()->GetScopeObject();
if (!sgo) {
return NS_ERROR_UNEXPECTED;
}
NS_ASSERTION(aScriptObject, "uh-oh, script Object should NOT be null or bad things will happen");
if (!aScriptObject)
return NS_ERROR_FAILURE;
JSObject * globalObject = sgo->GetGlobalJSObject();
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
JSObject * globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
// now we want to reevaluate our property using aContext and the script object for this window...
if (mJSGetterObject || mJSSetterObject) {
JSObject * getter = nullptr;
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, globalObject);
if (mJSGetterObject)
if (!(getter = ::JS_CloneFunctionObject(cx, mJSGetterObject, globalObject)))
if (!(getter = ::JS_CloneFunctionObject(aCx, mJSGetterObject, globalObject)))
return NS_ERROR_OUT_OF_MEMORY;
JSObject * setter = nullptr;
if (mJSSetterObject)
if (!(setter = ::JS_CloneFunctionObject(cx, mJSSetterObject, globalObject)))
if (!(setter = ::JS_CloneFunctionObject(aCx, mJSSetterObject, globalObject)))
return NS_ERROR_OUT_OF_MEMORY;
nsDependentString name(mName);
if (!::JS_DefineUCProperty(cx, aTargetClassObject,
if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
static_cast<const jschar*>(mName),
name.Length(), JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter),

View File

@ -33,11 +33,8 @@ public:
void SetGetterLineNumber(uint32_t aLineNumber);
void SetSetterLineNumber(uint32_t aLineNumber);
virtual nsresult InstallMember(nsIScriptContext* aContext,
nsIContent* aBoundElement,
JSObject* aScriptObject,
JSObject* aTargetClassObject,
const nsCString& aClassStr);
virtual nsresult InstallMember(JSContext* aCx,
JSObject* aTargetClassObject);
virtual nsresult CompileMember(nsIScriptContext* aContext,
const nsCString& aClassStr,
JSObject* aClassObject);