зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
db71e5ca7c
Коммит
13f064c989
|
@ -87,15 +87,15 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
|
||||||
holder->GetJSObject(&targetScriptObject);
|
holder->GetJSObject(&targetScriptObject);
|
||||||
|
|
||||||
JSContext *cx = context->GetNativeContext();
|
JSContext *cx = context->GetNativeContext();
|
||||||
|
JSAutoRequest ar(cx);
|
||||||
|
JSAutoCompartment ac(cx, targetClassObject);
|
||||||
AutoVersionChecker avc(cx);
|
AutoVersionChecker avc(cx);
|
||||||
|
|
||||||
// Walk our member list and install each one in turn.
|
// Walk our member list and install each one in turn.
|
||||||
for (nsXBLProtoImplMember* curr = mMembers;
|
for (nsXBLProtoImplMember* curr = mMembers;
|
||||||
curr;
|
curr;
|
||||||
curr = curr->GetNext())
|
curr = curr->GetNext())
|
||||||
curr->InstallMember(context, aBinding->GetBoundElement(), targetScriptObject,
|
curr->InstallMember(cx, targetClassObject);
|
||||||
targetClassObject, mClassName);
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,8 @@ public:
|
||||||
nsXBLProtoImplMember* GetNext() { return mNext; }
|
nsXBLProtoImplMember* GetNext() { return mNext; }
|
||||||
void SetNext(nsXBLProtoImplMember* aNext) { mNext = aNext; }
|
void SetNext(nsXBLProtoImplMember* aNext) { mNext = aNext; }
|
||||||
|
|
||||||
virtual nsresult InstallMember(nsIScriptContext* aContext,
|
virtual nsresult InstallMember(JSContext* aCx,
|
||||||
nsIContent* aBoundElement,
|
JSObject* aTargetClassObject) = 0;
|
||||||
JSObject* aScriptObject, // Unused
|
|
||||||
JSObject* aTargetClassObject,
|
|
||||||
const nsCString& aClassStr) = 0;
|
|
||||||
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
||||||
const nsCString& aClassStr,
|
const nsCString& aClassStr,
|
||||||
JSObject* aClassObject) = 0;
|
JSObject* aClassObject) = 0;
|
||||||
|
|
|
@ -92,40 +92,25 @@ nsXBLProtoImplMethod::SetLineNumber(uint32_t aLineNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsXBLProtoImplMethod::InstallMember(nsIScriptContext* aContext,
|
nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
|
||||||
nsIContent* aBoundElement,
|
JSObject* aTargetClassObject)
|
||||||
JSObject* aScriptObject,
|
|
||||||
JSObject* aTargetClassObject,
|
|
||||||
const nsCString& aClassStr)
|
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(IsCompiled(),
|
NS_PRECONDITION(IsCompiled(),
|
||||||
"Should not be installing an uncompiled method");
|
"Should not be installing an uncompiled method");
|
||||||
JSContext* cx = aContext->GetNativeContext();
|
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
||||||
|
|
||||||
nsIScriptGlobalObject* sgo = aBoundElement->OwnerDoc()->GetScopeObject();
|
JSObject* globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
// now we want to reevaluate our property using aContext and the script object for this window...
|
// now we want to reevaluate our property using aContext and the script object for this window...
|
||||||
if (mJSMethodObject) {
|
if (mJSMethodObject) {
|
||||||
nsDependentString name(mName);
|
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) {
|
if (!method) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!::JS_DefineUCProperty(cx, aTargetClassObject,
|
if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
|
||||||
static_cast<const jschar*>(mName),
|
static_cast<const jschar*>(mName),
|
||||||
name.Length(), OBJECT_TO_JSVAL(method),
|
name.Length(), OBJECT_TO_JSVAL(method),
|
||||||
NULL, NULL, JSPROP_ENUMERATE)) {
|
NULL, NULL, JSPROP_ENUMERATE)) {
|
||||||
|
|
|
@ -87,11 +87,8 @@ public:
|
||||||
|
|
||||||
void SetLineNumber(uint32_t aLineNumber);
|
void SetLineNumber(uint32_t aLineNumber);
|
||||||
|
|
||||||
virtual nsresult InstallMember(nsIScriptContext* aContext,
|
virtual nsresult InstallMember(JSContext* aCx,
|
||||||
nsIContent* aBoundElement,
|
JSObject* aTargetClassObject);
|
||||||
JSObject* aScriptObject,
|
|
||||||
JSObject* aTargetClassObject,
|
|
||||||
const nsCString& aClassStr);
|
|
||||||
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
||||||
const nsCString& aClassStr,
|
const nsCString& aClassStr,
|
||||||
JSObject* aClassObject);
|
JSObject* aClassObject);
|
||||||
|
@ -139,11 +136,8 @@ public:
|
||||||
// Override InstallMember; these methods never get installed as members on
|
// Override InstallMember; these methods never get installed as members on
|
||||||
// binding instantiations (though they may hang out in mMembers on the
|
// binding instantiations (though they may hang out in mMembers on the
|
||||||
// prototype implementation).
|
// prototype implementation).
|
||||||
virtual nsresult InstallMember(nsIScriptContext* aContext,
|
virtual nsresult InstallMember(JSContext* aCx,
|
||||||
nsIContent* aBoundElement,
|
JSObject* aTargetClassObject) {
|
||||||
JSObject* aScriptObject,
|
|
||||||
JSObject* aTargetClassObject,
|
|
||||||
const nsCString& aClassStr) {
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,45 +135,29 @@ nsXBLProtoImplProperty::SetSetterLineNumber(uint32_t aLineNumber)
|
||||||
const char* gPropertyArgs[] = { "val" };
|
const char* gPropertyArgs[] = { "val" };
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsXBLProtoImplProperty::InstallMember(nsIScriptContext* aContext,
|
nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
|
||||||
nsIContent* aBoundElement,
|
JSObject* aTargetClassObject)
|
||||||
JSObject* aScriptObject,
|
|
||||||
JSObject* aTargetClassObject,
|
|
||||||
const nsCString& aClassStr)
|
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(mIsCompiled,
|
NS_PRECONDITION(mIsCompiled,
|
||||||
"Should not be installing an uncompiled property");
|
"Should not be installing an uncompiled property");
|
||||||
JSContext* cx = aContext->GetNativeContext();
|
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
||||||
|
JSObject * globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
|
||||||
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();
|
|
||||||
|
|
||||||
// now we want to reevaluate our property using aContext and the script object for this window...
|
// now we want to reevaluate our property using aContext and the script object for this window...
|
||||||
if (mJSGetterObject || mJSSetterObject) {
|
if (mJSGetterObject || mJSSetterObject) {
|
||||||
JSObject * getter = nullptr;
|
JSObject * getter = nullptr;
|
||||||
JSAutoRequest ar(cx);
|
|
||||||
JSAutoCompartment ac(cx, globalObject);
|
|
||||||
|
|
||||||
if (mJSGetterObject)
|
if (mJSGetterObject)
|
||||||
if (!(getter = ::JS_CloneFunctionObject(cx, mJSGetterObject, globalObject)))
|
if (!(getter = ::JS_CloneFunctionObject(aCx, mJSGetterObject, globalObject)))
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
JSObject * setter = nullptr;
|
JSObject * setter = nullptr;
|
||||||
if (mJSSetterObject)
|
if (mJSSetterObject)
|
||||||
if (!(setter = ::JS_CloneFunctionObject(cx, mJSSetterObject, globalObject)))
|
if (!(setter = ::JS_CloneFunctionObject(aCx, mJSSetterObject, globalObject)))
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
nsDependentString name(mName);
|
nsDependentString name(mName);
|
||||||
if (!::JS_DefineUCProperty(cx, aTargetClassObject,
|
if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
|
||||||
static_cast<const jschar*>(mName),
|
static_cast<const jschar*>(mName),
|
||||||
name.Length(), JSVAL_VOID,
|
name.Length(), JSVAL_VOID,
|
||||||
JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter),
|
JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter),
|
||||||
|
|
|
@ -33,11 +33,8 @@ public:
|
||||||
void SetGetterLineNumber(uint32_t aLineNumber);
|
void SetGetterLineNumber(uint32_t aLineNumber);
|
||||||
void SetSetterLineNumber(uint32_t aLineNumber);
|
void SetSetterLineNumber(uint32_t aLineNumber);
|
||||||
|
|
||||||
virtual nsresult InstallMember(nsIScriptContext* aContext,
|
virtual nsresult InstallMember(JSContext* aCx,
|
||||||
nsIContent* aBoundElement,
|
JSObject* aTargetClassObject);
|
||||||
JSObject* aScriptObject,
|
|
||||||
JSObject* aTargetClassObject,
|
|
||||||
const nsCString& aClassStr);
|
|
||||||
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
||||||
const nsCString& aClassStr,
|
const nsCString& aClassStr,
|
||||||
JSObject* aClassObject);
|
JSObject* aClassObject);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче