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

Generated by: LCOV version 1.13