Bug 1546736 Part 3 - Only capture worker script and XHR stacks for net monitor when devtools are watching the worker, r=bzbarsky.
authorBrian Hackett <bhackett1024@gmail.com>
Wed, 08 May 2019 09:30:17 -1000
changeset 533034 134b0641a7aabf9f41a42678d74c497592b0fc49
parent 533033 a2f8435fe7ed425c770d4ee59143dada8aab143b
child 533035 6cd72bb81d8952d3b2ea8c8cd7cdcc9618d8e290
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1546736
milestone68.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 1546736 Part 3 - Only capture worker script and XHR stacks for net monitor when devtools are watching the worker, r=bzbarsky.
dom/base/SerializedStackHolder.cpp
dom/workers/WorkerPrivate.cpp
dom/workers/WorkerScope.cpp
dom/xhr/XMLHttpRequestWorker.cpp
--- a/dom/base/SerializedStackHolder.cpp
+++ b/dom/base/SerializedStackHolder.cpp
@@ -79,16 +79,19 @@ JSObject* SerializedStackHolder::ReadSta
 
   JS::RootedValue stackValue(aCx);
   mHolder.Read(xpc::CurrentNativeGlobal(aCx), aCx, &stackValue,
                IgnoreErrors());
   return stackValue.isObject() ? &stackValue.toObject() : nullptr;
 }
 
 UniquePtr<SerializedStackHolder> GetCurrentStackForNetMonitor(JSContext* aCx) {
+  MOZ_ASSERT_IF(!NS_IsMainThread(),
+                GetCurrentThreadWorkerPrivate()->IsWatchedByDevtools());
+
   UniquePtr<SerializedStackHolder> stack = MakeUnique<SerializedStackHolder>();
   stack->SerializeCurrentStack(aCx);
   return stack;
 }
 
 void NotifyNetworkMonitorAlternateStack(nsISupports* aChannel,
                                         UniquePtr<SerializedStackHolder> aStackHolder) {
   if (!aStackHolder) {
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -2253,17 +2253,20 @@ already_AddRefed<WorkerPrivate> WorkerPr
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
 
   worker->EnableDebugger();
 
   MOZ_DIAGNOSTIC_ASSERT(worker->PrincipalIsValid());
 
-  UniquePtr<SerializedStackHolder> stack = GetCurrentStackForNetMonitor(aCx);
+  UniquePtr<SerializedStackHolder> stack;
+  if (worker->IsWatchedByDevtools()) {
+    stack = GetCurrentStackForNetMonitor(aCx);
+  }
 
   RefPtr<CompileScriptRunnable> compiler =
       new CompileScriptRunnable(worker, std::move(stack), aScriptURL);
   if (!compiler->Dispatch()) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
 
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -235,17 +235,20 @@ void WorkerGlobalScope::SetOnerror(OnErr
   }
 }
 
 void WorkerGlobalScope::ImportScripts(JSContext* aCx,
                                       const Sequence<nsString>& aScriptURLs,
                                       ErrorResult& aRv) {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
-  UniquePtr<SerializedStackHolder> stack = GetCurrentStackForNetMonitor(aCx);
+  UniquePtr<SerializedStackHolder> stack;
+  if (mWorkerPrivate->IsWatchedByDevtools()) {
+    stack = GetCurrentStackForNetMonitor(aCx);
+  }
 
   workerinternals::Load(mWorkerPrivate, std::move(stack), aScriptURLs,
                         WorkerScript, aRv);
 }
 
 int32_t WorkerGlobalScope::SetTimeout(JSContext* aCx, Function& aHandler,
                                       const int32_t aTimeout,
                                       const Sequence<JS::Value>& aArguments,
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -1783,18 +1783,20 @@ void XMLHttpRequestWorker::Open(const ns
     mProxy = new Proxy(this, clientInfo.ref(), mWorkerPrivate->GetController(),
                        mMozAnon, mMozSystem);
     alsoOverrideMimeType = true;
   }
 
   mProxy->mOuterEventStreamId++;
 
   UniquePtr<SerializedStackHolder> stack;
-  if (JSContext* cx = nsContentUtils::GetCurrentJSContext()) {
-    stack = GetCurrentStackForNetMonitor(cx);
+  if (mWorkerPrivate->IsWatchedByDevtools()) {
+    if (JSContext* cx = nsContentUtils::GetCurrentJSContext()) {
+      stack = GetCurrentStackForNetMonitor(cx);
+    }
   }
 
   RefPtr<OpenRunnable> runnable = new OpenRunnable(
       mWorkerPrivate, mProxy, aMethod, aUrl, aUser, aPassword,
       mBackgroundRequest, mWithCredentials, mTimeout, mResponseType,
       alsoOverrideMimeType ? mMimeTypeOverride : VoidString(),
       std::move(stack));