9.4 Jobs and Host Operations to Enqueue Jobs
A Job is an
Jobs are scheduled for execution by ECMAScript
- At some future point in time, when there is no
running execution contextand the execution context stackis empty, the implementation must:
- Only one
Jobmay be actively undergoing evaluation at any point in time.
- Once evaluation of a
Jobstarts, it must run to completion before evaluation of any other Jobstarts.
Abstract Closuremust return a normal completion, implementing its own handling of errors. GetActiveScriptOrModule() is scriptOrModule.
- If scriptOrModule is a
Script Recordor Module Record, let ec be the topmost execution contexton the execution context stackwhose ScriptOrModule component is scriptOrModule. The Realmcomponent of ec is scriptOrModule.[[Realm]].
At any particular time, an execution is prepared to evaluate ECMAScript code if all of the following conditions are true:
execution context stackis not empty.
Realmcomponent of the topmost execution contexton the execution context stackis a Realm Record.
The specific choice of
Particular kinds of Jobs have additional conformance requirements.
9.4.1 JobCallback Records
A JobCallback Record is a
JobCallback Records have the fields listed in
9.4.2 HostMakeJobCallback ( callback )
The implementation of HostMakeJobCallback must conform to the following requirements:
- It must always complete normally (i.e., not return an
- It must always return a
JobCallback Recordwhose [[Callback]] field is callback.
The default implementation of HostMakeJobCallback performs the following steps when called:
ECMAScript hosts that are not web browsers must use the default implementation of HostMakeJobCallback.
This is called at the time that the callback is passed to the function that is responsible for its being eventually scheduled and run. For example,
promise.then(thenAction) calls MakeJobCallback on
thenAction at the time of invoking
Promise.prototype.then, not at the time of scheduling the reaction
9.4.3 HostCallJobCallback ( jobCallback, V, argumentsList )
The implementation of HostCallJobCallback must conform to the following requirements:
- It must always perform and return the result of
Call(jobCallback.[[Callback]], V, argumentsList).
This requirement means that hosts cannot change the [[Call]] behaviour of function objects defined in this specification.
The default implementation of HostCallJobCallback performs the following steps when called:
ECMAScript hosts that are not web browsers must use the default implementation of HostCallJobCallback.
9.4.4 HostEnqueuePromiseJob ( job, realm )
The implementation of HostEnqueuePromiseJob must conform to the requirements in
- If realm is not
null, each time job is invoked the implementation must perform implementation-definedsteps such that execution is prepared to evaluate ECMAScript codeat the time of job's invocation.
- Let scriptOrModule be
GetActiveScriptOrModule() at the time HostEnqueuePromiseJob is invoked. If realm is not null, each time job is invoked the implementation must perform implementation-definedsteps such that scriptOrModule is the active script or moduleat the time of job's invocation.
- Jobs must run in the same order as the HostEnqueuePromiseJob invocations that scheduled them.
The realm for Jobs returned by