Bug 871316 - Fix rooting hazards in InfoObject; r=till

This commit is contained in:
Ehsan Akhgari 2013-05-12 18:29:53 -04:00
parent 39bb41d1c6
commit 18ffce777d

View File

@ -9,6 +9,7 @@
#define __mozilla_widget_GfxInfoCollector_h__ #define __mozilla_widget_GfxInfoCollector_h__
#include "jsapi.h" #include "jsapi.h"
#include "mozilla/Attributes.h"
namespace mozilla { namespace mozilla {
namespace widget { namespace widget {
@ -16,7 +17,7 @@ namespace widget {
/* this is handy wrapper around JSAPI to make it more pleasant to use. /* this is handy wrapper around JSAPI to make it more pleasant to use.
* We collect the JSAPI errors and so that callers don't need to */ * We collect the JSAPI errors and so that callers don't need to */
class InfoObject class MOZ_STACK_CLASS InfoObject
{ {
friend class GfxInfoBase; friend class GfxInfoBase;
@ -46,14 +47,14 @@ class InfoObject
} }
void DefineProperty(const char *name, const char *value) void DefineProperty(const char *name, const char *value)
{ {
nsAutoString string = NS_ConvertASCIItoUTF16(value); nsAutoString string = NS_ConvertASCIItoUTF16(value);
DefineProperty(name, string); DefineProperty(name, string);
} }
private: private:
// We need to ensure that this object lives on the stack so that GC sees it properly // We need to ensure that this object lives on the stack so that GC sees it properly
InfoObject(JSContext *aCx) : mCx(aCx), mOk(JS_TRUE) InfoObject(JSContext *aCx) : mCx(aCx), mObj(aCx), mOk(JS_TRUE)
{ {
mObj = JS_NewObject(mCx, NULL, NULL, NULL); mObj = JS_NewObject(mCx, NULL, NULL, NULL);
if (!mObj) if (!mObj)
@ -62,7 +63,7 @@ class InfoObject
InfoObject(InfoObject&); InfoObject(InfoObject&);
JSContext *mCx; JSContext *mCx;
JSObject *mObj; JS::Rooted<JSObject*> mObj;
JSBool mOk; JSBool mOk;
}; };