LCOV - code coverage report
Current view: top level - js/xpconnect/src - xpcpublic.h (source / functions) Hit Total Coverage
Test: output.info Lines: 58 88 65.9 %
Date: 2018-08-07 16:42:27 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* vim: set ts=8 sts=4 et sw=4 tw=99: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef xpcpublic_h
       8             : #define xpcpublic_h
       9             : 
      10             : #include "jsapi.h"
      11             : #include "js/HeapAPI.h"
      12             : #include "js/GCAPI.h"
      13             : #include "js/Proxy.h"
      14             : 
      15             : #include "nsISupports.h"
      16             : #include "nsIURI.h"
      17             : #include "nsIPrincipal.h"
      18             : #include "nsIGlobalObject.h"
      19             : #include "nsPIDOMWindow.h"
      20             : #include "nsWrapperCache.h"
      21             : #include "nsString.h"
      22             : #include "nsTArray.h"
      23             : #include "mozilla/dom/JSSlots.h"
      24             : #include "mozilla/fallible.h"
      25             : #include "nsMathUtils.h"
      26             : #include "nsStringBuffer.h"
      27             : #include "mozilla/dom/BindingDeclarations.h"
      28             : #include "mozilla/Preferences.h"
      29             : 
      30             : class nsGlobalWindowInner;
      31             : class nsIPrincipal;
      32             : class nsIHandleReportCallback;
      33             : 
      34             : namespace mozilla {
      35             : namespace dom {
      36             : class Exception;
      37             : }
      38             : }
      39             : 
      40             : typedef void (* xpcGCCallback)(JSGCStatus status);
      41             : 
      42             : namespace xpc {
      43             : 
      44             : class Scriptability {
      45             : public:
      46             :     explicit Scriptability(JS::Realm* realm);
      47             :     bool Allowed();
      48             :     bool IsImmuneToScriptPolicy();
      49             : 
      50             :     void Block();
      51             :     void Unblock();
      52             :     void SetDocShellAllowsScript(bool aAllowed);
      53             : 
      54             :     static Scriptability& Get(JSObject* aScope);
      55             : 
      56             : private:
      57             :     // Whenever a consumer wishes to prevent script from running on a global,
      58             :     // it increments this value with a call to Block(). When it wishes to
      59             :     // re-enable it (if ever), it decrements this value with a call to Unblock().
      60             :     // Script may not run if this value is non-zero.
      61             :     uint32_t mScriptBlocks;
      62             : 
      63             :     // Whether the docshell allows javascript in this scope. If this scope
      64             :     // doesn't have a docshell, this value is always true.
      65             :     bool mDocShellAllowsScript;
      66             : 
      67             :     // Whether this scope is immune to user-defined or addon-defined script
      68             :     // policy.
      69             :     bool mImmuneToScriptPolicy;
      70             : 
      71             :     // Whether the new-style domain policy when this compartment was created
      72             :     // forbids script execution.
      73             :     bool mScriptBlockedByPolicy;
      74             : };
      75             : 
      76             : JSObject*
      77             : TransplantObject(JSContext* cx, JS::HandleObject origobj, JS::HandleObject target);
      78             : 
      79             : JSObject*
      80             : TransplantObjectRetainingXrayExpandos(JSContext* cx, JS::HandleObject origobj, JS::HandleObject target);
      81             : 
      82             : bool IsContentXBLCompartment(JS::Compartment* compartment);
      83             : bool IsContentXBLScope(JS::Realm* realm);
      84             : bool IsInContentXBLScope(JSObject* obj);
      85             : 
      86             : // Return a raw XBL scope object corresponding to contentScope, which must
      87             : // be an object whose global is a DOM window.
      88             : //
      89             : // The return value is not wrapped into cx->compartment, so be sure to enter
      90             : // its compartment before doing anything meaningful.
      91             : //
      92             : // Also note that XBL scopes are lazily created, so the return-value should be
      93             : // null-checked unless the caller can ensure that the scope must already
      94             : // exist.
      95             : //
      96             : // This function asserts if |contentScope| is itself in an XBL scope to catch
      97             : // sloppy consumers. Conversely, GetXBLScopeOrGlobal will handle objects that
      98             : // are in XBL scope (by just returning the global).
      99             : JSObject*
     100             : GetXBLScope(JSContext* cx, JSObject* contentScope);
     101             : 
     102             : inline JSObject*
     103             : GetXBLScopeOrGlobal(JSContext* cx, JSObject* obj)
     104             : {
     105             :     if (IsInContentXBLScope(obj))
     106             :         return js::GetGlobalForObjectCrossCompartment(obj);
     107             :     return GetXBLScope(cx, obj);
     108             : }
     109             : 
     110             : // Returns whether XBL scopes have been explicitly disabled for code running
     111             : // in this compartment. See the comment around mAllowContentXBLScope.
     112             : bool
     113             : AllowContentXBLScope(JS::Realm* realm);
     114             : 
     115             : // Returns whether we will use an XBL scope for this realm. This is
     116             : // semantically equivalent to comparing global != GetXBLScope(global), but it
     117             : // does not have the side-effect of eagerly creating the XBL scope if it does
     118             : // not already exist.
     119             : bool
     120             : UseContentXBLScope(JS::Realm* realm);
     121             : 
     122             : // Clear out the content XBL scope (if any) on the given global.  This will
     123             : // force creation of a new one if one is needed again.
     124             : void
     125             : ClearContentXBLScope(JSObject* global);
     126             : 
     127             : bool
     128             : IsSandboxPrototypeProxy(JSObject* obj);
     129             : 
     130             : bool
     131             : IsReflector(JSObject* obj);
     132             : 
     133             : bool
     134             : IsXrayWrapper(JSObject* obj);
     135             : 
     136             : // If this function was created for a given XrayWrapper, returns the global of
     137             : // the Xrayed object. Otherwise, returns the global of the function.
     138             : //
     139             : // To emphasize the obvious: the return value here is not necessarily same-
     140             : // compartment with the argument.
     141             : JSObject*
     142             : XrayAwareCalleeGlobal(JSObject* fun);
     143             : 
     144             : void
     145             : TraceXPCGlobal(JSTracer* trc, JSObject* obj);
     146             : 
     147             : /**
     148             :  * Creates a new global object using the given aCOMObj as the global
     149             :  * object. The object will be set up according to the flags (defined
     150             :  * below). If you do not pass INIT_JS_STANDARD_CLASSES, then aCOMObj
     151             :  * must implement nsIXPCScriptable so it can resolve the standard
     152             :  * classes when asked by the JS engine.
     153             :  *
     154             :  * @param aJSContext the context to use while creating the global object.
     155             :  * @param aCOMObj the native object that represents the global object.
     156             :  * @param aPrincipal the principal of the code that will run in this
     157             :  *                   compartment. Can be null if not on the main thread.
     158             :  * @param aFlags one of the flags below specifying what options this
     159             :  *               global object wants.
     160             :  * @param aOptions JSAPI-specific options for the new compartment.
     161             :  */
     162             : nsresult
     163             : InitClassesWithNewWrappedGlobal(JSContext* aJSContext,
     164             :                                 nsISupports* aCOMObj,
     165             :                                 nsIPrincipal* aPrincipal,
     166             :                                 uint32_t aFlags,
     167             :                                 JS::RealmOptions& aOptions,
     168             :                                 JS::MutableHandleObject aNewGlobal);
     169             : 
     170             : enum InitClassesFlag {
     171             :     INIT_JS_STANDARD_CLASSES  = 1 << 0,
     172             :     DONT_FIRE_ONNEWGLOBALHOOK = 1 << 1,
     173             :     OMIT_COMPONENTS_OBJECT    = 1 << 2,
     174             : };
     175             : 
     176             : } /* namespace xpc */
     177             : 
     178             : namespace JS {
     179             : 
     180             : struct RuntimeStats;
     181             : 
     182             : } // namespace JS
     183             : 
     184             : #define XPC_WRAPPER_FLAGS (JSCLASS_HAS_PRIVATE | JSCLASS_FOREGROUND_FINALIZE)
     185             : 
     186             : #define XPCONNECT_GLOBAL_FLAGS_WITH_EXTRA_SLOTS(n)                            \
     187             :     JSCLASS_DOM_GLOBAL | JSCLASS_HAS_PRIVATE |                                \
     188             :     JSCLASS_PRIVATE_IS_NSISUPPORTS |                                          \
     189             :     JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS + n)
     190             : 
     191             : #define XPCONNECT_GLOBAL_EXTRA_SLOT_OFFSET (JSCLASS_GLOBAL_SLOT_COUNT + DOM_GLOBAL_SLOTS)
     192             : 
     193             : #define XPCONNECT_GLOBAL_FLAGS XPCONNECT_GLOBAL_FLAGS_WITH_EXTRA_SLOTS(0)
     194             : 
     195             : inline JSObject*
     196           2 : xpc_FastGetCachedWrapper(JSContext* cx, nsWrapperCache* cache, JS::MutableHandleValue vp)
     197             : {
     198           2 :     if (cache) {
     199           0 :         JSObject* wrapper = cache->GetWrapper();
     200           0 :         if (wrapper &&
     201           0 :             js::GetObjectCompartment(wrapper) == js::GetContextCompartment(cx))
     202             :         {
     203           0 :             vp.setObject(*wrapper);
     204           0 :             return wrapper;
     205             :         }
     206             :     }
     207             : 
     208             :     return nullptr;
     209             : }
     210             : 
     211             : // If aWrappedJS is a JS wrapper, unmark its JSObject.
     212             : extern void
     213             : xpc_TryUnmarkWrappedGrayObject(nsISupports* aWrappedJS);
     214             : 
     215             : extern void
     216             : xpc_UnmarkSkippableJSHolders();
     217             : 
     218             : // Defined in XPCDebug.cpp.
     219             : extern bool
     220             : xpc_DumpJSStack(bool showArgs, bool showLocals, bool showThisProps);
     221             : 
     222             : // Return a newly-allocated string containing a representation of the
     223             : // current JS stack. Defined in XPCDebug.cpp.
     224             : extern JS::UniqueChars
     225             : xpc_PrintJSStack(JSContext* cx, bool showArgs, bool showLocals,
     226             :                  bool showThisProps);
     227             : 
     228             : 
     229             : // readable string conversions, static methods and members only
     230             : class XPCStringConvert
     231             : {
     232             : public:
     233             : 
     234             :     // If the string shares the readable's buffer, that buffer will
     235             :     // get assigned to *sharedBuffer.  Otherwise null will be
     236             :     // assigned.
     237             :     static bool ReadableToJSVal(JSContext* cx, const nsAString& readable,
     238             :                                 nsStringBuffer** sharedBuffer,
     239             :                                 JS::MutableHandleValue vp);
     240             : 
     241             :     // Convert the given stringbuffer/length pair to a jsval
     242             :     static MOZ_ALWAYS_INLINE bool
     243           2 :     StringBufferToJSVal(JSContext* cx, nsStringBuffer* buf, uint32_t length,
     244             :                         JS::MutableHandleValue rval, bool* sharedBuffer)
     245             :     {
     246           2 :         JSString* str = JS_NewMaybeExternalString(cx,
     247           2 :                                                   static_cast<char16_t*>(buf->Data()),
     248           2 :                                                   length, &sDOMStringFinalizer, sharedBuffer);
     249           2 :         if (!str) {
     250             :             return false;
     251             :         }
     252           2 :         rval.setString(str);
     253           2 :         return true;
     254             :     }
     255             : 
     256             :     static inline bool
     257           2 :     StringLiteralToJSVal(JSContext* cx, const char16_t* literal, uint32_t length,
     258             :                          JS::MutableHandleValue rval)
     259             :     {
     260             :         bool ignored;
     261           2 :         JSString* str = JS_NewMaybeExternalString(cx, literal, length,
     262           2 :                                                   &sLiteralFinalizer, &ignored);
     263           2 :         if (!str)
     264             :             return false;
     265           2 :         rval.setString(str);
     266           2 :         return true;
     267             :     }
     268             : 
     269         438 :     static MOZ_ALWAYS_INLINE bool IsLiteral(JSString* str)
     270             :     {
     271         438 :         return JS_IsExternalString(str) &&
     272         438 :                JS_GetExternalStringFinalizer(str) == &sLiteralFinalizer;
     273             :     }
     274             : 
     275           2 :     static MOZ_ALWAYS_INLINE bool IsDOMString(JSString* str)
     276             :     {
     277           2 :         return JS_IsExternalString(str) &&
     278           2 :                JS_GetExternalStringFinalizer(str) == &sDOMStringFinalizer;
     279             :     }
     280             : 
     281             : private:
     282             :     static const JSStringFinalizer sLiteralFinalizer, sDOMStringFinalizer;
     283             : 
     284             :     static void FinalizeLiteral(const JSStringFinalizer* fin, char16_t* chars);
     285             : 
     286             :     static void FinalizeDOMString(const JSStringFinalizer* fin, char16_t* chars);
     287             : 
     288             :     XPCStringConvert() = delete;
     289             : };
     290             : 
     291             : class nsIAddonInterposition;
     292             : 
     293             : namespace xpc {
     294             : 
     295             : // If these functions return false, then an exception will be set on cx.
     296             : bool Base64Encode(JSContext* cx, JS::HandleValue val, JS::MutableHandleValue out);
     297             : bool Base64Decode(JSContext* cx, JS::HandleValue val, JS::MutableHandleValue out);
     298             : 
     299             : /**
     300             :  * Convert an nsString to jsval, returning true on success.
     301             :  * Note, the ownership of the string buffer may be moved from str to rval.
     302             :  * If that happens, str will point to an empty string after this call.
     303             :  */
     304             : bool NonVoidStringToJsval(JSContext* cx, nsAString& str, JS::MutableHandleValue rval);
     305           0 : inline bool StringToJsval(JSContext* cx, nsAString& str, JS::MutableHandleValue rval)
     306             : {
     307             :     // From the T_DOMSTRING case in XPCConvert::NativeData2JS.
     308           0 :     if (str.IsVoid()) {
     309           0 :         rval.setNull();
     310           0 :         return true;
     311             :     }
     312           0 :     return NonVoidStringToJsval(cx, str, rval);
     313             : }
     314             : 
     315             : inline bool
     316        2878 : NonVoidStringToJsval(JSContext* cx, const nsAString& str, JS::MutableHandleValue rval)
     317             : {
     318        5756 :     nsString mutableCopy;
     319        2878 :     if (!mutableCopy.Assign(str, mozilla::fallible)) {
     320           0 :         JS_ReportOutOfMemory(cx);
     321           0 :         return false;
     322             :     }
     323        2878 :     return NonVoidStringToJsval(cx, mutableCopy, rval);
     324             : }
     325             : 
     326             : inline bool
     327           0 : StringToJsval(JSContext* cx, const nsAString& str, JS::MutableHandleValue rval)
     328             : {
     329           0 :     nsString mutableCopy;
     330           0 :     if (!mutableCopy.Assign(str, mozilla::fallible)) {
     331           0 :         JS_ReportOutOfMemory(cx);
     332           0 :         return false;
     333             :     }
     334           0 :     return StringToJsval(cx, mutableCopy, rval);
     335             : }
     336             : 
     337             : /**
     338             :  * As above, but for mozilla::dom::DOMString.
     339             :  */
     340             : inline
     341           2 : bool NonVoidStringToJsval(JSContext* cx, mozilla::dom::DOMString& str,
     342             :                           JS::MutableHandleValue rval)
     343             : {
     344           2 :     if (str.IsEmpty()) {
     345           2 :         rval.set(JS_GetEmptyStringValue(cx));
     346           2 :         return true;
     347             :     }
     348             : 
     349           2 :     if (str.HasStringBuffer()) {
     350           2 :         uint32_t length = str.StringBufferLength();
     351           2 :         nsStringBuffer* buf = str.StringBuffer();
     352             :         bool shared;
     353           2 :         if (!XPCStringConvert::StringBufferToJSVal(cx, buf, length, rval,
     354             :                                                    &shared)) {
     355             :             return false;
     356             :         }
     357           2 :         if (shared) {
     358             :             // JS now needs to hold a reference to the buffer
     359           2 :             str.RelinquishBufferOwnership();
     360             :         }
     361             :         return true;
     362             :     }
     363             : 
     364           2 :     if (str.HasLiteral()) {
     365           2 :         return XPCStringConvert::StringLiteralToJSVal(cx, str.Literal(),
     366           2 :                                                       str.LiteralLength(), rval);
     367             :     }
     368             : 
     369             :     // It's an actual XPCOM string
     370           2 :     return NonVoidStringToJsval(cx, str.AsAString(), rval);
     371             : }
     372             : 
     373             : MOZ_ALWAYS_INLINE
     374           2 : bool StringToJsval(JSContext* cx, mozilla::dom::DOMString& str,
     375             :                    JS::MutableHandleValue rval)
     376             : {
     377           2 :     if (str.IsNull()) {
     378           2 :         rval.setNull();
     379           2 :         return true;
     380             :     }
     381           2 :     return NonVoidStringToJsval(cx, str, rval);
     382             : }
     383             : 
     384             : nsIPrincipal* GetCompartmentPrincipal(JS::Compartment* compartment);
     385             : nsIPrincipal* GetRealmPrincipal(JS::Realm* realm);
     386             : 
     387             : void NukeAllWrappersForCompartment(JSContext* cx, JS::Compartment* compartment,
     388             :                                    js::NukeReferencesToWindow nukeReferencesToWindow = js::NukeWindowReferences);
     389             : 
     390             : void SetLocationForGlobal(JSObject* global, const nsACString& location);
     391             : void SetLocationForGlobal(JSObject* global, nsIURI* locationURI);
     392             : 
     393             : // ReportJSRuntimeExplicitTreeStats will expect this in the |extra| member
     394             : // of JS::ZoneStats.
     395           0 : class ZoneStatsExtras {
     396             : public:
     397           0 :     ZoneStatsExtras() {}
     398             : 
     399             :     nsCString pathPrefix;
     400             : 
     401             : private:
     402             :     ZoneStatsExtras(const ZoneStatsExtras& other) = delete;
     403             :     ZoneStatsExtras& operator=(const ZoneStatsExtras& other) = delete;
     404             : };
     405             : 
     406             : // ReportJSRuntimeExplicitTreeStats will expect this in the |extra| member
     407             : // of JS::RealmStats.
     408           0 : class RealmStatsExtras {
     409             : public:
     410           0 :     RealmStatsExtras() {}
     411             : 
     412             :     nsCString jsPathPrefix;
     413             :     nsCString domPathPrefix;
     414             :     nsCOMPtr<nsIURI> location;
     415             : 
     416             : private:
     417             :     RealmStatsExtras(const RealmStatsExtras& other) = delete;
     418             :     RealmStatsExtras& operator=(const RealmStatsExtras& other) = delete;
     419             : };
     420             : 
     421             : // This reports all the stats in |rtStats| that belong in the "explicit" tree,
     422             : // (which isn't all of them).
     423             : // @see ZoneStatsExtras
     424             : // @see RealmStatsExtras
     425             : void
     426             : ReportJSRuntimeExplicitTreeStats(const JS::RuntimeStats& rtStats,
     427             :                                  const nsACString& rtPath,
     428             :                                  nsIHandleReportCallback* handleReport,
     429             :                                  nsISupports* data,
     430             :                                  bool anonymize,
     431             :                                  size_t* rtTotal = nullptr);
     432             : 
     433             : /**
     434             :  * Throws an exception on cx and returns false.
     435             :  */
     436             : bool
     437             : Throw(JSContext* cx, nsresult rv);
     438             : 
     439             : /**
     440             :  * Returns the nsISupports native behind a given reflector (either DOM or
     441             :  * XPCWN).
     442             :  */
     443             : already_AddRefed<nsISupports>
     444             : UnwrapReflectorToISupports(JSObject* reflector);
     445             : 
     446             : /**
     447             :  * Singleton scopes for stuff that really doesn't fit anywhere else.
     448             :  *
     449             :  * If you find yourself wanting to use these compartments, you're probably doing
     450             :  * something wrong. Callers MUST consult with the XPConnect module owner before
     451             :  * using this compartment. If you don't, bholley will hunt you down.
     452             :  */
     453             : JSObject*
     454             : UnprivilegedJunkScope();
     455             : 
     456             : JSObject*
     457             : PrivilegedJunkScope();
     458             : 
     459             : /**
     460             :  * Shared compilation scope for XUL prototype documents and XBL
     461             :  * precompilation. This compartment has a null principal. No code may run, and
     462             :  * it is invisible to the debugger.
     463             :  */
     464             : JSObject*
     465             : CompilationScope();
     466             : 
     467             : /**
     468             :  * Returns the nsIGlobalObject corresponding to |aObj|'s JS global.
     469             :  */
     470             : nsIGlobalObject*
     471             : NativeGlobal(JSObject* aObj);
     472             : 
     473             : /**
     474             :  * If |aObj| is a window, returns the associated nsGlobalWindow.
     475             :  * Otherwise, returns null.
     476             :  */
     477             : nsGlobalWindowInner*
     478             : WindowOrNull(JSObject* aObj);
     479             : 
     480             : /**
     481             :  * If |aObj| has a window for a global, returns the associated nsGlobalWindow.
     482             :  * Otherwise, returns null.
     483             :  */
     484             : nsGlobalWindowInner*
     485             : WindowGlobalOrNull(JSObject* aObj);
     486             : 
     487             : /**
     488             :  * If |cx| is in a compartment whose global is a window, returns the associated
     489             :  * nsGlobalWindow. Otherwise, returns null.
     490             :  */
     491             : nsGlobalWindowInner*
     492             : CurrentWindowOrNull(JSContext* cx);
     493             : 
     494             : void
     495             : SimulateActivityCallback(bool aActive);
     496             : 
     497             : // This function may be used off-main-thread, in which case it is benignly
     498             : // racey.
     499             : bool
     500             : ShouldDiscardSystemSource();
     501             : 
     502             : bool
     503             : SharedMemoryEnabled();
     504             : 
     505             : bool
     506             : ExtraWarningsForSystemJS();
     507             : 
     508           2 : class ErrorBase {
     509             :   public:
     510             :     nsString mErrorMsg;
     511             :     nsString mFileName;
     512             :     uint32_t mLineNumber;
     513             :     uint32_t mColumn;
     514             : 
     515           2 :     ErrorBase() : mLineNumber(0)
     516           2 :                 , mColumn(0)
     517           2 :     {}
     518             : 
     519             :     void Init(JSErrorBase* aReport);
     520             : 
     521             :     void AppendErrorDetailsTo(nsCString& error);
     522             : };
     523             : 
     524           0 : class ErrorNote : public ErrorBase {
     525             :   public:
     526             :     void Init(JSErrorNotes::Note* aNote);
     527             : 
     528             :     // Produce an error event message string from the given JSErrorNotes::Note.
     529             :     // This may produce an empty string if aNote doesn't have a message
     530             :     // attached.
     531             :     static void ErrorNoteToMessageString(JSErrorNotes::Note* aNote,
     532             :                                          nsAString& aString);
     533             : 
     534             :     // Log the error note to the stderr.
     535             :     void LogToStderr();
     536             : };
     537             : 
     538             : class ErrorReport : public ErrorBase {
     539             :   public:
     540           2 :     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ErrorReport);
     541             : 
     542             :     nsTArray<ErrorNote> mNotes;
     543             : 
     544             :     nsCString mCategory;
     545             :     nsString mSourceLine;
     546             :     nsString mErrorMsgName;
     547             :     uint64_t mWindowID;
     548             :     uint32_t mFlags;
     549             :     bool mIsMuted;
     550             : 
     551           2 :     ErrorReport() : mWindowID(0)
     552             :                   , mFlags(0)
     553           2 :                   , mIsMuted(false)
     554           2 :     {}
     555             : 
     556             :     void Init(JSErrorReport* aReport, const char* aToStringResult,
     557             :               bool aIsChrome, uint64_t aWindowID);
     558             :     void Init(JSContext* aCx, mozilla::dom::Exception* aException,
     559             :               bool aIsChrome, uint64_t aWindowID);
     560             : 
     561             :     // Log the error report to the console.  Which console will depend on the
     562             :     // window id it was initialized with.
     563             :     void LogToConsole();
     564             :     // Log to console, using the given stack object (which should be a stack of
     565             :     // the sort that JS::CaptureCurrentStack produces).  aStack is allowed to be
     566             :     // null.
     567             :     void LogToConsoleWithStack(JS::HandleObject aStack);
     568             : 
     569             :     // Produce an error event message string from the given JSErrorReport.  Note
     570             :     // that this may produce an empty string if aReport doesn't have a
     571             :     // message attached.
     572             :     static void ErrorReportToMessageString(JSErrorReport* aReport,
     573             :                                            nsAString& aString);
     574             : 
     575             :     // Log the error report to the stderr.
     576             :     void LogToStderr();
     577             : 
     578             :   private:
     579           2 :     ~ErrorReport() {}
     580             : };
     581             : 
     582             : void
     583             : DispatchScriptErrorEvent(nsPIDOMWindowInner* win, JS::RootingContext* rootingCx,
     584             :                          xpc::ErrorReport* xpcReport, JS::Handle<JS::Value> exception);
     585             : 
     586             : // Get a stack of the sort that can be passed to
     587             : // xpc::ErrorReport::LogToConsoleWithStack from the given exception value.  Can
     588             : // return null if the exception value doesn't have an associated stack.  The
     589             : // returned stack, if any, may also not be in the same compartment as
     590             : // exceptionValue.
     591             : //
     592             : // The "win" argument passed in here should be the same as the window whose
     593             : // WindowID() is used to initialize the xpc::ErrorReport.  This may be null, of
     594             : // course.  If it's not null, this function may return a null stack object if
     595             : // the window is far enough gone, because in those cases we don't want to have
     596             : // the stack in the console message keeping the window alive.
     597             : JSObject*
     598             : FindExceptionStackForConsoleReport(nsPIDOMWindowInner* win,
     599             :                                    JS::HandleValue exceptionValue);
     600             : 
     601             : // Return a name for the realm.
     602             : // This function makes reasonable efforts to make this name both mostly human-readable
     603             : // and unique. However, there are no guarantees of either property.
     604             : extern void
     605             : GetCurrentRealmName(JSContext*, nsCString& name);
     606             : 
     607             : void AddGCCallback(xpcGCCallback cb);
     608             : void RemoveGCCallback(xpcGCCallback cb);
     609             : 
     610             : inline bool
     611           0 : AreNonLocalConnectionsDisabled()
     612             : {
     613             :     static int disabledForTest = -1;
     614           0 :     if (disabledForTest == -1) {
     615           0 :         char *s = getenv("MOZ_DISABLE_NONLOCAL_CONNECTIONS");
     616           0 :         if (s) {
     617           0 :             disabledForTest = *s != '0';
     618             :         } else {
     619           0 :             disabledForTest = 0;
     620             :         }
     621             :     }
     622           0 :     return disabledForTest;
     623             : }
     624             : 
     625             : inline bool
     626           2 : IsInAutomation()
     627             : {
     628             :     static bool sAutomationPrefIsSet;
     629             :     static bool sPrefCacheAdded = false;
     630           2 :     if (!sPrefCacheAdded) {
     631             :         mozilla::Preferences::AddBoolVarCache(
     632             :           &sAutomationPrefIsSet,
     633             :           "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer",
     634           2 :           false);
     635           2 :         sPrefCacheAdded = true;
     636             :     }
     637           2 :     return sAutomationPrefIsSet && AreNonLocalConnectionsDisabled();
     638             : }
     639             : 
     640             : void
     641             : CreateCooperativeContext();
     642             : 
     643             : void
     644             : DestroyCooperativeContext();
     645             : 
     646             : // Please see JS_YieldCooperativeContext in jsapi.h.
     647             : void
     648             : YieldCooperativeContext();
     649             : 
     650             : // Please see JS_ResumeCooperativeContext in jsapi.h.
     651             : void
     652             : ResumeCooperativeContext();
     653             : 
     654             : } // namespace xpc
     655             : 
     656             : namespace mozilla {
     657             : namespace dom {
     658             : 
     659             : /**
     660             :  * A test for whether WebIDL methods that should only be visible to
     661             :  * chrome or XBL scopes should be exposed.
     662             :  */
     663             : bool IsChromeOrXBL(JSContext* cx, JSObject* /* unused */);
     664             : 
     665             : /**
     666             :  * Same as IsChromeOrXBL but can be used in worker threads as well.
     667             :  */
     668             : bool ThreadSafeIsChromeOrXBL(JSContext* cx, JSObject* obj);
     669             : 
     670             : } // namespace dom
     671             : } // namespace mozilla
     672             : 
     673             : #endif

Generated by: LCOV version 1.13-14-ga5dd952