Skip to content

Commit 22d8cdb

Browse files
mgaudetdomenic
authored andcommitted
Disallow adding private fields to Location and WindowProxy
This uses the new HostEnsureCanAddPrivateElement host hook defined in the JavaScript specification to prevent using the super-override trick to add private fields to these host objects. Fixes #7952.
1 parent b9b1cfe commit 22d8cdb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

source

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,6 +2899,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
28992899
<li>The <dfn data-x="js-HostCallJobCallback" data-x-href="https://tc39.es/ecma262/#sec-hostcalljobcallback">HostCallJobCallback</dfn> abstract operation</li>
29002900
<li>The <dfn data-x="js-HostEnqueueFinalizationRegistryCleanupJob" data-x-href="https://tc39.es/ecma262/#sec-host-cleanup-finalization-registry">HostEnqueueFinalizationRegistryCleanupJob</dfn> abstract operation</li>
29012901
<li>The <dfn data-x="js-HostEnqueuePromiseJob" data-x-href="https://tc39.es/ecma262/#sec-hostenqueuepromisejob">HostEnqueuePromiseJob</dfn> abstract operation</li>
2902+
<li>The <dfn data-x="js-HostEnsureCanAddPrivateElement" data-x-href="https://tc39.es/ecma262/#sec-hostensurecanaddprivateelement">HostEnsureCanAddPrivateElement</dfn> abstract operation</li>
29022903
<li>The <dfn data-x="js-HostEnsureCanCompileStrings" data-x-href="https://tc39.es/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</dfn> abstract operation</li>
29032904
<li>The <dfn data-x="js-HostImportModuleDynamically" data-x-href="https://tc39.es/proposal-dynamic-import/#sec-hostimportmoduledynamically">HostImportModuleDynamically</dfn> abstract operation</li>
29042905
<li>The <dfn data-x="js-HostMakeJobCallback" data-x-href="https://tc39.es/ecma262/#sec-hostmakejobcallback">HostMakeJobCallback</dfn> abstract operation</li>
@@ -94762,6 +94763,28 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
9476294763
operations, that vary depending on the host environment. This section defines them for user
9476394764
agent hosts.</p>
9476494765

94766+
<h5 id="the-hostensurecanaddprivateelement-implementation"><dfn>HostEnsureCanAddPrivateElement</dfn>(<var>O</var>)</h5>
94767+
94768+
<p>JavaScript contains an <span>implementation-defined</span> <span
94769+
data-x="js-HostEnsureCanAddPrivateElement">HostEnsureCanAddPrivateElement</span>(<var>O</var>)
94770+
abstract operation. User agents must use the following implementation: <ref spec=JAVASCRIPT>
94771+
94772+
<ol>
94773+
<li><p>If <var>O</var> is a <code>WindowProxy</code> object, or <span>implements</span>
94774+
<code>Location</code>, then return Completion { [[Type]]: throw, [[Value]]: a new
94775+
<code>TypeError</code> }.</li>
94776+
94777+
<li><p>Return <span>NormalCompletion</span>(unused).</p></li>
94778+
</ol>
94779+
94780+
<p class="note">JavaScript private fields can be applied to arbitrary objects. Since this can
94781+
dramatically complicate implementation for particularly-exotic host objects, the JavaScript
94782+
language specification provides this hook to allow hosts to reject private fields on objects
94783+
meeting a host-defined criteria. In the case of HTML, <code>WindowProxy</code> and
94784+
<code>Location</code> have complicated semantics &mdash; particularly around navigation and
94785+
security &mdash; that make implementation of private field semantics challenging, so our
94786+
implementation simply rejects those objects.</p>
94787+
9476594788
<h5><dfn data-x="the-hostensurecancompilestrings-implementation">HostEnsureCanCompileStrings</dfn>(<var>realm</var>)</h5>
9476694789

9476794790
<p>JavaScript contains an <span>implementation-defined</span> <span
@@ -128677,6 +128700,7 @@ INSERT INTERFACES HERE
128677128700
Matt Falkenhagen,
128678128701
Matt Schmidt,
128679128702
Matt Wright,
128703+
Matthew Gaudet, <!-- mgaudet on GitHub -->
128680128704
Matthew Gregan,
128681128705
Matthew Mastracci,
128682128706
Matthew Noorenberghe,

0 commit comments

Comments
 (0)