Skip to content

Commit 74a78cb

Browse files
authored
Make Location's toString() work and drop its toJSON()
I mistakenly copied all boilerplate from IDL’s unforgeable interfaces concept (which was only ever used for Location) and thereby turned the toString() fallback behavior into the actual behavior (or an exception arguably, as [[Configurable]] is false). We also determined that only Firefox supports an unforgeable toJSON() and nobody really has a use for it, so that is dropped. Tests: web-platform-tests/wpt#4623. Fixes #2284.
1 parent 93c0a15 commit 74a78cb

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

source

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,8 +2882,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
28822882
<dfn>@@toStringTag</dfn></li>
28832883
<li><dfn data-x-href="https://tc39.github.io/ecma262/#sec-well-known-intrinsic-objects">Well-Known Intrinsic Objects</dfn>, including
28842884
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-arraybuffer-constructor">%ArrayBuffer%</dfn>,
2885-
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-properties-of-the-array-prototype-object">%ArrayPrototype%</dfn>,
2886-
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-object.prototype.tostring">%ObjProto_toString%</dfn>, and
2885+
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-properties-of-the-array-prototype-object">%ArrayPrototype%</dfn>, and
28872886
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-object.prototype.valueof">%ObjProto_valueOf%</dfn></li>
28882887

28892888
<li>The <dfn data-x="js-prod-FunctionBody" data-x-href="https://tc39.github.io/ecma262/#prod-FunctionBody"><i>FunctionBody</i></dfn> production</li>
@@ -80539,18 +80538,6 @@ State: &lt;OUTPUT NAME=I>1&lt;/OUTPUT> &lt;INPUT VALUE="Increment" TYPE=BUTTON O
8053980538
<li><p>Let <var>location</var> be a new <code>Location</code> <span>platform
8054080539
object</span>.</p></li>
8054180540

80542-
<li><p>Perform ! <var>location</var>.[[DefineOwnProperty]]("<code data-x="">toString</code>", {
80543-
[[Value]]: <span>%ObjProto_toString%</span>,
80544-
[[Writable]]: false,
80545-
[[Enumerable]]: false,
80546-
[[Configurable]]: false }).</p></li>
80547-
80548-
<li><p>Perform ! <var>location</var>.[[DefineOwnProperty]]("<code data-x="">toJSON</code>", {
80549-
[[Value]]: undefined,
80550-
[[Writable]]: false,
80551-
[[Enumerable]]: false,
80552-
[[Configurable]]: false }).</p></li>
80553-
8055480541
<li><p>Perform ! <var>location</var>.[[DefineOwnProperty]]("<code data-x="">valueOf</code>", {
8055580542
[[Value]]: <span>%ObjProto_valueOf%</span>,
8055680543
[[Writable]]: false,
@@ -80569,6 +80556,16 @@ State: &lt;OUTPUT NAME=I>1&lt;/OUTPUT> &lt;INPUT VALUE="Increment" TYPE=BUTTON O
8056980556
<li><p>Return <var>location</var>.</p></li>
8057080557
</ol>
8057180558

80559+
<p class="note">The addition of <code data-x="">valueOf</code> and <span>@@toPrimitive</span> own
80560+
data properties, as well as the fact that all of <code>Location</code>'s IDL attributes are marked
80561+
<code data-x="">[Unforgeable]</code>, is required by legacy code that consulted the
80562+
<code>Location</code> interface, or stringified it, to determine the <span
80563+
data-x="concept-document-url">document URL</span>, and then used it in a security-sensitive way.
80564+
In particular, the <code data-x="">valueOf</code>, <span>@@toPrimitive</span>, and <code
80565+
data-x="">[Unforgeable]</code> stringifier mitigations ensure that code such as <code
80566+
data-x="">foo[location] = bar</code> or <code data-x="">location + ""</code> cannot be
80567+
misdirected.</p>
80568+
8057280569
</div>
8057380570

8057480571
<dl class="domintro">
@@ -80605,7 +80602,7 @@ State: &lt;OUTPUT NAME=I>1&lt;/OUTPUT> &lt;INPUT VALUE="Increment" TYPE=BUTTON O
8060580602
<span>current entry</span> of the <span>browsing context</span>'s session history to be changed,
8060680603
by adding or replacing entries in the <code data-x="dom-history">history</code> object.</p>
8060780604

80608-
<pre class="idl">interface <dfn>Location</dfn> {
80605+
<pre class="idl">interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface">additional creation steps</a> and <a href="#location-internal-methods">overridden internal methods</a>
8060980606
[Unforgeable] stringifier attribute USVString <span data-x="dom-location-href">href</span>;
8061080607
[Unforgeable] readonly attribute USVString <span data-x="dom-location-origin">origin</span>;
8061180608
[Unforgeable] attribute USVString <span data-x="dom-location-protocol">protocol</span>;
@@ -81269,9 +81266,9 @@ State: &lt;OUTPUT NAME=I>1&lt;/OUTPUT> &lt;INPUT VALUE="Increment" TYPE=BUTTON O
8126981266

8127081267
<hr>
8127181268

81272-
<p>As explained earlier, the <code>Location</code> exotic object requires additional logic beyond
81273-
IDL for security purposes. The internal slot and internal methods <code>Location</code> objects
81274-
must implement are defined below.</p>
81269+
<p id="location-internal-methods">As explained earlier, the <code>Location</code> exotic object
81270+
requires additional logic beyond IDL for security purposes. The internal slot and internal methods
81271+
<code>Location</code> objects must implement are defined below.</p>
8127581272

8127681273
<p>Every <code>Location</code> object has a <dfn>[[DefaultProperties]]</dfn> internal slot
8127781274
representing its own properties at time of its creation.</p>
@@ -119246,6 +119243,7 @@ INSERT INTERFACES HERE
119246119243
Ami Fischman,
119247119244
Amos Jeffries,
119248119245
Anders Carlsson,
119246+
André Bargull,
119249119247
Andr&eacute; E. Veltstra,
119250119248
Andrea Rendine,
119251119249
Andreas<!-- mqmq87 -->,

0 commit comments

Comments
 (0)