summaryrefslogtreecommitdiffstats
path: root/dom/base/SerializedStackHolder.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/base/SerializedStackHolder.h
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/SerializedStackHolder.h')
-rw-r--r--dom/base/SerializedStackHolder.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/dom/base/SerializedStackHolder.h b/dom/base/SerializedStackHolder.h
new file mode 100644
index 0000000000..377f9c4f82
--- /dev/null
+++ b/dom/base/SerializedStackHolder.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_SerializedStackHolder_h
+#define mozilla_dom_SerializedStackHolder_h
+
+#include "mozilla/dom/StructuredCloneHolder.h"
+#include "mozilla/dom/WorkerRef.h"
+
+namespace mozilla {
+namespace dom {
+
+// Information about a main or worker thread stack trace that can be accessed
+// from either kind of thread. When a worker thread stack is serialized, the
+// worker is held alive until this holder is destroyed.
+class SerializedStackHolder {
+ // Holds any encoded stack data.
+ StructuredCloneHolder mHolder;
+
+ // The worker associated with this stack, or null if this is a main thread
+ // stack.
+ RefPtr<ThreadSafeWorkerRef> mWorkerRef;
+
+ // Write aStack's data into mHolder.
+ void WriteStack(JSContext* aCx, JS::HandleObject aStack);
+
+ public:
+ SerializedStackHolder();
+
+ // Fill this holder with a main or worklet thread stack.
+ void SerializeMainThreadOrWorkletStack(JSContext* aCx,
+ JS::HandleObject aStack);
+
+ // Fill this holder with a worker thread stack.
+ void SerializeWorkerStack(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
+ JS::HandleObject aStack);
+
+ // Fill this holder with the current thread's current stack.
+ void SerializeCurrentStack(JSContext* aCx);
+
+ // Read back a saved frame stack. This must be called on the main thread.
+ // This returns null on failure, and does not leave an exception on aCx.
+ JSObject* ReadStack(JSContext* aCx);
+};
+
+// Construct a stack for the current thread, which may be consumed by the net
+// monitor later on. This may be called on either the main or a worker thread.
+//
+// This always creates a stack, even if the net monitor isn't active for the
+// associated window. The net monitor will only be active if the associated
+// Browsing Context or worker's WatchedByDevTools flag is set, so this should
+// be checked before creating the stack.
+UniquePtr<SerializedStackHolder> GetCurrentStackForNetMonitor(JSContext* aCx);
+
+// If aStackHolder is non-null, this notifies the net monitor that aStackHolder
+// is the stack from which aChannel originates. This must be called on the main
+// thread. This call is synchronous, and aChannel and aStackHolder will not be
+// used afterward. aChannel is an nsISupports object because this can be used
+// with either nsIChannel or nsIWebSocketChannel.
+void NotifyNetworkMonitorAlternateStack(
+ nsISupports* aChannel, UniquePtr<SerializedStackHolder> aStackHolder);
+
+// Read back the saved frame stack and store it in a string as JSON.
+// This must be called on the main thread.
+void ConvertSerializedStackToJSON(UniquePtr<SerializedStackHolder> aStackHolder,
+ nsAString& aStackString);
+
+// As above, notify the net monitor for a stack that has already been converted
+// to JSON. This can be used with ConvertSerializedStackToJSON when multiple
+// notifications might be needed for a single stack.
+void NotifyNetworkMonitorAlternateStack(nsISupports* aChannel,
+ const nsAString& aStackJSON);
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_SerializedStackHolder_h