Skip to content

Commit 7f4711e

Browse files
littledanMs2gersyg
authored
Integrate with JavaScript WeakRefs
The role of HTML here is strictly limited to being a task scheduling service for JavaScript and tracking incumbent globals. Co-authored-by: Ms2ger <[email protected]> Co-authored-by: Shu-yu Guo <[email protected]>
1 parent 9fcb6c3 commit 7f4711e

File tree

1 file changed

+80
-8
lines changed

1 file changed

+80
-8
lines changed

source

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,6 +2775,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
27752775

27762776
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-arraycreate">ArrayCreate</dfn> abstract operation</li>
27772777
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-call">Call</dfn> abstract operation</li>
2778+
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-clear-kept-objects">ClearKeptObjects</dfn> abstract operation</li>
2779+
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-cleanup-finalization-registry">CleanupFinalizationRegistry</dfn> abstract operation</li>
27782780
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-construct">Construct</dfn> abstract operation</li>
27792781
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-copydatablockbytes">CopyDataBlockBytes</dfn> abstract operation</li>
27802782
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-createbytedatablock">CreateByteDataBlock</dfn> abstract operation</li>
@@ -2788,6 +2790,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
27882790
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-getfunctionrealm">GetFunctionRealm</dfn> abstract operation</li>
27892791
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-hasownproperty">HasOwnProperty</dfn> abstract operation</li>
27902792
<li>The <dfn data-x="js-HostCallJobCallback" data-x-href="https://tc39.es/ecma262/#sec-hostcalljobcallback">HostCallJobCallback</dfn> abstract operation</li>
2793+
<li>The <dfn data-x="js-HostEnqueueFinalizationRegistryCleanupJob" data-x-href="https://tc39.es/ecma262/#sec-host-cleanup-finalization-registry">HostEnqueueFinalizationRegistryCleanupJob</dfn> abstract operation</li>
27912794
<li>The <dfn data-x="js-HostEnqueuePromiseJob" data-x-href="https://tc39.es/ecma262/#sec-hostenqueuepromisejob">HostEnqueuePromiseJob</dfn> abstract operation</li>
27922795
<li>The <dfn data-x="js-HostEnsureCanCompileStrings" data-x-href="https://tc39.es/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</dfn> abstract operation</li>
27932796
<li>The <dfn data-x="js-HostImportModuleDynamically" data-x-href="https://tc39.es/proposal-dynamic-import/#sec-hostimportmoduledynamically">HostImportModuleDynamically</dfn> abstract operation</li>
@@ -2834,11 +2837,14 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
28342837
<li>The <dfn data-x="js-strict-equality" data-x-href="https://tc39.es/ecma262/#sec-strict-equality-comparison">Strict Equality Comparison</dfn> algorithm</li>
28352838
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-atomics-object"><code>Atomics</code></dfn> object</li>
28362839
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-date-objects"><code>Date</code></dfn> class</li>
2840+
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-finalization-registry-objects"><code>FinalizationRegistry</code></dfn> class</li>
28372841
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-regexp-regular-expression-objects"><code>RegExp</code></dfn> class</li>
28382842
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-sharedarraybuffer-objects"><code>SharedArrayBuffer</code></dfn> class</li>
28392843
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-typeerror"><code>TypeError</code></dfn> class</li>
28402844
<li>The <dfn data-x="js-RangeError" data-x-href="https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror"><code>RangeError</code></dfn> class</li>
2845+
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-weak-ref-objects"><code>WeakRef</code></dfn> class</li>
28412846
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-eval-x"><code>eval()</code></dfn> function</li>
2847+
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-weak-ref.prototype.deref"><code>WeakRef.prototype.deref()</code></dfn> function</li>
28422848
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot">[[IsHTMLDDA]]</dfn> internal slot</li>
28432849
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-import-calls"><code>import()</code></dfn></li>
28442850
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-meta-properties"><code>import.meta</code></dfn></li>
@@ -90002,16 +90008,20 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
9000290008
<span data-x="JobCallback Record">JobCallback Records</span> which encapsulate JavaScript
9000390009
functions that are called as part of jobs. The JavaScript specification contains a number of
9000490010
<span>implementation-defined</span> abstract operations that lets the host define how jobs are
90005-
scheduled and how JobCallbacks are handled. This section defines them for user agent hosts.</p>
90011+
scheduled and how JobCallbacks are handled. HTML uses these abstract operations to <span
90012+
id="incumbent-settings-object-tracking-in-promises">track the <span>incumbent settings
90013+
object</span> in promises and <code>FinalizationRegistry</code> callbacks</span> by saving and
90014+
restoring the <span>incumbent settings object</span> and a <span>JavaScript execution
90015+
context</span> for the <span>active script</span> in JobCallbacks. This section defines them for
90016+
user agent hosts.</p>
9000690017

