From 72626cd3b4cee99fc87630bcf7035ec289c9b8c6 Mon Sep 17 00:00:00 2001
From: Domenic Denicola The following features are defined in the Battery Status API specification:
+
+
+ getBattery()
method
+
A global object is a JavaScript object that is the [[GlobalObject]] field of a - JavaScript realm.
- -In this specification, all JavaScript
- realms are initialized with global objects that are either Window
or
- WorkerGlobalScope
objects.
There is always a 1:1:1 mapping between JavaScript - realms, global objects, and environment settings objects:
- -A JavaScript realm has a [[HostDefined]] field, which contains the Realm's settings object.
A JavaScript realm has a [[GlobalObject]] field, which contains the Realm's global object.
Each global object in this specification is created during the initialization of a corresponding JavaScript - realm, known as the global object's - Realm.
Each global object in this - specification is created alongside a corresponding environment settings object, - known as its relevant settings object.
- -An environment settings object's realm execution context's - Realm component is the environment settings - object's Realm.
An environment settings object's Realm then has a [[GlobalObject]] field, which contains the environment settings object's global - object.
The relevant settings object for a non-global platform object - o is the environment settings object whose global object is the global object of the - global environment associated with o.
- -The various script-fetching algorithms below have two hooks that may be customized by their @@ -87347,7 +87312,7 @@ interface NavigatorOnLine { -
To run a classic script given a classic script s and an optional rethrow errors flag:
@@ -87470,7 +87435,8 @@ interface NavigatorOnLine {Label settings as a candidate entry settings object.
Set settings's realm execution context's is candidate entry + execution context flag to true.
Push settings's realm execution context onto the JavaScript
execution context stack; it is now the running JavaScript execution
@@ -87484,12 +87450,12 @@ interface NavigatorOnLine {
Stop labeling settings as a candidate entry settings
- object. Assert: settings's realm execution context is the running
JavaScript execution context. Set settings's realm execution context's is candidate entry
+ execution context flag to false. Remove settings's realm execution context from the
JavaScript execution context stack. A JavaScript execution context's settings object is the
- settings object of the script in the [[HostDefined]] field in the
- ScriptOrModule component of the given JavaScript execution context. Each unit of related similar-origin browsing contexts has a global script
+ clean-up jobs list, which must initially be empty. A global script clean-up job cannot run
+ scripts, and cannot be sensitive to the order in which other clean-up jobs are executed. The File
+ API uses this to release When the user agent is to run the global script clean-up jobs, the user agent must
+ perform each of the jobs in the global script clean-up jobs list and then empty the
+ list. The current settings object is the environment settings object of the current
- Realm Record. A global object is a JavaScript object that is the [[GlobalObject]] field of a
+ JavaScript realm. In this specification, all JavaScript
+ realms are initialized with global objects that are either There is always a 1:1:1 mapping between JavaScript
+ realms, global objects, and environment settings objects: A JavaScript realm has a [[HostDefined]] field, which contains the Realm's settings object. A JavaScript realm has a [[GlobalObject]] field, which contains the Realm's global object. Each global object in this specification is created during the initialization of a corresponding JavaScript
+ realm, known as the global object's
+ Realm. Each global object in this
+ specification is created alongside a corresponding environment settings object,
+ known as its relevant settings object. The entry settings object is the settings object of the topmost entry in the JavaScript execution
- context stack whose settings object is labeled as a candidate entry settings object. An environment settings object's realm execution context's
+ Realm component is the environment settings
+ object's Realm. An environment settings object's Realm then has a [[GlobalObject]] field, which contains the environment settings object's global
+ object. When defining algorithm steps throughout this specification, it is often important to indicate
+ what JavaScript realm is to be used—or, equivalently, what global object
+ or settings object is to be used. In general, there are four possibilities: Consider the following pages, with Each page has its own browsing context, and thus its own JavaScript
+ realm, global object, and settings object. When the button is pressed in The entry settings object is that of The incumbent settings object is that of The current settings object is that of The relevant settings object of the object on which the The incumbent concept should not be used by
+ new specifications, and we are considering whether it can be removed from the platform. See Bugzilla bug 26603. Currently, the
+ incumbent concept is used in some security
+ checks. There is currently discussion about whether the entry concept should be used going forward; see Bugzilla bug 27203. Currently, the
+ entry concept is used to obtain, amongst other
+ things, the API base URL to parse a URL, used in
+ scripts running in that unit of related similar-origin browsing contexts. In general, the current concept is what should
+ be used by specifications going forward. There is an important exception, however. If an algorithm
+ is creating an object that is to be persisted and returned multiple times (instead of simply
+ returned to author code right away, and never vended again), it should use the relevant concept with regard to the object on which
+ the method in question is being executed. This prevents cross-realm calls from causing an object
+ to store objects created in the "wrong" realm. The If the algorithm for the The rest of this section deals with formally defining the entry, incumbent, current, and relevant concepts. All JavaScript execution contexts must
+ contain a boolean flag, is candidate entry execution context, which is initially set
+ to false. In the process of calling scripts, this flag can be
+ toggled. With this in hand, we define the entry execution context to be the topmost entry in
+ the JavaScript execution context stack whose is candidate entry execution
+ context flag is set to true. The entry Realm is
+ the entry execution context's Realm component. Then, the entry settings object is the environment settings object of the entry Realm. Similarly, the entry global object is the global object of the entry
+ Realm. The incumbent settings object is determined as follows:
-
- blob:
URLs. Realms, settings objects, and global objects
+
+ Window
or
+ WorkerGlobalScope
objects.
+
+
+
+
+
+ a.html
being loaded in a browser
+ window, b.html
being loaded in an iframe
as shown, and c.html
and d.html
omitted (they can simply be empty
+ documents):<!-- a.html -->
+<!DOCTYPE html>
+<html lang="en">
+<title>Entry page</title>
+
+<iframe src="b.html"></iframe>
+<button onclick="frames[0].hello()">Hello</button>
+
+<!--b.html -->
+<!DOCTYPE html>
+<html lang="en">
+<title>Incumbent page</title>
+
+<iframe src="c.html" id="c"></iframe>
+<iframe src="d.html" id="d"></iframe>
+
+<script>
+ const c = document.querySelector("#c").contentWindow;
+ const d = document.querySelector("#d").contentWindow;
+
+ window.hello = () => {
+ c.print.call(d);
+ };
+</script>
+
+ a.html
, then:
+
+ a.html
.b.html
.c.html
(since
+ it is the print()
method from c.html
+ whose code is running).print()
method is being called is that of d.html
.navigator.getBattery()
method creates
+ promises in the relevant Realm for the
+ Navigator
object on which it is invoked. This has the following impact:
+
+ <!DOCTYPE html>
+<html lang="en">
+<title>Relevant Realm demo</title>
+
+<iframe src="about:blank"></iframe>
+<script>
+ const promise = navigator.getBattery().call(frames[0].navigator);
+
+ console.log(promise instanceof Promise); // logs false
+ console.log(promise instanceof frames[0].Promise); // logs true
+</script>
+
+ getBattery()
method
+ had instead used the current Realm, the results would
+ be reversed. The downside of such an approach would be that all future calls to that frame's
+ getBattery()
, even ones from within the
+ iframe
and without cross-frame shenanigans, would forever return Promise
objects from the outer realm. Since this is undesirable, the algorithm
+ instead uses the relevant Realm.
+
+ Entry
+
+ Incumbent
The entry settings object is used to obtain, amongst other things, the API - base URL to parse a URL, used in scripts running in that - unit of related similar-origin browsing contexts.
+Then, the incumbent Realm is the Realm of the incumbent settings + object.
-The incumbent settings object is used in some security checks.
-The incumbent settings object concept should not be used by new - specifications, and we are considering whether it can be removed from the platform. See Bugzilla bug 26603.
+Similarly, the incumbent global object is the + global object of the incumbent + settings object.
-Consider the following two pages, with the first being loaded in a browser window and the
- second being loaded in the iframe
of the first:
The JavaScript specification defines the current Realm Record, sometimes + abbreviated to "the current Realm".
-<!-- a/a.html --> -<!DOCTYPE HTML> -<html lang="en"> -<title>Outer page</title> -<iframe src="../b/b.html"></iframe> -<input type=button onclick="frames[0].hello()" value="Hello">+
Then, the current settings object is the environment settings object of the current + Realm Record.
-<!-- b/b.html --> -<!DOCTYPE HTML> -<html lang="en"> -<title>Inner page</title> -<script> - function hello() { - location.assign('c.html'); - } -</script>+
Similarly, the current global object is the global object of the current Realm Record.
-When the button is pressed in the inner frame, the outer page runs script in the inner page.
- While the hello()
function is running, the entry settings
- object is that of the outer file (a/a.html
), and the
- incumbent settings object is that of the inner file (b/b.html
).
The assign()
method uses the entry settings
- object to parse the URL, so we end up loading a/c.html
, but it uses the incumbent settings object to establish
- the source browsing context, from which the referrer is established, so the `Referer
` header sent with the request for a/c.html
specifies the inner file's URL (the one ending with b/b.html
).
The relevant settings object for a platform object is defined as + follows:
- +The relevant settings object for a non-global platform object + o is the environment settings object whose global object is the global object of the + global environment associated with o.
-The "global environment associated with" concept is from the olden + days, before the modern JavaScript specification and its concept of realms. We expect that as the Web IDL specification gets updated, every + platform object will have a Realm associated + with it, and this definition can be re-cast in those terms.
+Each unit of related similar-origin browsing contexts has a global script
- clean-up jobs list, which must initially be empty. A global script clean-up job cannot run
- scripts, and cannot be sensitive to the order in which other clean-up jobs are executed. The File
- API uses this to release blob:
URLs.
Then, the relevant Realm for a platform + object is the Realm of its + relevant settings object.
-When the user agent is to run the global script clean-up jobs, the user agent must - perform each of the jobs in the global script clean-up jobs list and then empty the - list.
+Similarly, the relevant global object for a + platform object is the global + object of its relevant settings object.
Assert: queueName is "PromiseJobs"
. ("ScriptJobs"
must not be used by user agents.)
Let settings be the current settings object.
Let settings be the settings + object of job.[[Realm]].
Queue a microtask, on settings's responsible event loop, to perform the following steps:
@@ -118546,6 +118690,9 @@ INSERT INTERFACES HERE