2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-12-12 05:51:57 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* Utilities for managing the script settings object stack defined in webapps */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_ScriptSettings_h
|
|
|
|
#define mozilla_dom_ScriptSettings_h
|
|
|
|
|
|
|
|
#include "MainThreadUtils.h"
|
2013-12-12 05:51:57 +04:00
|
|
|
#include "nsIGlobalObject.h"
|
2014-02-15 10:36:44 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2013-12-12 05:51:57 +04:00
|
|
|
|
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
|
2014-08-15 05:47:15 +04:00
|
|
|
#include "jsapi.h"
|
2015-05-20 12:28:00 +03:00
|
|
|
#include "js/Debug.h"
|
2014-08-15 05:47:15 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2014-06-25 14:17:17 +04:00
|
|
|
class nsGlobalWindow;
|
2014-08-15 05:47:15 +04:00
|
|
|
class nsIScriptContext;
|
2014-08-19 23:02:06 +04:00
|
|
|
class nsIDocument;
|
2014-11-14 00:22:24 +03:00
|
|
|
class nsIDocShell;
|
2013-12-12 05:51:57 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-12-12 05:51:57 +04:00
|
|
|
/*
|
|
|
|
* System-wide setup/teardown routines. Init and Destroy should be invoked
|
|
|
|
* once each, at startup and shutdown (respectively).
|
|
|
|
*/
|
|
|
|
void InitScriptSettings();
|
|
|
|
void DestroyScriptSettings();
|
2014-12-06 20:51:14 +03:00
|
|
|
bool ScriptSettingsInitialized();
|
2013-12-12 05:51:57 +04:00
|
|
|
|
2014-11-14 00:22:24 +03:00
|
|
|
/*
|
|
|
|
* Static helpers in ScriptSettings which track the number of listeners
|
|
|
|
* of Javascript RunToCompletion events. These should be used by the code in
|
|
|
|
* nsDocShell::SetRecordProfileTimelineMarkers to indicate to script
|
|
|
|
* settings that script run-to-completion needs to be monitored.
|
|
|
|
* SHOULD BE CALLED ONLY BY MAIN THREAD.
|
|
|
|
*/
|
|
|
|
void UseEntryScriptProfiling();
|
|
|
|
void UnuseEntryScriptProfiling();
|
|
|
|
|
2014-08-19 23:02:05 +04:00
|
|
|
// To implement a web-compatible browser, it is often necessary to obtain the
|
|
|
|
// global object that is "associated" with the currently-running code. This
|
|
|
|
// process is made more complicated by the fact that, historically, different
|
|
|
|
// algorithms have operated with different definitions of the "associated"
|
|
|
|
// global.
|
|
|
|
//
|
|
|
|
// HTML5 formalizes this into two concepts: the "incumbent global" and the
|
|
|
|
// "entry global". The incumbent global corresponds to the global of the
|
|
|
|
// current script being executed, whereas the entry global corresponds to the
|
|
|
|
// global of the script where the current JS execution began.
|
|
|
|
//
|
|
|
|
// There is also a potentially-distinct third global that is determined by the
|
|
|
|
// current compartment. This roughly corresponds with the notion of Realms in
|
|
|
|
// ECMAScript.
|
|
|
|
//
|
|
|
|
// Suppose some event triggers an event listener in window |A|, which invokes a
|
|
|
|
// scripted function in window |B|, which invokes the |window.location.href|
|
|
|
|
// setter in window |C|. The entry global would be |A|, the incumbent global
|
|
|
|
// would be |B|, and the current compartment would be that of |C|.
|
|
|
|
//
|
|
|
|
// In general, it's best to use to use the most-closely-associated global
|
|
|
|
// unless the spec says to do otherwise. In 95% of the cases, the global of
|
|
|
|
// the current compartment (GetCurrentGlobal()) is the right thing. For
|
|
|
|
// example, WebIDL constructors (new C.XMLHttpRequest()) are initialized with
|
|
|
|
// the global of the current compartment (i.e. |C|).
|
|
|
|
//
|
|
|
|
// The incumbent global is very similar, but differs in a few edge cases. For
|
|
|
|
// example, if window |B| does |C.location.href = "..."|, the incumbent global
|
|
|
|
// used for the navigation algorithm is B, because no script from |C| was ever run.
|
|
|
|
//
|
|
|
|
// The entry global is used for various things like computing base URIs, mostly
|
|
|
|
// for historical reasons.
|
|
|
|
//
|
|
|
|
// Note that all of these functions return bonafide global objects. This means
|
|
|
|
// that, for Windows, they always return the inner.
|
|
|
|
|
|
|
|
// Returns the global associated with the top-most Candidate Entry Point on
|
|
|
|
// the Script Settings Stack. See the HTML spec. This may be null.
|
|
|
|
nsIGlobalObject* GetEntryGlobal();
|
|
|
|
|
2014-08-19 23:02:06 +04:00
|
|
|
// If the entry global is a window, returns its extant document. Otherwise,
|
|
|
|
// returns null.
|
|
|
|
nsIDocument* GetEntryDocument();
|
|
|
|
|
2014-08-19 23:02:05 +04:00
|
|
|
// Returns the global associated with the top-most entry of the the Script
|
|
|
|
// Settings Stack. See the HTML spec. This may be null.
|
2013-12-12 05:51:57 +04:00
|
|
|
nsIGlobalObject* GetIncumbentGlobal();
|
|
|
|
|
2014-08-19 23:02:05 +04:00
|
|
|
// Returns the global associated with the current compartment. This may be null.
|
|
|
|
nsIGlobalObject* GetCurrentGlobal();
|
|
|
|
|
2014-02-15 10:36:44 +04:00
|
|
|
// JS-implemented WebIDL presents an interesting situation with respect to the
|
|
|
|
// subject principal. A regular C++-implemented API can simply examine the
|
|
|
|
// compartment of the most-recently-executed script, and use that to infer the
|
|
|
|
// responsible party. However, JS-implemented APIs are run with system
|
|
|
|
// principal, and thus clobber the subject principal of the script that
|
|
|
|
// invoked the API. So we have to do some extra work to keep track of this
|
|
|
|
// information.
|
|
|
|
//
|
|
|
|
// We therefore implement the following behavior:
|
|
|
|
// * Each Script Settings Object has an optional WebIDL Caller Principal field.
|
|
|
|
// This defaults to null.
|
|
|
|
// * When we push an Entry Point in preparation to run a JS-implemented WebIDL
|
|
|
|
// callback, we grab the subject principal at the time of invocation, and
|
|
|
|
// store that as the WebIDL Caller Principal.
|
|
|
|
// * When non-null, callers can query this principal from script via an API on
|
|
|
|
// Components.utils.
|
|
|
|
nsIPrincipal* GetWebIDLCallerPrincipal();
|
|
|
|
|
2014-02-15 10:39:33 +04:00
|
|
|
// This may be used by callers that know that their incumbent global is non-
|
|
|
|
// null (i.e. they know there have been no System Caller pushes since the
|
|
|
|
// inner-most script execution).
|
|
|
|
inline JSObject& IncumbentJSGlobal()
|
|
|
|
{
|
|
|
|
return *GetIncumbentGlobal()->GetGlobalJSObject();
|
|
|
|
}
|
|
|
|
|
2016-06-24 21:19:50 +03:00
|
|
|
// Returns whether JSAPI is active right now. If it is not, working with a
|
|
|
|
// JSContext you grab from somewhere random is not OK and you should be doing
|
|
|
|
// AutoJSAPI or AutoEntryScript to get yourself a properly set up JSContext.
|
|
|
|
bool IsJSAPIActive();
|
|
|
|
|
2016-07-08 03:08:26 +03:00
|
|
|
namespace danger {
|
|
|
|
|
|
|
|
// Get the JSContext for this thread. This is in the "danger" namespace because
|
|
|
|
// we generally want people using AutoJSAPI instead, unless they really know
|
|
|
|
// what they're doing.
|
|
|
|
JSContext* GetJSContext();
|
|
|
|
|
|
|
|
} // namespace danger
|
|
|
|
|
2016-08-11 15:39:22 +03:00
|
|
|
JS::RootingContext* RootingCx();
|
2016-07-08 03:08:26 +03:00
|
|
|
|
2013-12-12 05:51:57 +04:00
|
|
|
class ScriptSettingsStack;
|
2014-06-13 10:24:13 +04:00
|
|
|
class ScriptSettingsStackEntry {
|
|
|
|
friend class ScriptSettingsStack;
|
2013-12-12 05:51:57 +04:00
|
|
|
|
2014-06-13 10:24:13 +04:00
|
|
|
public:
|
|
|
|
~ScriptSettingsStackEntry();
|
2013-12-12 05:51:57 +04:00
|
|
|
|
2016-06-24 21:19:50 +03:00
|
|
|
bool NoJSAPI() const { return mType == eNoJSAPI; }
|
|
|
|
bool IsEntryCandidate() const {
|
|
|
|
return mType == eEntryScript || mType == eNoJSAPI;
|
|
|
|
}
|
|
|
|
bool IsIncumbentCandidate() { return mType != eJSAPI; }
|
2016-06-24 21:19:50 +03:00
|
|
|
bool IsIncumbentScript() { return mType == eIncumbentScript; }
|
2013-12-12 05:51:57 +04:00
|
|
|
|
2014-06-13 10:24:13 +04:00
|
|
|
protected:
|
2016-06-24 21:19:50 +03:00
|
|
|
enum Type {
|
|
|
|
eEntryScript,
|
|
|
|
eIncumbentScript,
|
|
|
|
eJSAPI,
|
|
|
|
eNoJSAPI
|
|
|
|
};
|
|
|
|
|
|
|
|
ScriptSettingsStackEntry(nsIGlobalObject *aGlobal,
|
|
|
|
Type aEntryType);
|
2014-08-15 03:23:15 +04:00
|
|
|
|
2014-06-13 10:24:13 +04:00
|
|
|
nsCOMPtr<nsIGlobalObject> mGlobalObject;
|
2016-06-24 21:19:50 +03:00
|
|
|
Type mType;
|
2013-12-12 05:51:57 +04:00
|
|
|
|
|
|
|
private:
|
2014-06-13 10:24:13 +04:00
|
|
|
ScriptSettingsStackEntry *mOlder;
|
2013-12-12 05:51:57 +04:00
|
|
|
};
|
|
|
|
|
2014-04-15 07:26:59 +04:00
|
|
|
/*
|
|
|
|
* For any interaction with JSAPI, an AutoJSAPI (or one of its subclasses)
|
|
|
|
* must be on the stack.
|
|
|
|
*
|
|
|
|
* This base class should be instantiated as-is when the caller wants to use
|
2014-06-19 11:21:14 +04:00
|
|
|
* JSAPI but doesn't expect to run script. The caller must then call one of its
|
|
|
|
* Init functions before being able to access the JSContext through cx().
|
|
|
|
* Its current duties are as-follows (see individual Init comments for details):
|
2014-04-15 07:26:59 +04:00
|
|
|
*
|
|
|
|
* * Grabbing an appropriate JSContext, and, on the main thread, pushing it onto
|
|
|
|
* the JSContext stack.
|
2014-06-19 11:21:14 +04:00
|
|
|
* * Entering an initial (possibly null) compartment, to ensure that the
|
|
|
|
* previously entered compartment for that JSContext is not used by mistake.
|
2016-06-24 21:19:51 +03:00
|
|
|
* * Reporting any exceptions left on the JSRuntime, unless the caller steals
|
|
|
|
* or silences them.
|
|
|
|
* * On main thread, entering a JSAutoRequest.
|
2014-04-15 07:26:59 +04:00
|
|
|
*
|
|
|
|
* Additionally, the following duties are planned, but not yet implemented:
|
|
|
|
*
|
2016-06-24 21:19:51 +03:00
|
|
|
* * De-poisoning the JSRuntime to allow manipulation of JSAPI. This requires
|
|
|
|
* implementing the poisoning first. For now, this de-poisoning
|
2014-04-15 07:26:59 +04:00
|
|
|
* effectively corresponds to having a non-null cx on the stack.
|
|
|
|
*
|
|
|
|
* In situations where the consumer expects to run script, AutoEntryScript
|
|
|
|
* should be used, which does additional manipulation of the script settings
|
|
|
|
* stack. In bug 991758, we'll add hard invariants to SpiderMonkey, such that
|
|
|
|
* any attempt to run script without an AutoEntryScript on the stack will
|
|
|
|
* fail. This prevents system code from accidentally triggering script
|
|
|
|
* execution at inopportune moments via surreptitious getters and proxies.
|
|
|
|
*/
|
2016-06-24 21:19:50 +03:00
|
|
|
class MOZ_STACK_CLASS AutoJSAPI : protected ScriptSettingsStackEntry {
|
2014-04-15 07:26:59 +04:00
|
|
|
public:
|
2014-06-19 11:21:14 +04:00
|
|
|
// Trivial constructor. One of the Init functions must be called before
|
|
|
|
// accessing the JSContext through cx().
|
2014-04-15 07:26:59 +04:00
|
|
|
AutoJSAPI();
|
2014-06-19 11:21:14 +04:00
|
|
|
|
2014-09-29 17:34:21 +04:00
|
|
|
~AutoJSAPI();
|
|
|
|
|
2014-06-19 11:21:14 +04:00
|
|
|
// This uses the SafeJSContext (or worker equivalent), and enters a null
|
|
|
|
// compartment, so that the consumer is forced to select a compartment to
|
|
|
|
// enter before manipulating objects.
|
2016-03-18 17:48:38 +03:00
|
|
|
//
|
|
|
|
// This variant will ensure that any errors reported by this AutoJSAPI as it
|
|
|
|
// comes off the stack will not fire error events or be associated with any
|
|
|
|
// particular web-visible global.
|
2014-06-19 11:21:14 +04:00
|
|
|
void Init();
|
|
|
|
|
|
|
|
// This uses the SafeJSContext (or worker equivalent), and enters the
|
|
|
|
// compartment of aGlobalObject.
|
|
|
|
// If aGlobalObject or its associated JS global are null then it returns
|
|
|
|
// false and use of cx() will cause an assertion.
|
2016-03-18 17:48:38 +03:00
|
|
|
//
|
|
|
|
// If aGlobalObject represents a web-visible global, errors reported by this
|
|
|
|
// AutoJSAPI as it comes off the stack will fire the relevant error events and
|
|
|
|
// show up in the corresponding web console.
|
2016-07-14 06:18:11 +03:00
|
|
|
MOZ_MUST_USE bool Init(nsIGlobalObject* aGlobalObject);
|
2014-06-19 11:21:14 +04:00
|
|
|
|
2014-09-21 23:31:53 +04:00
|
|
|
// This is a helper that grabs the native global associated with aObject and
|
|
|
|
// invokes the above Init() with that.
|
2016-07-14 06:18:11 +03:00
|
|
|
MOZ_MUST_USE bool Init(JSObject* aObject);
|
2014-09-21 23:31:53 +04:00
|
|
|
|
2014-06-19 11:21:14 +04:00
|
|
|
// Unsurprisingly, this uses aCx and enters the compartment of aGlobalObject.
|
|
|
|
// If aGlobalObject or its associated JS global are null then it returns
|
|
|
|
// false and use of cx() will cause an assertion.
|
|
|
|
// If aCx is null it will cause an assertion.
|
2016-03-18 17:48:38 +03:00
|
|
|
//
|
|
|
|
// If aGlobalObject represents a web-visible global, errors reported by this
|
|
|
|
// AutoJSAPI as it comes off the stack will fire the relevant error events and
|
|
|
|
// show up in the corresponding web console.
|
2016-07-14 06:18:11 +03:00
|
|
|
MOZ_MUST_USE bool Init(nsIGlobalObject* aGlobalObject, JSContext* aCx);
|
2014-06-19 11:21:14 +04:00
|
|
|
|
2014-06-25 14:17:17 +04:00
|
|
|
// Convenience functions to take an nsPIDOMWindow* or nsGlobalWindow*,
|
|
|
|
// when it is more easily available than an nsIGlobalObject.
|
2016-07-14 06:18:11 +03:00
|
|
|
MOZ_MUST_USE bool Init(nsPIDOMWindowInner* aWindow);
|
|
|
|
MOZ_MUST_USE bool Init(nsPIDOMWindowInner* aWindow, JSContext* aCx);
|
2014-06-25 14:17:17 +04:00
|
|
|
|
2016-07-14 06:18:11 +03:00
|
|
|
MOZ_MUST_USE bool Init(nsGlobalWindow* aWindow);
|
|
|
|
MOZ_MUST_USE bool Init(nsGlobalWindow* aWindow, JSContext* aCx);
|
2014-06-25 14:17:17 +04:00
|
|
|
|
2014-06-19 11:21:14 +04:00
|
|
|
JSContext* cx() const {
|
|
|
|
MOZ_ASSERT(mCx, "Must call Init before using an AutoJSAPI");
|
2016-06-24 21:19:50 +03:00
|
|
|
MOZ_ASSERT(IsStackTop());
|
2014-06-19 11:21:14 +04:00
|
|
|
return mCx;
|
|
|
|
}
|
2014-04-15 07:26:59 +04:00
|
|
|
|
2016-06-21 00:40:39 +03:00
|
|
|
#ifdef DEBUG
|
2016-06-24 21:19:50 +03:00
|
|
|
bool IsStackTop() const;
|
2016-06-21 00:40:39 +03:00
|
|
|
#endif
|
2014-04-15 07:26:59 +04:00
|
|
|
|
2016-03-23 18:44:54 +03:00
|
|
|
// If HasException, report it. Otherwise, a no-op.
|
2015-06-16 03:10:38 +03:00
|
|
|
void ReportException();
|
2014-09-29 17:34:21 +04:00
|
|
|
|
|
|
|
bool HasException() const {
|
2016-06-24 21:19:50 +03:00
|
|
|
MOZ_ASSERT(IsStackTop());
|
2014-09-29 17:34:21 +04:00
|
|
|
return JS_IsExceptionPending(cx());
|
|
|
|
};
|
|
|
|
|
|
|
|
// Transfers ownership of the current exception from the JS engine to the
|
|
|
|
// caller. Callers must ensure that HasException() is true, and that cx()
|
|
|
|
// is in a non-null compartment.
|
|
|
|
//
|
|
|
|
// Note that this fails if and only if we OOM while wrapping the exception
|
|
|
|
// into the current compartment.
|
2016-07-14 06:18:11 +03:00
|
|
|
MOZ_MUST_USE bool StealException(JS::MutableHandle<JS::Value> aVal);
|
2014-09-29 17:34:21 +04:00
|
|
|
|
2015-06-08 23:16:27 +03:00
|
|
|
// Peek the current exception from the JS engine, without stealing it.
|
|
|
|
// Callers must ensure that HasException() is true, and that cx() is in a
|
|
|
|
// non-null compartment.
|
|
|
|
//
|
|
|
|
// Note that this fails if and only if we OOM while wrapping the exception
|
|
|
|
// into the current compartment.
|
2016-07-14 06:18:11 +03:00
|
|
|
MOZ_MUST_USE bool PeekException(JS::MutableHandle<JS::Value> aVal);
|
2015-06-08 23:16:27 +03:00
|
|
|
|
2014-09-29 17:34:21 +04:00
|
|
|
void ClearException() {
|
2016-06-24 21:19:50 +03:00
|
|
|
MOZ_ASSERT(IsStackTop());
|
2014-09-29 17:34:21 +04:00
|
|
|
JS_ClearPendingException(cx());
|
|
|
|
}
|
|
|
|
|
2014-04-15 07:26:59 +04:00
|
|
|
protected:
|
2016-07-08 03:08:25 +03:00
|
|
|
// Protected constructor for subclasses. This constructor initialises the
|
|
|
|
// AutoJSAPI, so Init must NOT be called on subclasses that use this.
|
|
|
|
AutoJSAPI(nsIGlobalObject* aGlobalObject, bool aIsMainThread, Type aType);
|
2014-04-15 07:26:59 +04:00
|
|
|
|
|
|
|
private:
|
2016-06-24 21:19:51 +03:00
|
|
|
mozilla::Maybe<JSAutoRequest> mAutoRequest;
|
2014-06-19 11:21:14 +04:00
|
|
|
mozilla::Maybe<JSAutoNullableCompartment> mAutoNullableCompartment;
|
2014-04-15 07:26:59 +04:00
|
|
|
JSContext *mCx;
|
|
|
|
|
2015-11-21 00:29:41 +03:00
|
|
|
// Whether we're mainthread or not; set when we're initialized.
|
|
|
|
bool mIsMainThread;
|
2016-06-07 21:30:48 +03:00
|
|
|
Maybe<JS::WarningReporter> mOldWarningReporter;
|
2014-09-29 17:34:21 +04:00
|
|
|
|
2016-06-02 17:34:39 +03:00
|
|
|
void InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal,
|
|
|
|
JSContext* aCx, bool aIsMainThread);
|
2014-09-29 17:34:21 +04:00
|
|
|
|
2015-01-07 02:35:02 +03:00
|
|
|
AutoJSAPI(const AutoJSAPI&) = delete;
|
|
|
|
AutoJSAPI& operator= (const AutoJSAPI&) = delete;
|
2014-04-15 07:26:59 +04:00
|
|
|
};
|
|
|
|
|
2013-12-12 05:51:57 +04:00
|
|
|
/*
|
|
|
|
* A class that represents a new script entry point.
|
2015-04-09 04:23:48 +03:00
|
|
|
*
|
|
|
|
* |aReason| should be a statically-allocated C string naming the reason we're
|
|
|
|
* invoking JavaScript code: "setTimeout", "event", and so on. The devtools use
|
|
|
|
* these strings to label JS execution in timeline and profiling displays.
|
2013-12-12 05:51:57 +04:00
|
|
|
*/
|
2016-06-24 21:19:50 +03:00
|
|
|
class MOZ_STACK_CLASS AutoEntryScript : public AutoJSAPI {
|
2013-12-12 05:51:57 +04:00
|
|
|
public:
|
2015-04-09 04:23:48 +03:00
|
|
|
AutoEntryScript(nsIGlobalObject* aGlobalObject,
|
|
|
|
const char *aReason,
|
2016-07-08 03:08:25 +03:00
|
|
|
bool aIsMainThread = NS_IsMainThread());
|
2013-12-12 05:51:57 +04:00
|
|
|
|
2016-03-09 23:28:26 +03:00
|
|
|
AutoEntryScript(JSObject* aObject, // Any object from the relevant global
|
|
|
|
const char *aReason,
|
2016-07-08 03:08:25 +03:00
|
|
|
bool aIsMainThread = NS_IsMainThread());
|
2016-03-09 23:28:26 +03:00
|
|
|
|
2014-08-14 02:36:44 +04:00
|
|
|
~AutoEntryScript();
|
|
|
|
|
2014-02-15 10:36:44 +04:00
|
|
|
void SetWebIDLCallerPrincipal(nsIPrincipal *aPrincipal) {
|
|
|
|
mWebIDLCallerPrincipal = aPrincipal;
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:51:57 +04:00
|
|
|
private:
|
2015-05-20 12:28:00 +03:00
|
|
|
// A subclass of AutoEntryMonitor that notifies the docshell.
|
2016-07-09 02:20:18 +03:00
|
|
|
class DocshellEntryMonitor final : public JS::dbg::AutoEntryMonitor
|
2015-05-20 12:28:00 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DocshellEntryMonitor(JSContext* aCx, const char* aReason);
|
|
|
|
|
2016-03-23 17:40:53 +03:00
|
|
|
// Please note that |aAsyncCause| here is owned by the caller, and its
|
|
|
|
// lifetime must outlive the lifetime of the DocshellEntryMonitor object.
|
|
|
|
// In practice, |aAsyncCause| is identical to |aReason| passed into
|
|
|
|
// the AutoEntryScript constructor, so the lifetime requirements are
|
|
|
|
// trivially satisfied by |aReason| being a statically allocated string.
|
2015-11-05 13:31:00 +03:00
|
|
|
void Entry(JSContext* aCx, JSFunction* aFunction,
|
|
|
|
JS::Handle<JS::Value> aAsyncStack,
|
2016-03-23 17:40:53 +03:00
|
|
|
const char* aAsyncCause) override
|
2015-05-20 12:28:00 +03:00
|
|
|
{
|
2015-11-05 13:31:00 +03:00
|
|
|
Entry(aCx, aFunction, nullptr, aAsyncStack, aAsyncCause);
|
2015-05-20 12:28:00 +03:00
|
|
|
}
|
|
|
|
|
2015-11-05 13:31:00 +03:00
|
|
|
void Entry(JSContext* aCx, JSScript* aScript,
|
|
|
|
JS::Handle<JS::Value> aAsyncStack,
|
2016-03-23 17:40:53 +03:00
|
|
|
const char* aAsyncCause) override
|
2015-05-20 12:28:00 +03:00
|
|
|
{
|
2015-11-05 13:31:00 +03:00
|
|
|
Entry(aCx, nullptr, aScript, aAsyncStack, aAsyncCause);
|
2015-05-20 12:28:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Exit(JSContext* aCx) override;
|
|
|
|
|
|
|
|
private:
|
2015-11-05 13:31:00 +03:00
|
|
|
void Entry(JSContext* aCx, JSFunction* aFunction, JSScript* aScript,
|
|
|
|
JS::Handle<JS::Value> aAsyncStack,
|
2016-03-23 17:40:53 +03:00
|
|
|
const char* aAsyncCause);
|
2015-05-20 12:28:00 +03:00
|
|
|
|
|
|
|
const char* mReason;
|
|
|
|
};
|
|
|
|
|
2014-06-05 06:48:06 +04:00
|
|
|
// It's safe to make this a weak pointer, since it's the subject principal
|
|
|
|
// when we go on the stack, so can't go away until after we're gone. In
|
|
|
|
// particular, this is only used from the CallSetup constructor, and only in
|
|
|
|
// the aIsJSImplementedWebIDL case. And in that case, the subject principal
|
|
|
|
// is the principal of the callee function that is part of the CallArgs just a
|
|
|
|
// bit up the stack, and which will outlive us. So we know the principal
|
|
|
|
// can't go away until then either.
|
2015-01-18 22:07:02 +03:00
|
|
|
nsIPrincipal* MOZ_NON_OWNING_REF mWebIDLCallerPrincipal;
|
2014-02-15 10:36:44 +04:00
|
|
|
friend nsIPrincipal* GetWebIDLCallerPrincipal();
|
2014-11-14 00:22:24 +03:00
|
|
|
|
2015-05-20 12:28:00 +03:00
|
|
|
Maybe<DocshellEntryMonitor> mDocShellEntryMonitor;
|
2013-12-12 05:51:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A class that can be used to force a particular incumbent script on the stack.
|
|
|
|
*/
|
2014-02-15 10:36:43 +04:00
|
|
|
class AutoIncumbentScript : protected ScriptSettingsStackEntry {
|
2013-12-12 05:51:57 +04:00
|
|
|
public:
|
2014-07-28 21:17:51 +04:00
|
|
|
explicit AutoIncumbentScript(nsIGlobalObject* aGlobalObject);
|
2016-06-24 21:19:50 +03:00
|
|
|
~AutoIncumbentScript();
|
|
|
|
|
2013-12-12 05:51:57 +04:00
|
|
|
private:
|
2013-12-12 05:51:57 +04:00
|
|
|
JS::AutoHideScriptedCaller mCallerOverride;
|
2013-12-12 05:51:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2014-04-15 07:27:00 +04:00
|
|
|
* A class to put the JS engine in an unusable state. The subject principal
|
|
|
|
* will become System, the information on the script settings stack is
|
|
|
|
* rendered inaccessible, and JSAPI may not be manipulated until the class is
|
|
|
|
* either popped or an AutoJSAPI instance is subsequently pushed.
|
|
|
|
*
|
|
|
|
* This class may not be instantiated if an exception is pending.
|
2013-12-12 05:51:57 +04:00
|
|
|
*/
|
2014-06-13 10:24:13 +04:00
|
|
|
class AutoNoJSAPI : protected ScriptSettingsStackEntry {
|
2013-12-12 05:51:57 +04:00
|
|
|
public:
|
2016-06-24 21:19:51 +03:00
|
|
|
explicit AutoNoJSAPI();
|
2016-06-24 21:19:50 +03:00
|
|
|
~AutoNoJSAPI();
|
2013-12-12 05:51:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
2014-08-15 05:47:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use AutoJSContext when you need a JS context on the stack but don't have one
|
|
|
|
* passed as a parameter. AutoJSContext will take care of finding the most
|
|
|
|
* appropriate JS context and release it when leaving the stack.
|
|
|
|
*/
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII AutoJSContext {
|
2014-08-15 05:47:15 +04:00
|
|
|
public:
|
|
|
|
explicit AutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
|
|
|
|
operator JSContext*() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
JSContext* mCx;
|
2014-08-15 05:47:16 +04:00
|
|
|
dom::AutoJSAPI mJSAPI;
|
2014-08-15 05:47:15 +04:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AutoSafeJSContext is similar to AutoJSContext but will only return the safe
|
|
|
|
* JS context. That means it will never call nsContentUtils::GetCurrentJSContext().
|
|
|
|
*
|
|
|
|
* Note - This is deprecated. Please use AutoJSAPI instead.
|
|
|
|
*/
|
2016-03-18 06:23:55 +03:00
|
|
|
class MOZ_RAII AutoSafeJSContext : public dom::AutoJSAPI {
|
2014-08-15 05:47:15 +04:00
|
|
|
public:
|
|
|
|
explicit AutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
|
2016-03-18 06:23:55 +03:00
|
|
|
operator JSContext*() const
|
|
|
|
{
|
|
|
|
return cx();
|
|
|
|
}
|
|
|
|
|
2014-08-15 05:47:15 +04:00
|
|
|
private:
|
2016-03-18 06:23:55 +03:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2014-08-15 05:47:15 +04:00
|
|
|
};
|
|
|
|
|
2016-08-08 23:29:05 +03:00
|
|
|
/**
|
|
|
|
* Use AutoSlowOperation when native side calls many JS callbacks in a row
|
|
|
|
* and slow script dialog should be activated if too much time is spent going
|
|
|
|
* through those callbacks.
|
|
|
|
* AutoSlowOperation puts a JSAutoRequest on the stack so that we don't continue
|
|
|
|
* to reset the watchdog and CheckForInterrupt can be then used to check whether
|
|
|
|
* JS execution should be interrupted.
|
|
|
|
*/
|
|
|
|
class MOZ_RAII AutoSlowOperation : public dom::AutoJSAPI
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoSlowOperation(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
|
|
|
|
void CheckForInterrupt();
|
|
|
|
private:
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2013-12-12 05:51:57 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_ScriptSettings_h
|