Skip to content

Commit

Permalink
Ensure there is an active script while running JS jobs
Browse files Browse the repository at this point in the history
"Fixes" tc39/ecma262#871, at least for HTML,
given that we have our own version of EnqueueJob. Important for #3117.
  • Loading branch information
domenic committed Nov 17, 2017
1 parent 3a413b6 commit 1e0b334
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3014,6 +3014,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-enumerableownproperties">EnumerableOwnProperties</dfn> abstract operation</li>
<li>The <dfn data-x="js-FunctionCreate" data-x-href="https://tc39.github.io/ecma262/#sec-functioncreate">FunctionCreate</dfn> abstract operation</li>
<li>The <dfn data-x="js-Get" data-x-href="https://tc39.github.io/ecma262/#sec-get-o-p">Get</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-getactivescriptormodule">GetActiveScriptOrModule</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-getfunctionrealm">GetFunctionRealm</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-hasownproperty">HasOwnProperty</dfn> abstract operation</li>
<li>The <dfn data-x="js-HostEnsureCanCompileStrings" data-x-href="https://tc39.github.io/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</dfn> abstract operation</li>
Expand Down Expand Up @@ -86186,6 +86187,16 @@ interface <dfn>NavigatorOnLine</dfn> {
data-x="concept-script">script</span>. It has no additional <span data-x="struct
item">items</span>.</p>

<p>The <dfn>active script</dfn> is determined by the following algorithm:</p>

<ol>
<li><p>Let <var>record</var> be <span>GetActiveScriptOrModule</span>().</p></li>

<li><p>If <var>record</var> is null, return null.</p></li>

<li><p>Return <var>record</var>.[[HostDefined]].</p></li>
</ol>

<hr>

<p>An <dfn data-export="">environment</dfn> is an object that identifies the settings of a
Expand Down Expand Up @@ -87933,6 +87944,17 @@ document.querySelector("button").addEventListener("click", bound);

<li><p>Let <var>incumbent settings</var> be the <span>incumbent settings object</span>.</p></li>

<li><p>Let <var>active script</var> be the <span>active script</span>.</p></li>

<li><p>Assert: <var>active script</var> is not null, as jobs are only enqueued by the JavaScript
specification while a script is active.</p></li>

<li><p>Let <var>script execution context</var> be a new <span>JavaScript execution
context</span>, with its Function field set to null, its Realm field set to <var>active
script</var>'s <span>settings object</span>'s <span data-x="environment settings object's
Realm">Realm</span>, and its ScriptOrModule set to <var>active script</var>'s <span
data-x="concept-script-record">record</span>.</p></li>

<li>
<p><span>Queue a microtask</span>, on <var>job settings</var>'s <span>responsible event
loop</span>, to perform the following steps:</p>
Expand All @@ -87941,13 +87963,36 @@ document.querySelector("button").addEventListener("click", bound);
<li><p><span>Check if we can run script</span> with <var>job settings</var>. If this returns
"do not run" then return.</p></li>

<li><p><span>Prepare to run script</span> with <var>job settings</var>.</p></li>
<li>
<p><span>Prepare to run script</span> with <var>job settings</var>.</p>

<p class="note">This affects the <span data-x="concept-entry-everything">entry</span> concept
while the job runs.</p>
</li>

<li>
<p><span>Prepare to run a callback</span> with <var>incumbent settings</var>.</p>

<li><p><span>Prepare to run a callback</span> with <var>incumbent settings</var>.</p></li>
<p class="note">This affects the <span data-x="concept-incumbent-everything">incumbent</span>
concept while the job runs.</p>
</li>

<li>
<p><span data-x="stack push">Push</span> <var>script execution context</var> onto the
<span>JavaScript execution context stack</span>.</p>

<p class="note">This affects the <span>active script</span> while the job runs, in cases like
<code data-x="">Promise.resolve("...").then(eval)</code> where there would otherwise be no
active script since <code data-x="">eval</code> is a built-in function that does not originate
from any particular <span data-x="concept-script">script</span>.</p>
</li>

<li><p>Let <var>result</var> be the result of performing the abstract operation specified by
<var>job</var>, using the elements of <var>arguments</var> as its arguments.</p></li>

<li><p><span data-x="stack pop">Pop</span> <var>script execution context</var> from the
<span>JavaScript execution context stack</span>.</p></li>

<li><p><span>Clean up after running a callback</span> with <var>incumbent
settings</var>.</p></li>

Expand Down

0 comments on commit 1e0b334

Please sign in to comment.