Bug 865969 part 8. Fix rooting hazards in CallbackObject. r=ms2ger

This commit is contained in:
Boris Zbarsky 2013-05-03 19:29:09 -04:00
parent e8ede4855e
commit d058ab83b1
3 changed files with 11 additions and 9 deletions

View File

@ -35,7 +35,7 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(CallbackObject)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCallback)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
CallbackObject::CallSetup::CallSetup(JSObject* const aCallback,
CallbackObject::CallSetup::CallSetup(JS::Handle<JSObject*> aCallback,
ErrorResult& aRv,
ExceptionHandling aExceptionHandling)
: mCx(nullptr)
@ -191,9 +191,10 @@ CallbackObjectHolderBase::ToXPCOMCallback(CallbackObject* aCallback,
return nullptr;
}
JSObject* callback = aCallback->Callback();
SafeAutoJSContext cx;
JS::Rooted<JSObject*> callback(cx, aCallback->Callback());
JSAutoCompartment ac(cx, callback);
XPCCallContext ccx(NATIVE_CALLER, cx);
if (!ccx.IsValid()) {

View File

@ -121,7 +121,7 @@ protected:
* non-null.
*/
public:
CallSetup(JSObject* const aCallable, ErrorResult& aRv,
CallSetup(JS::Handle<JSObject*> aCallable, ErrorResult& aRv,
ExceptionHandling aExceptionHandling);
~CallSetup();
@ -341,12 +341,13 @@ public:
return nullptr;
}
JSObject* obj;
if (NS_FAILED(wrappedJS->GetJSObject(&obj)) || !obj) {
SafeAutoJSContext cx;
JS::Rooted<JSObject*> obj(cx);
if (NS_FAILED(wrappedJS->GetJSObject(obj.address())) || !obj) {
return nullptr;
}
SafeAutoJSContext cx;
JSAutoCompartment ac(cx, obj);
nsRefPtr<WebIDLCallbackT> newCallback = new WebIDLCallbackT(obj);

View File

@ -8858,7 +8858,7 @@ class CGCallback(CGClass):
argsWithoutThis = list(args)
args.insert(0, Argument("const T&", "thisObj"))
setupCall = ("CallSetup s(mCallback, aRv, aExceptionHandling);\n"
setupCall = ("CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling);\n"
"if (!s.GetContext()) {\n"
" aRv.Throw(NS_ERROR_UNEXPECTED);\n"
" return${errorReturn};\n"
@ -9132,7 +9132,7 @@ class CallbackMember(CGNativeMember):
# It's been done for us already
return ""
return string.Template(
"CallSetup s(mCallback, aRv, aExceptionHandling);\n"
"CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling);\n"
"JSContext* cx = s.GetContext();\n"
"if (!cx) {\n"
" aRv.Throw(NS_ERROR_UNEXPECTED);\n"