Bug 855411 - InstallMember. r=bz,terrence

This commit is contained in:
Tom Schuster 2013-04-05 15:21:02 +02:00
Родитель 5159d18b7a
Коммит a463f6bb01
6 изменённых файлов: 33 добавлений и 28 удалений

Просмотреть файл

@ -67,7 +67,7 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
// This function also has the side effect of building up the prototype implementation if it has
// not been built already.
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
JSObject* targetClassObject = nullptr;
JS::Rooted<JSObject*> targetClassObject(context->GetNativeContext(), nullptr);
bool targetObjectIsNew = false;
nsresult rv = InitTargetObjects(aPrototypeBinding, context,
aBinding->GetBoundElement(),
@ -83,8 +83,8 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
if (!targetObjectIsNew)
return NS_OK;
JSObject * targetScriptObject;
holder->GetJSObject(&targetScriptObject);
JS::Rooted<JSObject*> targetScriptObject(context->GetNativeContext());
holder->GetJSObject(targetScriptObject.address());
AutoPushJSContext cx(context->GetNativeContext());
JSAutoRequest ar(cx);

Просмотреть файл

@ -74,7 +74,7 @@ public:
const PRUnichar* GetName() { return mName; }
virtual nsresult InstallMember(JSContext* aCx,
JSObject* aTargetClassObject) = 0;
JS::Handle<JSObject*> aTargetClassObject) = 0;
virtual nsresult CompileMember(nsIScriptContext* aContext,
const nsCString& aClassStr,
JSObject* aClassObject) = 0;

Просмотреть файл

@ -96,14 +96,14 @@ nsXBLProtoImplMethod::SetLineNumber(uint32_t aLineNumber)
nsresult
nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
JSObject* aTargetClassObject)
JS::Handle<JSObject*> aTargetClassObject)
{
NS_PRECONDITION(IsCompiled(),
"Should not be installing an uncompiled method");
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
JSObject* globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
JSObject* scopeObject = xpc::GetXBLScope(aCx, globalObject);
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
JS::Rooted<JSObject*> scopeObject(aCx, xpc::GetXBLScope(aCx, globalObject));
// now we want to reevaluate our property using aContext and the script object for this window...
if (mJSMethodObject) {
@ -111,7 +111,7 @@ nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
// First, make the function in the compartment of the scope object.
JSAutoCompartment ac(aCx, scopeObject);
JSObject * method = ::JS_CloneFunctionObject(aCx, mJSMethodObject, scopeObject);
JS::Rooted<JSObject*> method(aCx, ::JS_CloneFunctionObject(aCx, mJSMethodObject, scopeObject));
if (!method) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -119,10 +119,13 @@ nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
// Then, enter the content compartment, wrap the method pointer, and define
// the wrapped version on the class object.
JSAutoCompartment ac2(aCx, aTargetClassObject);
if (!JS_WrapObject(aCx, &method) ||
!::JS_DefineUCProperty(aCx, aTargetClassObject,
if (!JS_WrapObject(aCx, method.address()))
return NS_ERROR_OUT_OF_MEMORY;
JS::Rooted<JS::Value> value(aCx, JS::ObjectValue(*method));
if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
static_cast<const jschar*>(mName),
name.Length(), OBJECT_TO_JSVAL(method),
name.Length(), value,
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_OUT_OF_MEMORY;
}

Просмотреть файл

@ -89,7 +89,7 @@ public:
void SetLineNumber(uint32_t aLineNumber);
virtual nsresult InstallMember(JSContext* aCx,
JSObject* aTargetClassObject);
JS::Handle<JSObject*> aTargetClassObject);
virtual nsresult CompileMember(nsIScriptContext* aContext,
const nsCString& aClassStr,
JSObject* aClassObject);
@ -138,7 +138,7 @@ public:
// binding instantiations (though they may hang out in mMembers on the
// prototype implementation).
virtual nsresult InstallMember(JSContext* aCx,
JSObject* aTargetClassObject) {
JS::Handle<JSObject*> aTargetClassObject) {
return NS_OK;
}

Просмотреть файл

@ -140,40 +140,42 @@ const char* gPropertyArgs[] = { "val" };
nsresult
nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
JSObject* aTargetClassObject)
JS::Handle<JSObject*> aTargetClassObject)
{
NS_PRECONDITION(mIsCompiled,
"Should not be installing an uncompiled property");
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
JSObject * globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
JSObject * scopeObject = xpc::GetXBLScope(aCx, globalObject);
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
JS::Rooted<JSObject*> scopeObject(aCx, xpc::GetXBLScope(aCx, globalObject));
// now we want to reevaluate our property using aContext and the script object for this window...
if (mJSGetterObject || mJSSetterObject) {
JSObject * getter = nullptr;
// First, enter the compartment of the scope object and clone the functions.
JSAutoCompartment ac(aCx, scopeObject);
if (mJSGetterObject)
JS::Rooted<JSObject*> getter(aCx, nullptr);
if (mJSGetterObject) {
if (!(getter = ::JS_CloneFunctionObject(aCx, mJSGetterObject, scopeObject)))
return NS_ERROR_OUT_OF_MEMORY;
}
JSObject * setter = nullptr;
if (mJSSetterObject)
JS::Rooted<JSObject*> setter(aCx, nullptr);
if (mJSSetterObject) {
if (!(setter = ::JS_CloneFunctionObject(aCx, mJSSetterObject, scopeObject)))
return NS_ERROR_OUT_OF_MEMORY;
}
// Now, enter the content compartment, wrap the getter/setter, and define
// them on the class object.
JSAutoCompartment ac2(aCx, aTargetClassObject);
nsDependentString name(mName);
if (!JS_WrapObject(aCx, &getter) ||
!JS_WrapObject(aCx, &setter) ||
if (!JS_WrapObject(aCx, getter.address()) ||
!JS_WrapObject(aCx, setter.address()) ||
!::JS_DefineUCProperty(aCx, aTargetClassObject,
static_cast<const jschar*>(mName),
name.Length(), JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter),
JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter),
JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter.get()),
JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter.get()),
mJSAttributes))
return NS_ERROR_OUT_OF_MEMORY;
}

Просмотреть файл

@ -33,7 +33,7 @@ public:
void SetSetterLineNumber(uint32_t aLineNumber);
virtual nsresult InstallMember(JSContext* aCx,
JSObject* aTargetClassObject);
JS::Handle<JSObject*> aTargetClassObject);
virtual nsresult CompileMember(nsIScriptContext* aContext,
const nsCString& aClassStr,
JSObject* aClassObject);