9000790018
<h6 id="hostcalljobcallback"><dfn>HostCallJobCallback</dfn>(<var>callback</var>, <var>V</var>,
9000890019
<var>argumentsList</var>)</h6>
9000990020

9001090021
<p>JavaScript contains an <span>implementation-defined</span> <span
9001190022
data-x="js-HostCallJobCallback">HostCallJobCallback</span>(<var>callback</var>, <var>V</var>,
9001290023
<var>argumentsList</var>) abstract operation to let hosts restore state when invoking JavaScript
90013-
callbacks from inside tasks. HTML restores the <span>incumbent settings object</span> and the
90014-
<span>active script</span>. User agents must use the following implementation: <ref
90024+
callbacks from inside tasks. User agents must use the following implementation: <ref
9001590025
spec=JAVASCRIPT></p>
9001690026

9001790027
<ol>
@@ -90049,6 +90059,62 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
9004990059
<li><p>Return <var>result</var>.</p></li>
9005090060
</ol>
9005190061

90062+
<h6
90063+
id="hostenqueuefinalizationregistrycleanupjob"><dfn>HostEnqueueFinalizationRegistryCleanupJob</dfn>(<var>finalizationRegistry</var>)</h6>
90064+
90065+
<p>JavaScript has the ability to register objects with <code>FinalizationRegistry</code> objects,
90066+
in order to schedule a cleanup action if they are found to be garbage collected. The JavaScript
90067+
specification contains an <span>implementation-defined</span> <span
90068+
data-x="js-HostEnqueueFinalizationRegistryCleanupJob">HostEnqueueFinalizationRegistryCleanupJob</span>(<var>finalizationRegistry</var>)
90069+
abstract operation to schedule the cleanup action.</p>
90070+
90071+
<p class="note">The timing and occurrence of cleanup work is <span>implementation-defined</span>
90072+
in the JavaScript specification. User agents might differ in when and whether an object is garbage
90073+
collected, affecting both whether the return value of the <code>WeakRef.prototype.deref()</code>
90074+
method is undefined, and whether <code>FinalizationRegistry</code> cleanup callbacks occur. There
90075+
are well-known cases in popular web browsers where objects are not accessible to JavaScript, but
90076+
they remain retained by the garbage collector indefinitely. HTML clears kept-alive
90077+
<code>WeakRef</code> objects in the <span>perform a microtask checkpoint</span> algorithm. Authors
90078+
would be best off not depending on the timing details of garbage collection implementations.</p>
90079+
90080+
<p>Cleanup actions do not take place interspersed with synchronous JavaScript execution, but
90081+
rather happen in queued <span data-x="concept-task">tasks</span>. User agents must use the
90082+
following implementation: <ref spec=JAVASCRIPT></p>
90083+
90084+
<ol>
90085+
<li><p>Let <var>global</var> be <var>finalizationRegistry</var>.[[Realm]]'s <span>global
90086+
object</span>.</p></li>
90087+
90088+
<li>
90089+
<p><span>Queue a global task</span> on the <dfn>JavaScript engine task source</dfn> given
90090+
<var>global</var> to perform the following steps:</p>
90091+
90092+
<ol>
90093+
<li><p>Let <var>entry</var> be
90094+
<var>finalizationRegistry</var>.[[CleanupCallback]].[[Callback]].[[Realm]]'s <span
90095+
data-x="concept-realm-settings-object">environment settings object</span>.</p></li>
90096+
90097+
<li><p><span>Check if we can run script</span> with <var>entry</var>. If this returns "do not
90098+
run", then return.</p></li>
90099+
90100+
<li>
90101+
<p><span>Prepare to run script</span> with <var>entry</var>.</p>
90102+
90103+
<p class="note">This affects the <span data-x="concept-entry-everything">entry</span> concept
90104+
while the cleanup callback runs.</p>
90105+
</li>
90106+
90107+
<li><p>Let <var>result</var> be the result of performing
90108+
<span>CleanupFinalizationRegistry</span>(<var>finalizationRegistry</var>).</p></li>
90109+
90110+
<li><p><span>Clean up after running script</span> with <var>entry</var>.</p></li>
90111+
90112+
<li><p>If <var>result</var> is an <span>abrupt completion</span>, then <span>report the
90113+
exception</span> given by <var>result</var>.[[Value]].</p></li>
90114+
</ol>
90115+
</li>
90116+
</ol>
90117+
9005290118
<span id="integration-with-the-javascript-job-queue"></span>
9005390119
<span id="enqueuejob(queuename,-job,-arguments)"></span>
9005490120
<h6 id="hostenqueuepromisejob"><dfn>HostEnqueuePromiseJob</dfn>(<var>job</var>,
@@ -90123,11 +90189,8 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
9012390189
<p>JavaScript contains an <span>implementation-defined</span> <span
9012490190
data-x="js-HostMakeJobCallback">HostMakeJobCallback</span>(<var>callable</var>) abstract operation
9012590191
to let hosts attach state to JavaScript callbacks that are called from inside <span
90126-
data-x="concept-task">task</span>s. HTML <span
90127-
id="incumbent-settings-object-tracking-in-promises">tracks the <span>incumbent settings
90128-
object</span> in promises</span> by saving the <span>incumbent settings object</span> and a
90129-
<span>JavaScript execution context</span> for the <span>active script</span>. User agents must use
90130-
the following implementation: <ref spec=JAVASCRIPT></p>
90192+
data-x="concept-task">task</span>s. User agents must use the following implementation: <ref
90193+
spec=JAVASCRIPT></p>
9013190194

9013290195
<ol>
9013390196
<li><p>Let <var>incumbent settings</var> be the <span>incumbent settings object</span>.</p></li>
@@ -90187,6 +90250,7 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
9018790250
<var>script execution context</var> } }.</p></li>
9018890251
</ol>
9018990252

90253+
9019090254
<h5 id="integration-with-the-javascript-module-system">Module-related host hooks</h5>
9019190255

9019290256
<p>The JavaScript specification defines a syntax for modules, as well as some host-agnostic parts
@@ -91067,6 +91131,14 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
9106791131

9106891132
<li><p><span>Cleanup Indexed Database transactions</span>.</p></li>
9106991133

91134+
<li>
91135+
<p>Perform <span>ClearKeptObjects</span>().</p>
91136+
91137+
<p class="note">When <code>WeakRef.prototype.deref()</code> returns an object, that object is
91138+
kept alive until the next invocation of <span>ClearKeptObjects</span>(), after which it is again
91139+
subject to garbage collection.</p>
91140+
</li>
91141+
9107091142
<li><p>Set the <span>event loop</span>'s <span>performing a microtask checkpoint</span> to
9107191143
false.</p></li>
9107291144
</ol>

0 commit comments

Comments
 (0)