Bug 869784 - Fix rooting hazards in the profiler; r=BenWa,till
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 08 May 2013 20:21:37 -0400
changeset 138098 202d4048a8b8cb67ef2fd1143ca00bb95097273f
parent 138097 4e55b3a02970b5e28cf770abcdc6691e224f6670
child 138099 02f1eeef26139b5d4a0f86a5fc059c4622aa405d
push id3752
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 17:21:10 +0000
treeherdermozilla-aurora@1580544aef0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa, till
bugs869784
milestone23.0a1
Bug 869784 - Fix rooting hazards in the profiler; r=BenWa,till X-Git-Commit-ID: da732de921f64d9bd6ea028ed384d2d5c80de66f X-Mailer: git-send-email
tools/profiler/JSObjectBuilder.cpp
tools/profiler/JSObjectBuilder.h
--- a/tools/profiler/JSObjectBuilder.cpp
+++ b/tools/profiler/JSObjectBuilder.cpp
@@ -81,60 +81,61 @@ JSObjectBuilder::DefineProperty(JSCustom
 }
 
 void
 JSObjectBuilder::ArrayPush(JSCustomArray *aArray, int value)
 {
   if (!mOk)
     return;
 
-  JS::Value objval = INT_TO_JSVAL(value);
   uint32_t length;
   mOk = JS_GetArrayLength(mCx, (JSObject*)aArray, &length);
 
   if (!mOk)
     return;
 
+  JS::Value objval = INT_TO_JSVAL(value);
   mOk = JS_SetElement(mCx, (JSObject*)aArray, length, &objval);
 }
 
 void
 JSObjectBuilder::ArrayPush(JSCustomArray *aArray, const char *value)
 {
   if (!mOk)
     return;
 
-  JSString *string = JS_NewStringCopyN(mCx, value, strlen(value));
+  JS::RootedString string(mCx, JS_NewStringCopyN(mCx, value, strlen(value)));
   if (!string) {
     mOk = JS_FALSE;
     return;
   }
 
-  JS::Value objval = STRING_TO_JSVAL(string);
   uint32_t length;
   mOk = JS_GetArrayLength(mCx, (JSObject*)aArray, &length);
 
   if (!mOk)
     return;
 
+  JS::Value objval = STRING_TO_JSVAL(string);
   mOk = JS_SetElement(mCx, (JSObject*)aArray, length, &objval);
 }
 
 void
 JSObjectBuilder::ArrayPush(JSCustomArray *aArray, JSCustomObject *aObject)
 {
   if (!mOk)
     return;
 
-  JS::Value objval = OBJECT_TO_JSVAL((JSObject*)aObject); uint32_t length;
+  uint32_t length;
   mOk = JS_GetArrayLength(mCx, (JSObject*)aArray, &length);
 
   if (!mOk)
     return;
 
+  JS::Value objval = OBJECT_TO_JSVAL((JSObject*)aObject);
   mOk = JS_SetElement(mCx, (JSObject*)aArray, length, &objval);
 }
 
 JSCustomArray*
 JSObjectBuilder::CreateArray() {
   JSCustomArray *array = (JSCustomArray*)JS_NewArrayObject(mCx, 0, nullptr);
   if (!array)
     mOk = JS_FALSE;
--- a/tools/profiler/JSObjectBuilder.h
+++ b/tools/profiler/JSObjectBuilder.h
@@ -49,14 +49,13 @@ private:
     // has to provide a destructor in the object file that will call
     // operate delete in case there is a derived class since its
     // destructor wont know how to free this instance.
     abort();
   }
   void operator delete[](void*);
 
   JSContext *mCx;
-  JSObject *mObj;
   int mOk;
 };
 
 #endif