зеркало из https://github.com/mozilla/gecko-dev.git
Bug 855411 - InstallMember. r=bz,terrence
This commit is contained in:
Родитель
5159d18b7a
Коммит
a463f6bb01
|
@ -67,7 +67,7 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
|
||||||
// This function also has the side effect of building up the prototype implementation if it has
|
// This function also has the side effect of building up the prototype implementation if it has
|
||||||
// not been built already.
|
// not been built already.
|
||||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||||
JSObject* targetClassObject = nullptr;
|
JS::Rooted<JSObject*> targetClassObject(context->GetNativeContext(), nullptr);
|
||||||
bool targetObjectIsNew = false;
|
bool targetObjectIsNew = false;
|
||||||
nsresult rv = InitTargetObjects(aPrototypeBinding, context,
|
nsresult rv = InitTargetObjects(aPrototypeBinding, context,
|
||||||
aBinding->GetBoundElement(),
|
aBinding->GetBoundElement(),
|
||||||
|
@ -83,8 +83,8 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
|
||||||
if (!targetObjectIsNew)
|
if (!targetObjectIsNew)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
JSObject * targetScriptObject;
|
JS::Rooted<JSObject*> targetScriptObject(context->GetNativeContext());
|
||||||
holder->GetJSObject(&targetScriptObject);
|
holder->GetJSObject(targetScriptObject.address());
|
||||||
|
|
||||||
AutoPushJSContext cx(context->GetNativeContext());
|
AutoPushJSContext cx(context->GetNativeContext());
|
||||||
JSAutoRequest ar(cx);
|
JSAutoRequest ar(cx);
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
const PRUnichar* GetName() { return mName; }
|
const PRUnichar* GetName() { return mName; }
|
||||||
|
|
||||||
virtual nsresult InstallMember(JSContext* aCx,
|
virtual nsresult InstallMember(JSContext* aCx,
|
||||||
JSObject* aTargetClassObject) = 0;
|
JS::Handle<JSObject*> aTargetClassObject) = 0;
|
||||||
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
||||||
const nsCString& aClassStr,
|
const nsCString& aClassStr,
|
||||||
JSObject* aClassObject) = 0;
|
JSObject* aClassObject) = 0;
|
||||||
|
|
|
@ -96,14 +96,14 @@ nsXBLProtoImplMethod::SetLineNumber(uint32_t aLineNumber)
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
|
nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
|
||||||
JSObject* aTargetClassObject)
|
JS::Handle<JSObject*> aTargetClassObject)
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(IsCompiled(),
|
NS_PRECONDITION(IsCompiled(),
|
||||||
"Should not be installing an uncompiled method");
|
"Should not be installing an uncompiled method");
|
||||||
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
||||||
|
|
||||||
JSObject* globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
|
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
|
||||||
JSObject* scopeObject = xpc::GetXBLScope(aCx, globalObject);
|
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...
|
// now we want to reevaluate our property using aContext and the script object for this window...
|
||||||
if (mJSMethodObject) {
|
if (mJSMethodObject) {
|
||||||
|
@ -111,7 +111,7 @@ nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
|
||||||
|
|
||||||
// First, make the function in the compartment of the scope object.
|
// First, make the function in the compartment of the scope object.
|
||||||
JSAutoCompartment ac(aCx, scopeObject);
|
JSAutoCompartment ac(aCx, scopeObject);
|
||||||
JSObject * method = ::JS_CloneFunctionObject(aCx, mJSMethodObject, scopeObject);
|
JS::Rooted<JSObject*> method(aCx, ::JS_CloneFunctionObject(aCx, mJSMethodObject, scopeObject));
|
||||||
if (!method) {
|
if (!method) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
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
|
// Then, enter the content compartment, wrap the method pointer, and define
|
||||||
// the wrapped version on the class object.
|
// the wrapped version on the class object.
|
||||||
JSAutoCompartment ac2(aCx, aTargetClassObject);
|
JSAutoCompartment ac2(aCx, aTargetClassObject);
|
||||||
if (!JS_WrapObject(aCx, &method) ||
|
if (!JS_WrapObject(aCx, method.address()))
|
||||||
!::JS_DefineUCProperty(aCx, aTargetClassObject,
|
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),
|
static_cast<const jschar*>(mName),
|
||||||
name.Length(), OBJECT_TO_JSVAL(method),
|
name.Length(), value,
|
||||||
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public:
|
||||||
void SetLineNumber(uint32_t aLineNumber);
|
void SetLineNumber(uint32_t aLineNumber);
|
||||||
|
|
||||||
virtual nsresult InstallMember(JSContext* aCx,
|
virtual nsresult InstallMember(JSContext* aCx,
|
||||||
JSObject* aTargetClassObject);
|
JS::Handle<JSObject*> aTargetClassObject);
|
||||||
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
||||||
const nsCString& aClassStr,
|
const nsCString& aClassStr,
|
||||||
JSObject* aClassObject);
|
JSObject* aClassObject);
|
||||||
|
@ -138,7 +138,7 @@ public:
|
||||||
// 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(JSContext* aCx,
|
virtual nsresult InstallMember(JSContext* aCx,
|
||||||
JSObject* aTargetClassObject) {
|
JS::Handle<JSObject*> aTargetClassObject) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,40 +140,42 @@ const char* gPropertyArgs[] = { "val" };
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
|
nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
|
||||||
JSObject* aTargetClassObject)
|
JS::Handle<JSObject*> aTargetClassObject)
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(mIsCompiled,
|
NS_PRECONDITION(mIsCompiled,
|
||||||
"Should not be installing an uncompiled property");
|
"Should not be installing an uncompiled property");
|
||||||
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
||||||
JSObject * globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
|
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
|
||||||
JSObject * scopeObject = xpc::GetXBLScope(aCx, globalObject);
|
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...
|
// 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;
|
|
||||||
|
|
||||||
// First, enter the compartment of the scope object and clone the functions.
|
// First, enter the compartment of the scope object and clone the functions.
|
||||||
JSAutoCompartment ac(aCx, scopeObject);
|
JSAutoCompartment ac(aCx, scopeObject);
|
||||||
if (mJSGetterObject)
|
|
||||||
|
JS::Rooted<JSObject*> getter(aCx, nullptr);
|
||||||
|
if (mJSGetterObject) {
|
||||||
if (!(getter = ::JS_CloneFunctionObject(aCx, mJSGetterObject, scopeObject)))
|
if (!(getter = ::JS_CloneFunctionObject(aCx, mJSGetterObject, scopeObject)))
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
JSObject * setter = nullptr;
|
JS::Rooted<JSObject*> setter(aCx, nullptr);
|
||||||
if (mJSSetterObject)
|
if (mJSSetterObject) {
|
||||||
if (!(setter = ::JS_CloneFunctionObject(aCx, mJSSetterObject, scopeObject)))
|
if (!(setter = ::JS_CloneFunctionObject(aCx, mJSSetterObject, scopeObject)))
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
// Now, enter the content compartment, wrap the getter/setter, and define
|
// Now, enter the content compartment, wrap the getter/setter, and define
|
||||||
// them on the class object.
|
// them on the class object.
|
||||||
JSAutoCompartment ac2(aCx, aTargetClassObject);
|
JSAutoCompartment ac2(aCx, aTargetClassObject);
|
||||||
nsDependentString name(mName);
|
nsDependentString name(mName);
|
||||||
if (!JS_WrapObject(aCx, &getter) ||
|
if (!JS_WrapObject(aCx, getter.address()) ||
|
||||||
!JS_WrapObject(aCx, &setter) ||
|
!JS_WrapObject(aCx, setter.address()) ||
|
||||||
!::JS_DefineUCProperty(aCx, aTargetClassObject,
|
!::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.get()),
|
||||||
JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter),
|
JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter.get()),
|
||||||
mJSAttributes))
|
mJSAttributes))
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
void SetSetterLineNumber(uint32_t aLineNumber);
|
void SetSetterLineNumber(uint32_t aLineNumber);
|
||||||
|
|
||||||
virtual nsresult InstallMember(JSContext* aCx,
|
virtual nsresult InstallMember(JSContext* aCx,
|
||||||
JSObject* aTargetClassObject);
|
JS::Handle<JSObject*> aTargetClassObject);
|
||||||
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
||||||
const nsCString& aClassStr,
|
const nsCString& aClassStr,
|
||||||
JSObject* aClassObject);
|
JSObject* aClassObject);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче