9.5 Jobs and Host Operations to Enqueue Jobs
A Job is an
- At some future point in time, when there is no running context in the
agent for which the job is scheduled and thatagent 'sexecution context stack is empty, the implementation must:- Perform any
host-defined preparation steps. Invoke theJob Abstract Closure .- Perform any
host-defined cleanup steps, after which theexecution context stack must be empty.
- Perform any
- Only one
Job may be actively undergoing evaluation at any point in time in anagent . - Once evaluation of a
Job starts, it must run to completion before evaluation of any otherJob starts in anagent . - The
Abstract Closure must return anormal completion , implementing its own handling of errors.
At any particular time, scriptOrModule (a
GetActiveScriptOrModule () is scriptOrModule.- If scriptOrModule is a
Script Record orModule Record , let ec be the topmostexecution context on theexecution context stack whose ScriptOrModule component is scriptOrModule. TheRealm component 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:
- The
execution context stack is not empty. - The
Realm component of the topmostexecution context on theexecution context stack is aRealm Record .
The specific choice of
Particular kinds of
9.5.1 JobCallback Records
A JobCallback Record is a
The WHATWG HTML specification (https://html.spec.whatwg.org/), for example, uses the
JobCallback Records have the fields listed in
Field Name | Value | Meaning |
---|---|---|
[[Callback]] |
a |
The function to invoke when the |
[[HostDefined]] |
anything (default value is |
Field reserved for use by |
9.5.2 HostMakeJobCallback ( callback )
The
An implementation of HostMakeJobCallback must conform to the following requirements:
- It must return a
JobCallback Record whose [[Callback]] field is callback.
The default implementation of HostMakeJobCallback performs the following steps when called:
- Return the
JobCallback Record { [[Callback]]: callback, [[HostDefined]]:empty }.
ECMAScript
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.5.3 HostCallJobCallback ( jobCallback, V, argumentsList )
The
An implementation of HostCallJobCallback must conform to the following requirements:
- It must perform and return the result of
Call (jobCallback.[[Callback]], V, argumentsList).
This requirement means that
The default implementation of HostCallJobCallback performs the following steps when called:
Assert :IsCallable (jobCallback.[[Callback]]) istrue .- Return ?
Call (jobCallback.[[Callback]], V, argumentsList).
ECMAScript
9.5.4 HostEnqueueGenericJob ( job, realm )
The
An implementation of HostEnqueueGenericJob must conform to the requirements in
9.5.5 HostEnqueuePromiseJob ( job, realm )
The
An implementation of HostEnqueuePromiseJob must conform to the requirements in
- If realm is not
null , each time job is invoked the implementation must performimplementation-defined steps such that execution isprepared to evaluate ECMAScript code at the time of job's invocation. - Let scriptOrModule be
GetActiveScriptOrModule () at the time HostEnqueuePromiseJob is invoked. If realm is notnull , each time job is invoked the implementation must performimplementation-defined steps such that scriptOrModule is theactive script or module at the time of job's invocation. Jobs must run in the same order as the HostEnqueuePromiseJob invocations that scheduled them.
The realm for
9.5.6 HostEnqueueTimeoutJob ( timeoutJob, realm, milliseconds )
The
An implementation of HostEnqueueTimeoutJob must conform to the requirements in