Permalink
Browse files

Ensure there is an active script while running JS jobs

"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 8b055c0 commit cc3fcc87a7c6f8783efa327b449d7381a0e0303d
Showing with 48 additions and 2 deletions.
  1. +48 −2 source
View
50 source
@@ -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>
@@ -3056,6 +3057,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-sharedarraybuffer-objects"><code>SharedArrayBuffer</code></dfn> class</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror"><code>TypeError</code></dfn> class</li>
<li>The <dfn data-x="js-RangeError" data-x-href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror"><code>RangeError</code></dfn> class</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-eval-x"><code>eval()</code></dfn> function</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-IsHTMLDDA-internal-slot">[[IsHTMLDDA]]</dfn> internal slot</li>
<li>The <dfn data-x="js-typeof" data-x-href="https://tc39.github.io/ecma262/#sec-typeof-operator"><code>typeof</code></dfn> operator</li>
<li><dfn data-x-href="https://tc39.github.io/ecma262/#table-49">The <var>TypedArray</var> Constructors</dfn> table</li>
@@ -86195,6 +86197,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
@@ -87942,6 +87954,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>
@@ -87950,13 +87973,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>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>

0 comments on commit cc3fcc8

Please sign in to comment.