pub enum Callable {
Show 16 variants
Bytecode {
code: Gc<CompiledCode>,
env: Gc<ClosureEnv>,
},
Bound {
target: Value,
this: Value,
args: Vec<Value>,
},
Native {
func: NativeFn,
own_instance: bool,
},
Host {
func: Rc<RefCell<HostFn>>,
own_instance: bool,
},
Revoker(ProxyRef),
PromiseResolve(Gc<JsObject>),
PromiseReject(Gc<JsObject>),
AwaitResume {
coroutine: Gc<JsObject>,
promise: Gc<JsObject>,
kind: ResumeKind,
},
CombinatorSettle {
state: Gc<JsObject>,
index: usize,
fulfilled: bool,
},
SettlePromise {
promise: Gc<JsObject>,
value: Value,
rejected: bool,
},
GeneratorResume {
generator: Gc<JsObject>,
promise: Gc<JsObject>,
kind: ResumeKind,
},
ModuleBinding {
cell: Gc<Cell>,
},
CompletedReturn {
generator: Gc<JsObject>,
promise: Gc<JsObject>,
rejected: bool,
},
YieldResult {
generator: Gc<JsObject>,
promise: Gc<JsObject>,
done: bool,
},
DisposeStep {
remaining: Gc<JsObject>,
promise: Gc<JsObject>,
error: Value,
rejected: bool,
},
FinallyShim {
callback: Option<Value>,
fulfilled: bool,
},
}Expand description
The body of a callable object.
Variants§
Bytecode
A function compiled from JavaScript source.
Fields
code: Gc<CompiledCode>The bytecode and slot mapping.
env: Gc<ClosureEnv>The captured environment.
Bound
A function produced by Function.prototype.bind.
This is a variant rather than a native function carrying the state in
properties because the state is not observable: bind has to remember its
target, this and leading arguments, and a native trampoline cannot capture
them.
Fields
Native
A built-in implemented in Rust.
The name and length a script observes are ordinary properties on the
function object, not fields here: they are writable (f.name = "x" works)
and would otherwise be two sources of truth.
Fields
own_instance: boolWhether this constructor builds its own instance instead of being handed one.
The spec has a constructor validate its arguments before
OrdinaryCreateFromConstructor reads new.target.prototype, and only the ones
with real validation need to: new Promise(nonCallable) and new DataView(…)
must refuse the argument before a throwing prototype getter can run. The rest
keep the simpler shape where new has already made the object.
Host
A host function: a native closure that carries its own state.
Behind an Rc<RefCell<…>> because the closure has to be called with
&mut Interp, and the call site would otherwise still be holding a borrow of this
object’s data — the closure itself may reach the same object. Cloning the Rc out
and dropping the borrow first is what keeps that from panicking.
Fields
own_instance: boolWhether this constructor builds its own instance; see Callable::Native.
Revoker(ProxyRef)
The revoke function Proxy.revocable hands back.
It is a variant rather than a Native with the slots in a property because a
NativeFn is a plain function pointer: it cannot capture, and the slots are
precisely what this function exists to hold. Keeping them here also means the
collector sees them, so a proxy stays alive while only its revoke is reachable.
PromiseResolve(Gc<JsObject>)
The resolve a Promise executor receives.
Like Callable::Revoker, this cannot be a plain Native with the state in a
property: a NativeFn is a function pointer and cannot capture, and the promise
it settles is exactly what it has to remember. Both are one-shot per §27.2.1.3.1 —
the second call is a no-op rather than a second settlement.
The promise object is held directly rather than the state behind its Rc, because
settling has to run that object’s reactions.
PromiseReject(Gc<JsObject>)
The reject half of that pair.
AwaitResume
One of the two continuations an await parks on.
Reached through the ordinary reaction machinery, which is why it has to be a
callable object rather than a queue entry: await x is specified as
PerformPromiseThen(x, resume, rethrow).
Fields
kind: ResumeKindWhether this continuation delivers the value or raises the reason.
CombinatorSettle
One element of Promise.all/allSettled/any/race settling.
Fields
SettlePromise
Settle a promise with a fixed outcome when called.
finally needs “wait for this promise, then re-deliver that value”, and a
NativeFn cannot carry the value to re-deliver.
Fields
GeneratorResume
One continuation of an await inside an async generator.
Fields
kind: ResumeKindWhether this delivers the value or raises the reason.
ModuleBinding
Reads a module namespace’s binding out of the cell it is stored in.
A namespace object is an ordinary object whose exports are getters, so a getter
is what ns.x calls — and it has to be a callable object carrying the cell, for
the same reason PromiseResolve carries its promise.
CompletedReturn
Finish a completed async generator’s return(v) once v has settled.
Fields
YieldResult
Answer a pending async-generator method with {value, done: false}.
yield v in an async generator awaits v first, so the value can arrive after
the body has already parked; this is what turns it into the result object.
Fields
DisposeStep
One step of AsyncDisposableStack.disposeAsync.
The remaining resources ride along as a JS array so the collector can see them:
disposeAsync awaits each disposer in turn, which means the list has to survive
across microtasks rather than living on the Rust stack.
Fields
FinallyShim
One of the two shims Promise.prototype.finally installs.