Bug 1484389 - Move various SavedFrame-related functions and data types into js/public/SavedFrameAPI.h so that users aren't forced to depend on jsapi.h or jsfriendapi.h for them. r=jandem
authorJeff Walden <jwalden@mit.edu>
Mon, 20 Aug 2018 07:45:44 -0700
changeset 487637 8e8b440d0128d4bb43445603137cb7575ede027b
parent 487636 cd604eaf33010f3a8b31b6f63669321c5fe0d92d
child 487638 67d5039dcbc2522e187bcf3dbec1c6e92bd32167
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1484389
milestone63.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 1484389 - Move various SavedFrame-related functions and data types into js/public/SavedFrameAPI.h so that users aren't forced to depend on jsapi.h or jsfriendapi.h for them. r=jandem
devtools/shared/heapsnapshot/tests/gtest/DeserializedStackFrameUbiStackFrames.cpp
dom/base/ChromeUtils.cpp
dom/bindings/Exceptions.cpp
js/public/SavedFrameAPI.h
js/src/jsapi-tests/testSavedStacks.cpp
js/src/jsapi.h
js/src/jsfriendapi.h
js/src/moz.build
js/src/vm/SavedStacks.cpp
js/xpconnect/src/XPCComponents.cpp
--- a/devtools/shared/heapsnapshot/tests/gtest/DeserializedStackFrameUbiStackFrames.cpp
+++ b/devtools/shared/heapsnapshot/tests/gtest/DeserializedStackFrameUbiStackFrames.cpp
@@ -3,16 +3,17 @@
  * 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/. */
 
 // Test that the `JS::ubi::StackFrame`s we create from
 // `mozilla::devtools::DeserializedStackFrame` instances look and behave as we would
 // like.
 
 #include "DevTools.h"
+#include "js/SavedFrameAPI.h"
 #include "js/TypeDecls.h"
 #include "mozilla/devtools/DeserializedNode.h"
 
 using testing::Field;
 using testing::ReturnRef;
 
 // A mock DeserializedStackFrame for testing.
 struct MockDeserializedStackFrame : public DeserializedStackFrame
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -1,16 +1,17 @@
 /* -*- 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/. */
 
 #include "ChromeUtils.h"
 
+#include "js/SavedFrameAPI.h"
 #include "jsfriendapi.h"
 #include "WrapperFactory.h"
 
 #include "mozilla/Base64.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/CycleCollectedJSRuntime.h"
 #include "mozilla/PerformanceMetricsCollector.h"
 #include "mozilla/Preferences.h"
--- a/dom/bindings/Exceptions.cpp
+++ b/dom/bindings/Exceptions.cpp
@@ -4,16 +4,17 @@
  * 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/. */
 
 #include "mozilla/dom/Exceptions.h"
 
 #include "js/RootingAPI.h"
 #include "js/TypeDecls.h"
 #include "jsapi.h"
+#include "js/SavedFrameAPI.h"
 #include "mozilla/CycleCollectedJSContext.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "nsPIDOMWindow.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "XPCWrapper.h"
