Skip to content

Commit

Permalink
Fix error creation for revoked Proxies; separate out active script pr…
Browse files Browse the repository at this point in the history
…opagation
  • Loading branch information
syg committed May 8, 2020
1 parent 57ca40d commit ef0495a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions spec.html
Expand Up @@ -7626,33 +7626,40 @@ <h1>Jobs and Host Operations to Enqueue Jobs</h1>
<li>The Abstract Closure must return a normal completion, implementing its own handling of errors.</li>
</ul>

<p>At any point in time, an execution is <dfn id="job-preparedtoevaluatecode">prepared to evaluate code</dfn> in _scriptOrModule_ (a Module Record, a Script Record, or *null*) when all of the following conditions are true:</p>
<emu-note>
Host environments are not required to treat Jobs uniformly with respect to scheduling. For example, web browsers and Node.js treat Promise-handling Jobs as a higher priority than other work; future features may add Jobs that are not treated at such a high priority.
</emu-note>

<p>A Job _job_ <dfn id="job-propagatesactivescriptormodule">propagates the script or module</dfn> _scriptOrModule_ (a Script Record, a Module Record, or *null*) if GetActiveScriptOrModule() is _scriptOrModule_ whenever _job_ is called.</p>

<p>a Job _job_ is <dfn id="job-preparedtoevaluatecode">prepared to evaluate code</dfn> if all of the following conditions are true whenever _job_ is called:</p>
<ul>
<li>The execution context stack is not empty.</li>
<li>The Realm component of the topmost execution context on the execution context stack is a Realm Record.</li>
<li>The ScriptOrModule component of the topmost execution context on the execution context stack is _scriptOrModule_.</li>
</ul>

<p>Particular kinds of Jobs have additional conformance requirements.</p>

<emu-note>
<p>Host environments may prepare an execution to evaluate code by pushing execution contexts onto the execution context stack. The specific steps are implementation-defined.</p>
<p>Host environments are not required to treat Jobs uniformly with respect to scheduling. For example, web browsers and Node.js treat Promise-handling Jobs as a higher priority than other work; future features may add Jobs that are not treated at such a high priority.</p>
<p>The specific choice of Realm is up to the host environment. This initial execution context and Realm is only in use before any callback function is invoked. When a callback function related to a Job, like a Promise handler, is invoked, the invocation pushes its own execution context and Realm.</p>
</emu-note>

<p>Particular kinds of Jobs have additional conformance requirements.</p>

<emu-clause id="sec-hostenqueuepromisejob" aoid="HostEnqueuePromiseJob">
<h1>HostEnqueuePromiseJob ( _job_, _realm_ )</h1>
<p>HostEnqueuePromiseJob is a host-defined abstract operation that schedules the Job Abstract Closure _job_ to be performed, at some future time. The Abstract Closures used with this algorithm are intended to be related to the handling of Promises, or otherwise, to be scheduled with equal priority to Promise handling operations.</p>
<p>The _realm_ parameter is passed through to hosts with no normative requirements; it is either *null* or a Realm.</p>
<p>The _realm_ parameter is either *null* or a Realm Record.</p>

<p>The implementation of HostEnqueuePromiseJob must conform to the requirements in <emu-xref href="#sec-jobs"></emu-xref>. Additionally, Jobs enqueued by this hook must conform to all of the following requirements:</p>
<ul>
<li>Let _scriptOrModule_ be GetActiveScriptOrModule(). If _realm_ is not *null*, when the Job runs, the implementation must perform implementation-defined steps such that execution is prepared to evaluate code in _scriptOrModule_ before the _job_ Abstract Closure is called.</li>
<li>If _realm_ is not *null*, the implementation must perform implementation-defined steps such that _job_ is prepared to evaluate code.</li>
<li>Let _scriptOrModule_ be GetActiveScriptOrModule(). The implementation must perform implementation-defined steps such that _job_ propagates the script or module _scriptOrModule_.</li>
<li>Jobs must be scheduled in FIFO order, with Jobs running in the same order as the HostEnqueuePromiseJob invocations which scheduled them.</li>
</ul>

<emu-note>
The _realm_ for PromiseResolveThenableJobs is the result of calling GetFunctionRealm on the _then_ function object. The _realm_ for PromiseReactionJobs is the result of calling GetFunctionRealm on the handler if the handler is not *undefined*. Otherwise the _realm_ is *null* and no user ECMAScript code will be evaluated. The WHATWG HTML specification, for example, uses _realm_ to check for ability to run script and to prepare to run script.
<p>The _realm_ for PromiseResolveThenableJobs is usually the result of calling GetFunctionRealm on the _then_ function object. The _realm_ for PromiseReactionJobs is usually the result of calling GetFunctionRealm on the handler if the handler is not *undefined*. When the _realm_ is *null* due to being called on a revoked Proxy, the current Realm at the time of the GetFunctionRealm call is used instead. When the _realm_ is *null* and no user ECMAScript code will be evaluated, and no new ECMAScript objects (e.g. Error objects) will be created. The WHATWG HTML specification, for example, uses _realm_ to check for ability to run script and for the <a href="https://html.spec.whatwg.org/#entry">entry</a> concept.</p>
<p>The script or module that _job_ propagates may be *null*.</p>
</emu-note>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -39940,6 +39947,8 @@ <h1>NewPromiseReactionJob ( _reaction_, _argument_ )</h1>
1. If _reaction_.[[Handler]] is not *undefined*, then
1. Let _getHandlerRealmResult_ be GetFunctionRealm(_reaction_.[[Handler]]).
1. If _getHandlerRealmResult_ is a normal completion, then set _handlerRealm_ to _getHandlerRealmResult_.[[Value]].
1. Else, set _handlerRealm_ to the current Realm Record.
1. NOTE: _handlerRealm_ is never *null* when the handler is not *undefined*. When the handler is a revoked Proxy and no code runs, _handlerRealm_ is used to create error objects.
1. Return the Record { [[Job]]: _job_, [[Realm]]: _handlerRealm_ }.
</emu-alg>
</emu-clause>
Expand All @@ -39957,7 +39966,8 @@ <h1>NewPromiseResolveThenableJob ( _promiseToResolve_, _thenable_, _then_ )</h1>
1. Return Completion(_thenCallResult_).
1. Let _getThenRealmResult_ be GetFunctionRealm(_then_).
1. If _getThenRealmResult_ is a normal completion, then let _thenRealm_ be _getThenRealmResult_.[[Value]].
1. Otherwise, let _thenRealm_ be *null*.
1. Else, let _thenRealm_ be the current Realm Record.
1. NOTE: _thenRealm_ is never *null*. When _then_ is a revoked Proxy and no code runs, _thenRealm_ is used to create error objects.
1. Return the Record { [[Job]]: _job_, [[Realm]]: _thenRealm_ }.
</emu-alg>
<emu-note>
Expand Down

0 comments on commit ef0495a

Please sign in to comment.