Skip to content

Commit 488e201

Browse files
domenicannevk
authored andcommitted
Update advice to favor the relevant realm over the current one
Fixes whatwg#1653, and also clarifies and tidies up some stuff while in the area.
1 parent 9e38ff4 commit 488e201

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

source

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87199,15 +87199,16 @@ interface <dfn>NavigatorOnLine</dfn> {
8719987199

8720087200
<dt><dfn data-x="concept-current-everything">Current</dfn></dt>
8720187201
<dd>This corresponds to the currently-running function object, including built-in user-agent
87202-
functions which might not be implemented as JavaScript. (It is derived from the <span>current
87203-
JavaScript realm</span>.)</dd>
87202+
functions which might not be implemented as JavaScript. (It is derived from the <span
87203+
data-x="current Realm Record">current JavaScript realm</span>.)</dd>
8720487204

8720587205
<dt><dfn data-x="concept-relevant-everything">Relevant</dfn></dt>
8720687206
<dd>Every <span>platform object</span> has a <span data-x="concept-relevant-realm">relevant
87207-
Realm</span>. When writing algorithms, the most prominent <span>platform object</span> whose
87208-
<span data-x="concept-relevant-realm">relevant Realm</span> might be important is the
87209-
<b>this</b> value of the currently-running function object. In some cases, there can be other
87210-
important <span data-x="concept-relevant-realm">relevant Realms</span>, such as those of any
87207+
Realm</span>, which is roughly the <span>JavaScript realm</span> in which it was created. When
87208+
writing algorithms, the most prominent <span>platform object</span> whose <span
87209+
data-x="concept-relevant-realm">relevant Realm</span> might be important is the <b>this</b>
87210+
value of the currently-running function object. In some cases, there can be other important
87211+
<span data-x="concept-relevant-realm">relevant Realms</span>, such as those of any
8721187212
arguments.</dd>
8721287213
</dl>
8721387214

@@ -87271,31 +87272,33 @@ interface <dfn>NavigatorOnLine</dfn> {
8727187272

8727287273
<p class="warning">The <span data-x="concept-incumbent-everything">incumbent</span> and <span
8727387274
data-x="concept-entry-everything">entry</span> concepts should not be used by new specifications,
87274-
and we are considering whether we can remove almost all existing uses. See <a
87275-
href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=26603">Bugzilla bug 26603</a> for <span
87275+
as they are excessively complicated and unintuitive to work with. We are working to remove almost
87276+
all existing uses from the platform: see <a
87277+
href="https://github.com/whatwg/html/issues/1430">issue #1430</a> for <span
8727687278
data-x="concept-incumbent-everything">incumbent</span>, and <a
87277-
href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=27203">Bugzilla bug 27203</a> for <span
87279+
href="https://github.com/whatwg/html/issues/1431">issue #1431</a> for <span
8727887280
data-x="concept-entry-everything">entry</span>.</p>
8727987281

87280-
<p class="note">Currently, the <span data-x="concept-incumbent-everything">incumbent</span>
87281-
concept is used in some security checks, and the <span
87282-
data-x="concept-entry-everything">entry</span> concept is sometimes used to obtain, amongst other
87283-
things, the <span>API base URL</span> to <span data-x="parse a url">parse a URL</span>, used in
87284-
scripts running in that <span>unit of related similar-origin browsing contexts</span>.</p>
87282+
<p>In general, web platform specifications should use the <span
87283+
data-x="concept-relevant-everything">relevant</span> concept, applied to the object being operated
87284+
on (usually the <b>this</b> value of the current method). This mismatches the JavaScript
87285+
specification, where <span data-x="concept-current-everything">current</span> is generally used as
87286+
the default (e.g. in determining the <span>JavaScript realm</span> whose <code
87287+
data-x="">Array</code> constructor should be used to construct the result in <code
87288+
data-x="">Array.prototype.map</code>). But this inconsistency is so embedded in the platform that
87289+
we have to accept it going forward.</p>
8728587290

87286-
<p>In general, the <span data-x="concept-current-everything">current</span> concept is what should
87287-
be used by specifications going forward. There is an important exception, however. If an algorithm
87288-
is creating an object that is to be persisted and returned multiple times (instead of simply
87289-
returned to author code right away, and never vended again), it should use the <span
87290-
data-x="concept-relevant-everything">relevant</span> concept with regard to the object on which
87291-
the method in question is being executed. This prevents cross-realm calls from causing an object
87292-
to store objects created in the "wrong" realm.</p>
87291+
<p>Note that in constructors, where there is no <b>this</b> value yet, the <span
87292+
data-x="concept-current-everything">current</span> concept is the appropriate default.</p>
8729387293

8729487294
<div class="example">
87295-
<p>The <code data-x="dom-navigator-getBattery">navigator.getBattery()</code> method creates
87296-
promises in the <span data-x="concept-relevant-realm">relevant Realm</span> for the
87297-
<code>Navigator</code> object on which it is invoked. This has the following impact: <ref
87298-
spec=BATTERY>
87295+
<p>One reason why the <span data-x="concept-relevant-everything">relevant</span> concept is
87296+
generally a better default choice than the <span
87297+
data-x="concept-current-everything">current</span> concept is that it is more suitable for
87298+
creating an object that is to be persisted and returned multiple times. For example, the <code
87299+
data-x="dom-navigator-getBattery">navigator.getBattery()</code> method creates promises in the
87300+
<span data-x="concept-relevant-realm">relevant Realm</span> for the <code>Navigator</code> object
87301+
on which it is invoked. This has the following impact: <ref spec=BATTERY>
8729987302

8730087303
<pre>&lt;!-- outer.html -->
8730187304
&lt;!DOCTYPE html>

0 commit comments

Comments
 (0)