Bug 1022773 - Return value rooting for SPS, r=ehsan, a=abillings
☠☠ backed out by ee727fe51f06 ☠ ☠
authorSteve Fink <sfink@mozilla.com>
Wed, 25 Jun 2014 15:35:37 -0700
changeset 208628 232abc366696961be38064000c1f49c252d70796
parent 208627 cde190482d72217502f687f17a184e3b955ddf6b
child 208629 ee727fe51f064d134ed45376e59c6c72a654402d
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, abillings
bugs1022773
milestone32.0a2
Bug 1022773 - Return value rooting for SPS, r=ehsan, a=abillings
tools/profiler/ProfileEntry.cpp
tools/profiler/TableTicker.cpp
--- a/tools/profiler/ProfileEntry.cpp
+++ b/tools/profiler/ProfileEntry.cpp
@@ -476,20 +476,24 @@ void ThreadProfile::StreamJSObject(JSStr
     b.EndArray();
   b.EndObject();
 }
 
 JSObject* ThreadProfile::ToJSObject(JSContext *aCx)
 {
   JS::RootedValue val(aCx);
   std::stringstream ss;
-  JSStreamWriter b(ss);
-  StreamJSObject(b);
-  NS_ConvertUTF8toUTF16 js_string(nsDependentCString(ss.str().c_str()));
-  JS_ParseJSON(aCx, static_cast<const jschar*>(js_string.get()), js_string.Length(), &val);
+  {
+    // Define a scope to prevent a moving GC during ~JSStreamWriter from
+    // trashing the return value.
+    JSStreamWriter b(ss);
+    StreamJSObject(b);
+    NS_ConvertUTF8toUTF16 js_string(nsDependentCString(ss.str().c_str()));
+    JS_ParseJSON(aCx, static_cast<const jschar*>(js_string.get()), js_string.Length(), &val);
+  }
   return &val.toObject();
 }
 
 PseudoStack* ThreadProfile::GetPseudoStack()
 {
   return mPseudoStack;
 }
 
--- a/tools/profiler/TableTicker.cpp
+++ b/tools/profiler/TableTicker.cpp
@@ -165,20 +165,24 @@ void TableTicker::ToStreamAsJSON(std::os
   JSStreamWriter b(stream);
   StreamJSObject(b);
 }
 
 JSObject* TableTicker::ToJSObject(JSContext *aCx)
 {
   JS::RootedValue val(aCx);
   std::stringstream ss;
-  JSStreamWriter b(ss);
-  StreamJSObject(b);
-  NS_ConvertUTF8toUTF16 js_string(nsDependentCString(ss.str().c_str()));
-  JS_ParseJSON(aCx, static_cast<const jschar*>(js_string.get()), js_string.Length(), &val);
+  {
+    // Define a scope to prevent a moving GC during ~JSStreamWriter from
+    // trashing the return value.
+    JSStreamWriter b(ss);
+    StreamJSObject(b);
+    NS_ConvertUTF8toUTF16 js_string(nsDependentCString(ss.str().c_str()));
+    JS_ParseJSON(aCx, static_cast<const jschar*>(js_string.get()), js_string.Length(), &val);
+  }
   return &val.toObject();
 }
 
 struct SubprocessClosure {
   SubprocessClosure(JSStreamWriter *aWriter)
     : mWriter(aWriter)
   {}