Skip to main content

Callable

Enum Callable 

Source
pub enum Callable {
Show 13 variants Bytecode { code: Gc<CompiledCode>, env: Gc<ClosureEnv>, }, Bound { target: Value, this: Value, args: Vec<Value>, }, Native { func: NativeFn, }, 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, }, YieldResult { 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

§target: Value

The function being called.

§this: Value

The this every call uses.

§args: Vec<Value>

Arguments prepended to every call’s own.

§

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

§func: NativeFn

The implementation.

§

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

§coroutine: Gc<JsObject>

The body to continue.

§promise: Gc<JsObject>

The promise the async function returned.

§kind: ResumeKind

Whether this continuation delivers the value or raises the reason.

§

CombinatorSettle

One element of Promise.all/allSettled/any/race settling.

Fields

§state: Gc<JsObject>

The hidden object holding the results array, the remaining count and the combinator’s own resolve/reject pair.

§index: usize

Which element this callback belongs to.

§fulfilled: bool

Whether the element fulfilled or rejected.

§

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

§promise: Gc<JsObject>

The promise to settle.

§value: Value

The outcome to settle it with, which is the original one.

§rejected: bool

Whether that outcome is a rejection.

§

GeneratorResume

One continuation of an await inside an async generator.

Fields

§generator: Gc<JsObject>

The async generator to continue.

§promise: Gc<JsObject>

The promise the pending next/return/throw returned.

§kind: ResumeKind

Whether this delivers the value or raises the reason.

§

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

§promise: Gc<JsObject>

The promise the pending method returned.

§done: bool

Whether this answers a completed generator rather than a yield.

§

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

§remaining: Gc<JsObject>

Pairs of [resource, disposeMethod], consumed from the end.

§promise: Gc<JsObject>

The promise disposeAsync returned.

§error: Value

The SuppressedError chain built so far, or Uninitialized for none.

§rejected: bool

Whether this continuation is being called with a rejection reason.

§

FinallyShim

One of the two shims Promise.prototype.finally installs.

Fields

§callback: Option<Value>

The script’s callback, or None to pass the outcome straight through.

§fulfilled: bool

Whether this is the fulfil side.

Trait Implementations§

Source§

impl Trace for Callable

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Report every Gc owned by self to tracer.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.