new file mode 100644
--- /dev/null
+++ b/js/public/SavedFrameAPI.h
@@ -0,0 +1,145 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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/. */
+
+/*
+ * Functions and types related to SavedFrame objects created by the Debugger
+ * API.
+ */
+
+#ifndef js_SavedFrameAPI_h
+#define js_SavedFrameAPI_h
+
+#include "jstypes.h" // JS_FRIEND_API, JS_PUBLIC_API
+
+#include "js/RootingAPI.h" // JS::Handle, JS::MutableHandle
+
+struct JSContext;
+class JSObject;
+struct JSPrincipals;
+
+namespace JS {
+
+/*
+ * Accessors for working with SavedFrame JSObjects
+ *
+ * Each of these functions assert that if their `HandleObject savedFrame`
+ * argument is non-null, its JSClass is the SavedFrame class (or it is a
+ * cross-compartment or Xray wrapper around an object with the SavedFrame class)
+ * and the object is not the SavedFrame.prototype object.
+ *
+ * Each of these functions will find the first SavedFrame object in the chain
+ * whose underlying stack frame principals are subsumed by the given
+ * |principals|, and operate on that SavedFrame object. This prevents leaking
+ * information about privileged frames to un-privileged callers
+ *
+ * The SavedFrame in parameters do _NOT_ need to be in the same compartment as
+ * the cx, and the various out parameters are _NOT_ guaranteed to be in the same
+ * compartment as cx.
+ *
+ * You may consider or skip over self-hosted frames by passing
+ * `SavedFrameSelfHosted::Include` or `SavedFrameSelfHosted::Exclude`
+ * respectively.
+ *
+ * Additionally, it may be the case that there is no such SavedFrame object
+ * whose captured frame's principals are subsumed by |principals|! If the
+ * `HandleObject savedFrame` argument is null, or the |principals| do not
+ * subsume any of the chained SavedFrame object's principals,
+ * `SavedFrameResult::AccessDenied` is returned and a (hopefully) sane default
+ * value is chosen for the out param.
+ *
+ * See also `js/src/doc/SavedFrame/SavedFrame.md`.
+ */
+
+enum class SavedFrameResult {
+    Ok,
+    AccessDenied
+};
+
+enum class SavedFrameSelfHosted {
+    Include,
+    Exclude
+};
+
+/**
+ * Given a SavedFrame JSObject, get its source property. Defaults to the empty
+ * string.
+ */
+extern JS_PUBLIC_API(SavedFrameResult)
+GetSavedFrameSource(JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
+                    MutableHandle<JSString*> sourcep,
+                    SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
+
+/**
+ * Given a SavedFrame JSObject, get its line property. Defaults to 0.
+ */
+extern JS_PUBLIC_API(SavedFrameResult)
+GetSavedFrameLine(JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
+                  uint32_t* linep,
+                  SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
+
+/**
+ * Given a SavedFrame JSObject, get its column property. Defaults to 0.
+ */
+extern JS_PUBLIC_API(SavedFrameResult)
+GetSavedFrameColumn(JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
+                    uint32_t* columnp,
+                    SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
+
+/**
+ * Given a SavedFrame JSObject, get its functionDisplayName string, or nullptr
+ * if SpiderMonkey was unable to infer a name for the captured frame's
+ * function. Defaults to nullptr.
+ */
+extern JS_PUBLIC_API(SavedFrameResult)
+GetSavedFrameFunctionDisplayName(JSContext* cx, JSPrincipals* principals,
+                                 Handle<JSObject*> savedFrame,
+                                 MutableHandle<JSString*> namep,
+                                 SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
+
+/**
+ * Given a SavedFrame JSObject, get its asyncCause string. Defaults to nullptr.
+ */
+extern JS_PUBLIC_API(SavedFrameResult)
+GetSavedFrameAsyncCause(JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
+                        MutableHandle<JSString*> asyncCausep,
+                        SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
+
+/**
+ * Given a SavedFrame JSObject, get its asyncParent SavedFrame object or nullptr
+ * if there is no asyncParent. The `asyncParentp` out parameter is _NOT_
+ * guaranteed to be in the cx's compartment. Defaults to nullptr.
+ */
+extern JS_PUBLIC_API(SavedFrameResult)
+GetSavedFrameAsyncParent(JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
+                         MutableHandle<JSObject*> asyncParentp,
+                         SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
+
+/**
+ * Given a SavedFrame JSObject, get its parent SavedFrame object or nullptr if
+ * it is the oldest frame in the stack. The `parentp` out parameter is _NOT_
+ * guaranteed to be in the cx's compartment. Defaults to nullptr.
+ */
+extern JS_PUBLIC_API(SavedFrameResult)
+GetSavedFrameParent(JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
+                    MutableHandle<JSObject*> parentp,
+                    SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
+
+} // namespace JS
+
+namespace js {
+
+/**
+ * Get the first SavedFrame object in this SavedFrame stack whose principals are
+ * subsumed by the given |principals|. If there is no such frame, return nullptr.
+ *
+ * Do NOT pass a non-SavedFrame object here.
+ */
+extern JS_FRIEND_API(JSObject*)
+GetFirstSubsumedSavedFrame(JSContext* cx, JSPrincipals* principals,
+                           JS::Handle<JSObject*> savedFrame, JS::SavedFrameSelfHosted selfHosted);
+
+} // namespace js
+
+#endif /* js_SavedFrameAPI_h */
--- a/js/src/jsapi-tests/testSavedStacks.cpp
+++ b/js/src/jsapi-tests/testSavedStacks.cpp
@@ -3,16 +3,17 @@
  * 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/. */
 
 #include "jsfriendapi.h"
 #include "builtin/String.h"
 
 #include "builtin/TestingFunctions.h"
+#include "js/SavedFrameAPI.h"
 #include "jsapi-tests/tests.h"
 #include "vm/ArrayObject.h"
 #include "vm/Realm.h"
 #include "vm/SavedStacks.h"
 
 BEGIN_TEST(testSavedStacks_withNoStack)
 {
     JS::Realm* realm = cx->realm();
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -5975,120 +5975,16 @@ CaptureCurrentStack(JSContext* cx, Mutab
  * new stack object is written to |stackp|.  Returns true on success,
  * or sets an exception and returns |false| on error.
  */
 extern JS_PUBLIC_API(bool)
 CopyAsyncStack(JSContext* cx, HandleObject asyncStack,
                HandleString asyncCause, MutableHandleObject stackp,
                const mozilla::Maybe<size_t>& maxFrameCount);
 
-/*
- * Accessors for working with SavedFrame JSObjects
- *
- * Each of these functions assert that if their `HandleObject savedFrame`
- * argument is non-null, its JSClass is the SavedFrame class (or it is a
- * cross-compartment or Xray wrapper around an object with the SavedFrame class)
- * and the object is not the SavedFrame.prototype object.
- *
- * Each of these functions will find the first SavedFrame object in the chain
- * whose underlying stack frame principals are subsumed by the given
- * |principals|, and operate on that SavedFrame object. This prevents leaking
- * information about privileged frames to un-privileged callers
- *
- * The SavedFrame in parameters do _NOT_ need to be in the same compartment as
- * the cx, and the various out parameters are _NOT_ guaranteed to be in the same
- * compartment as cx.
- *
- * You may consider or skip over self-hosted frames by passing
- * `SavedFrameSelfHosted::Include` or `SavedFrameSelfHosted::Exclude`
- * respectively.
- *
- * Additionally, it may be the case that there is no such SavedFrame object
- * whose captured frame's principals are subsumed by |principals|! If the
- * `HandleObject savedFrame` argument is null, or the |principals| do not
- * subsume any of the chained SavedFrame object's principals,
- * `SavedFrameResult::AccessDenied` is returned and a (hopefully) sane default
- * value is chosen for the out param.
- *
- * See also `js/src/doc/SavedFrame/SavedFrame.md`.
- */
-
-enum class SavedFrameResult {
-    Ok,
-    AccessDenied
-};
-
-enum class SavedFrameSelfHosted {
-    Include,
-    Exclude
-};
-
-/**
- * Given a SavedFrame JSObject, get its source property. Defaults to the empty
- * string.
- */
-extern JS_PUBLIC_API(SavedFrameResult)
-GetSavedFrameSource(JSContext* cx, JSPrincipals* principals, HandleObject savedFrame,
-                    MutableHandleString sourcep,
-                    SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
-
-/**
- * Given a SavedFrame JSObject, get its line property. Defaults to 0.
- */
-extern JS_PUBLIC_API(SavedFrameResult)
-GetSavedFrameLine(JSContext* cx, JSPrincipals* principals, HandleObject savedFrame,
-                  uint32_t* linep,
-                  SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
-
-/**
- * Given a SavedFrame JSObject, get its column property. Defaults to 0.
- */
-extern JS_PUBLIC_API(SavedFrameResult)
-GetSavedFrameColumn(JSContext* cx, JSPrincipals* principals, HandleObject savedFrame,
-                    uint32_t* columnp,
-                    SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
-
-/**
- * Given a SavedFrame JSObject, get its functionDisplayName string, or nullptr
- * if SpiderMonkey was unable to infer a name for the captured frame's
- * function. Defaults to nullptr.
- */
-extern JS_PUBLIC_API(SavedFrameResult)
-GetSavedFrameFunctionDisplayName(JSContext* cx, JSPrincipals* principals, HandleObject savedFrame,
-                                 MutableHandleString namep,
-                                 SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
-
-/**
- * Given a SavedFrame JSObject, get its asyncCause string. Defaults to nullptr.
- */
-extern JS_PUBLIC_API(SavedFrameResult)
-GetSavedFrameAsyncCause(JSContext* cx, JSPrincipals* principals, HandleObject savedFrame,
-                        MutableHandleString asyncCausep,
-                        SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
-
-/**
- * Given a SavedFrame JSObject, get its asyncParent SavedFrame object or nullptr
- * if there is no asyncParent. The `asyncParentp` out parameter is _NOT_
- * guaranteed to be in the cx's compartment. Defaults to nullptr.
- */
-extern JS_PUBLIC_API(SavedFrameResult)
-GetSavedFrameAsyncParent(JSContext* cx, JSPrincipals* principals, HandleObject savedFrame,
-                         MutableHandleObject asyncParentp,
-                         SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
-
-/**
- * Given a SavedFrame JSObject, get its parent SavedFrame object or nullptr if
- * it is the oldest frame in the stack. The `parentp` out parameter is _NOT_
- * guaranteed to be in the cx's compartment. Defaults to nullptr.
- */
-extern JS_PUBLIC_API(SavedFrameResult)
-GetSavedFrameParent(JSContext* cx, JSPrincipals* principals, HandleObject savedFrame,
-                    MutableHandleObject parentp,
-                    SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
-
 /**
  * Given a SavedFrame JSObject stack, stringify it in the same format as
  * Error.prototype.stack. The stringified stack out parameter is placed in the
  * cx's compartment. Defaults to the empty string.
  *
  * The same notes above about SavedFrame accessors applies here as well: cx
  * doesn't need to be in stack's compartment, and stack can be null, a
  * SavedFrame object, or a wrapper (CCW or Xray) around a SavedFrame object.
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -2797,25 +2797,16 @@ typedef long
  *
  * Gecko must call SetJitExceptionFilter before any JIT code is compiled and
  * only once per process.
  */
 extern JS_FRIEND_API(void)
 SetJitExceptionHandler(JitExceptionHandler handler);
 #endif
 
-/**
- * Get the first SavedFrame object in this SavedFrame stack whose principals are
- * subsumed by the given |principals|. If there is no such frame, return nullptr.
- *
- * Do NOT pass a non-SavedFrame object here.
- */
-extern JS_FRIEND_API(JSObject*)
-GetFirstSubsumedSavedFrame(JSContext* cx, JSPrincipals* principals, JS::HandleObject savedFrame, JS::SavedFrameSelfHosted selfHosted);
-
 extern JS_FRIEND_API(bool)
 ReportIsNotFunction(JSContext* cx, JS::HandleValue v);
 
 extern JS_FRIEND_API(JSObject*)
 ConvertArgsToArray(JSContext* cx, const JS::CallArgs& args);
 
 /**
  * Window and WindowProxy
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -150,16 +150,17 @@ EXPORTS.js += [
     '../public/ProfilingStack.h',
     '../public/ProtoKey.h',
     '../public/Proxy.h',
     '../public/Realm.h',
     '../public/RefCounted.h',
     '../public/RequiredDefines.h',
     '../public/Result.h',
     '../public/RootingAPI.h',
+    '../public/SavedFrameAPI.h',
     '../public/SliceBudget.h',
     '../public/StableStringChars.h',
     '../public/Stream.h',
     '../public/StructuredClone.h',
     '../public/SweepingAPI.h',
     '../public/TraceKind.h',
     '../public/TracingAPI.h',
     '../public/TrackedOptimizationInfo.h',
--- a/js/src/vm/SavedStacks.cpp
+++ b/js/src/vm/SavedStacks.cpp
@@ -20,16 +20,17 @@
 #include "jsnum.h"
 
 #include "gc/FreeOp.h"
 #include "gc/HashUtil.h"
 #include "gc/Marking.h"
 #include "gc/Policy.h"
 #include "gc/Rooting.h"
 #include "js/CharacterEncoding.h"
+#include "js/SavedFrameAPI.h"
 #include "js/Vector.h"
 #include "util/StringBuffer.h"
 #include "vm/Debugger.h"
 #include "vm/GeckoProfiler.h"
 #include "vm/JSScript.h"
 #include "vm/Realm.h"
 #include "vm/SavedFrame.h"
 #include "vm/Time.h"
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -10,16 +10,17 @@
 #include "xpc_make_class.h"
 #include "XPCJSWeakReference.h"
 #include "WrapperFactory.h"
 #include "nsJSUtils.h"
 #include "mozJSComponentLoader.h"
 #include "nsContentUtils.h"
 #include "nsCycleCollector.h"
 #include "jsfriendapi.h"
+#include "js/SavedFrameAPI.h"
 #include "js/StructuredClone.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
 #include "mozilla/Preferences.h"
 #include "nsJSEnvironment.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/ResultExtensions.h"
 #include "mozilla/URLPreloader.h"