Bug 1350967 (part 1) - Remove profiler_get_profile_jsobject. r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 29 Mar 2017 14:02:37 +1100
changeset 400224 4483302f97a757145dca7dd5720a397d4f9b9246
parent 400223 4f5caf3ceda2973558a84e6054346d82d4555857
child 400225 a1e5043844f295aa8f9a70517b7b76e34fecc634
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1350967
milestone55.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 1350967 (part 1) - Remove profiler_get_profile_jsobject. r=mstange. The conversion to a JSObject is better done within nsProfiler::GetProfileData().
tools/profiler/core/platform.cpp
tools/profiler/gecko/nsProfiler.cpp
tools/profiler/public/GeckoProfiler.h
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -2142,45 +2142,16 @@ profiler_get_profile(double aSinceTime)
 
   if (!gPS->IsActive(lock)) {
     return nullptr;
   }
 
   return ToJSON(lock, aSinceTime);
 }
 
-JSObject*
-profiler_get_profile_jsobject(JSContext *aCx, double aSinceTime)
-{
-  LOG("profiler_get_profile_jsobject");
-
-  MOZ_RELEASE_ASSERT(NS_IsMainThread());
-  MOZ_RELEASE_ASSERT(gPS);
-
-  // |val| must outlive |lock| to avoid a GC hazard.
-  JS::RootedValue val(aCx);
-  UniquePtr<char[]> buf = nullptr;
-
-  {
-    PS::AutoLock lock(gPSMutex);
-
-    if (!gPS->IsActive(lock)) {
-      return nullptr;
-    }
-
-    buf = ToJSON(lock, aSinceTime);
-  }
-
-  NS_ConvertUTF8toUTF16 js_string(nsDependentCString(buf.get()));
-  auto buf16 = static_cast<const char16_t*>(js_string.get());
-  MOZ_ALWAYS_TRUE(JS_ParseJSON(aCx, buf16, js_string.Length(), &val));
-
-  return &val.toObject();
-}
-
 void
 profiler_get_profile_jsobject_async(double aSinceTime,
                                     mozilla::dom::Promise* aPromise)
 {
   LOG("profiler_get_profile_jsobject_async");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
--- a/tools/profiler/gecko/nsProfiler.cpp
+++ b/tools/profiler/gecko/nsProfiler.cpp
@@ -185,21 +185,28 @@ nsProfiler::DumpProfileToFile(const char
   profiler_save_profile_to_file(aFilename);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsProfiler::GetProfileData(double aSinceTime, JSContext* aCx,
                            JS::MutableHandle<JS::Value> aResult)
 {
-  JS::RootedObject obj(aCx, profiler_get_profile_jsobject(aCx, aSinceTime));
-  if (!obj) {
+  mozilla::UniquePtr<char[]> profile = profiler_get_profile(aSinceTime);
+  if (!profile) {
     return NS_ERROR_FAILURE;
   }
-  aResult.setObject(*obj);
+
+  NS_ConvertUTF8toUTF16 js_string(nsDependentCString(profile.get()));
+  auto profile16 = static_cast<const char16_t*>(js_string.get());
+
+  JS::RootedValue val(aCx);
+  MOZ_ALWAYS_TRUE(JS_ParseJSON(aCx, profile16, js_string.Length(), &val));
+
+  aResult.set(val);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsProfiler::GetProfileDataAsync(double aSinceTime, JSContext* aCx,
                                 nsISupports** aPromise)
 {
   MOZ_ASSERT(NS_IsMainThread());
--- a/tools/profiler/public/GeckoProfiler.h
+++ b/tools/profiler/public/GeckoProfiler.h
@@ -210,22 +210,16 @@ PROFILER_FUNC(bool profiler_feature_acti
 // active or not.
 PROFILER_FUNC_VOID(profiler_set_frame_number(int frameNumber))
 
 // Get the profile encoded as a JSON string. A no-op (returning nullptr) if the
 // profiler is inactive.
 PROFILER_FUNC(mozilla::UniquePtr<char[]> profiler_get_profile(double aSinceTime = 0),
               nullptr)
 
-// Get the profile encoded as a JSON object. A no-op (returning nullptr) if the
-// profiler is inactive.
-PROFILER_FUNC(JSObject* profiler_get_profile_jsobject(JSContext* aCx,
-                                                      double aSinceTime = 0),
-              nullptr)
-
 // Get the profile encoded as a JSON object, asynchronously. A no-op if the
 // profiler is inactive.
 PROFILER_FUNC_VOID(profiler_get_profile_jsobject_async(double aSinceTime = 0,
                                                        mozilla::dom::Promise* = 0))
 
 // Get the params used to start the profiler. Returns 0 and empty vectors (via
 // outparams) if the profile is inactive.
 PROFILER_FUNC_VOID(profiler_get_start_params(int* aEntrySize,