[Bug 866527] Fix ctypes rooting hazards r=terrence
authorDavid Zbarsky <dzbarsky@gmail.com>
Mon, 29 Apr 2013 14:25:53 -0400
changeset 141204 004679f2317bd5731029ba25d69a8ea93ce1724f
parent 141203 dbb499490f45e19a81c81b94d20ca64777b8bccf
child 141205 d8b7bf4c92231c843db488651568773f78b780e0
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs866527
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
[Bug 866527] Fix ctypes rooting hazards r=terrence
toolkit/components/ctypes/ctypes.cpp
--- a/toolkit/components/ctypes/ctypes.cpp
+++ b/toolkit/components/ctypes/ctypes.cpp
@@ -61,43 +61,43 @@ Module::~Module()
 #define XPC_MAP_QUOTED_CLASSNAME "Module"
 #define XPC_MAP_WANT_CALL
 #define XPC_MAP_FLAGS nsIXPCScriptable::WANT_CALL
 #include "xpc_map_end.h"
 
 static JSBool
 SealObjectAndPrototype(JSContext* cx, JSObject* parent, const char* name)
 {
-  JS::Value prop;
-  if (!JS_GetProperty(cx, parent, name, &prop))
+  JS::Rooted<JS::Value> prop(cx);
+  if (!JS_GetProperty(cx, parent, name, prop.address()))
     return false;
 
   if (prop.isUndefined()) {
     // Pretend we sealed the object.
     return true;
   }
 
-  JSObject* obj = JSVAL_TO_OBJECT(prop);
-  if (!JS_GetProperty(cx, obj, "prototype", &prop))
+  JS::Rooted<JSObject*> obj(cx, prop.toObjectOrNull());
+  if (!JS_GetProperty(cx, obj, "prototype", prop.address()))
     return false;
 
-  JSObject* prototype = JSVAL_TO_OBJECT(prop);
+  JS::Rooted<JSObject*> prototype(cx, prop.toObjectOrNull());
   return JS_FreezeObject(cx, obj) && JS_FreezeObject(cx, prototype);
 }
 
 static JSBool
-InitAndSealCTypesClass(JSContext* cx, JSObject* global)
+InitAndSealCTypesClass(JSContext* cx, JS::Handle<JSObject*> global)
 {
   // Init the ctypes object.
   if (!JS_InitCTypesClass(cx, global))
     return false;
 
   // Set callbacks for charset conversion and such.
-  JS::Value ctypes;
-  if (!JS_GetProperty(cx, global, "ctypes", &ctypes))
+  JS::Rooted<JS::Value> ctypes(cx);
+  if (!JS_GetProperty(cx, global, "ctypes", ctypes.address()))
     return false;
 
   JS_SetCTypesCallbacks(JSVAL_TO_OBJECT(ctypes), &sCallbacks);
 
   // Seal up Object, Function, Array and Error and their prototypes.  (This
   // single object instance is shared amongst everyone who imports the ctypes
   // module.)
   if (!SealObjectAndPrototype(cx, global, "Object") ||