Skip to main content

JsHost

Struct JsHost 

Source
pub struct JsHost {
    pub funcs: Vec<FuncDef>,
    pub tries: Vec<TryDef>,
    pub error: Option<String>,
    pub exc: Option<Value>,
    pub signal: Option<Signal>,
    pub nextticks: VecDeque<Task>,
    pub microtasks: VecDeque<Task>,
    pub macrotasks: Vec<Timer>,
    /* private fields */
}
Expand description

The JavaScript runtime.

Fields§

§funcs: Vec<FuncDef>

Function templates, indexed by def id.

§tries: Vec<TryDef>

try/catch/finally block templates, indexed by try id.

§error: Option<String>§exc: Option<Value>

The in-flight thrown value, if any (JS throw).

§signal: Option<Signal>§nextticks: VecDeque<Task>

process.nextTick callbacks (drained before promise microtasks).

§microtasks: VecDeque<Task>

Promise-reaction / queueMicrotask microtasks.

§macrotasks: Vec<Timer>

setTimeout/setInterval/setImmediate macrotasks.

Implementations§

Source§

impl JsHost

Source

pub fn new() -> JsHost

Source

pub fn proto_of(&self, v: &Value) -> Option<Value>

The [[Prototype]] of a heap value, if explicitly linked.

Source

pub fn set_proto(&mut self, v: &Value, proto: Value)

Set v’s [[Prototype]] to proto. Null links the object as an explicit null-prototype object (recorded so instanceof Object reads false); undefined just clears any link without the null marker.

Source

pub fn has_null_proto(&self, v: &Value) -> bool

Whether v’s [[Prototype]] was explicitly set to null.

Source

pub fn object_proto(&self) -> Value

Source

pub fn tag_proto_class(&mut self, proto: &Value, class_val: Value)

Record that the prototype object proto belongs to the class constructor class_val (so instances can recover their constructor).

Source

pub fn class_of(&self, obj: &Value) -> Option<Value>

The class constructor value nearest in obj’s prototype chain, if any.

Source

pub fn ctor_name(&self, obj: &Value) -> String

The constructor display name of obj for util.inspect (empty ⇒ plain object, no prefix).

Source

pub fn fn_prop(&self, v: &Value, name: &str) -> Option<Value>

A function’s own-property table (created on demand).

Source

pub fn class_static(&self, class_val: &Value, name: &str) -> Option<Value>

A class static member, inherited down the constructor chain: a subclass sees its superclass’s static methods/fields (Sub.create → Base.create).

Source

pub fn set_fn_prop(&mut self, v: &Value, name: &str, val: Value)

Source

pub fn builtin_static(&self, ns: &str, name: &str) -> Option<Value>

A user-assigned static on a builtin namespace (Error.prepareStackTrace).

Source

pub fn set_builtin_static(&mut self, ns: &str, name: &str, val: Value)

Assign a static on a builtin namespace (persists across fresh Builtin handles for the same namespace).

Source

pub fn fn_prop_keys(&self, v: &Value) -> Vec<String>

Source

pub fn set_accessor( &mut self, owner: &Value, key: &str, get: Option<Value>, set: Option<Value>, )

Install an accessor (get, set) for key on the object owner.

Source

pub fn own_accessor( &self, owner: &Value, key: &str, ) -> Option<(Option<Value>, Option<Value>)>

The accessor (get, set) for key directly on owner (no chain walk).

Source

pub fn new_symbol(&mut self, desc: Option<String>) -> Value

A fresh unique Symbol(desc) value.

Source

pub fn symbol_for(&mut self, key: &str) -> Value

The shared Symbol.for(key) value (interned by description).

Source

pub fn well_known_iterator(&mut self) -> Value

The well-known Symbol.iterator (a fixed shared symbol whose internal property key is @@iterator).

Source

pub fn well_known_async_iterator(&mut self) -> Value

The well-known Symbol.asyncIterator (internal key @@asyncIterator).

Source

pub fn property_key(&self, v: &Value) -> String

The internal property-key string for a value used as a key. A Symbol maps to a stable per-symbol string so symbol-keyed props round-trip; Symbol.iterator maps to the sentinel @@iterator.

Source

pub fn null(&self) -> Value

Source

pub fn is_null(&self, v: &Value) -> bool

Source

pub fn program_offsets(&self) -> (usize, usize)

Source

pub fn load_program(&mut self, funcs: Vec<FuncDef>, tries: Vec<TryDef>)

Source

pub fn try_def(&self, id: usize) -> Option<TryDef>

Source

pub fn alloc(&mut self, obj: JsObj) -> Value

Source

pub fn get(&self, v: &Value) -> Option<&JsObj>

Source

pub fn get_mut(&mut self, v: &Value) -> Option<&mut JsObj>

Source

pub fn new_str(&mut self, s: impl Into<String>) -> Value

Source

pub fn new_array(&mut self, items: Vec<Value>) -> Value

Source

pub fn new_object(&mut self, props: IndexMap<String, Value>) -> Value

Source

pub fn as_str(&self, v: &Value) -> Option<String>

Source

pub fn frame_depth(&self) -> usize

Number of active call frames (the debugger’s step-depth reference).

Source

pub fn set_cur_line(&mut self, line: u32)

Record the source line the innermost frame is executing (DAP line hook).

Source

pub fn dbg_stack(&self) -> Vec<(String, u32)>

The call stack as (frame name, line) pairs, innermost first — for the DAP stackTrace. owner carries the function name where known.

Source

pub fn dbg_locals(&self) -> Vec<(String, String)>

The innermost frame’s locals as (name, inspect) pairs — for DAP variables.

Source

pub fn read_name(&self, name: &str) -> Option<Value>

Scope-chain read: local + enclosing chain, then globals.

Source

pub fn read_global(&self, name: &str) -> Option<Value>

Source

pub fn set_name(&mut self, name: &str, val: Value)

Assign to an existing binding up the scope chain, else create a global (JS assignment to an undeclared name targets the global object).

Source

pub fn declare_name(&mut self, name: &str, val: Value)

Declare a new binding in the current scope (let/const/var).

Source

pub fn set_global(&mut self, name: &str, val: Value)

Source

pub fn del_name(&mut self, name: &str)

Source

pub fn current_this(&self) -> Option<Value>

Source

pub fn current_env_capture(&self) -> Env

Source

pub fn current_new_target(&self) -> Option<Value>

Source

pub fn super_context(&self) -> (Option<Value>, Vec<(String, Value)>)

The (parent_ctor, this_class_fields) for a running constructor’s super(...), derived from the frame’s home class.

Source

pub fn super_resolve(&self, name: &str) -> SuperRef

Resolve super.name to either the parent-prototype getter (to be invoked by the caller, outside any host borrow) or a directly-usable value.

Source

pub fn take_error(&mut self) -> Option<String>

Source

pub fn raise_str(&mut self, class: &str, msg: &str) -> String

Source§

impl JsHost

Source

pub fn type_of(&self, v: &Value) -> &'static str

The typeof string for v.

Source

pub fn truthy(&self, v: &Value) -> bool

JS truthiness: false / 0 / -0 / NaN / “” / null / undefined are falsy.

Source

pub fn to_number(&self, v: &Value) -> f64

Coerce to a number (ToNumber): the arithmetic-context conversion.

Source

pub fn str_of(&self, v: &Value) -> String

String(v) — the string-coercion form (raw, unquoted).

Source

pub fn console_format(&self, v: &Value) -> String

console.log-style rendering of a top-level argument: bare strings print raw; everything else uses inspect.

Source

pub fn inspect(&self, v: &Value) -> String

util.inspect-style rendering (nested; strings quoted).

Source

pub fn callable_name(&self, v: &Value) -> String

The .name of any callable (function/class/builtin/bound).

Source

pub fn strict_eq(&self, a: &Value, b: &Value) -> bool

Strict equality (===): same type and same value, no coercion.

Source

pub fn is_nullish(&self, v: &Value) -> bool

Whether v is null or undefined.

Source

pub fn loose_eq(&self, a: &Value, b: &Value) -> bool

Loose equality (==) following the ECMAScript Abstract Equality Comparison. Objects reduce via ToPrimitive (which for our heap objects is always their string toString), so [0] == "0" is true (string compare of "0") but [0] == "" is false — never a number coercion of the object.

Source

pub fn arith( &mut self, op: NumOp, a: &Value, b: &Value, ) -> Result<Value, String>

The numeric-hook arithmetic/relational fallback for non-native operands (called by fusevm when at least one operand isn’t Int/Float).

Source

pub fn bitwise( &mut self, tag: i64, a: &Value, b: &Value, ) -> Result<Value, String>

Bitwise/shift ops with JS ToInt32/ToUint32 semantics — or true arbitrary-width BigInt bitwise when both operands are BigInt (mixing a BigInt with a Number throws, matching Node).

Source

pub fn is_bigint_val(&self, v: &Value) -> bool

Whether v is a heap BigInt.

Source

pub fn as_bigint(&self, v: &Value) -> Option<BigInt>

The BigInt value of v (a heap bigint), else None.

Source

pub fn new_bigint(&mut self, b: BigInt) -> Value

Allocate a heap BigInt.

Source§

impl JsHost

Source

pub fn iter_vec(&mut self, v: &Value) -> Result<Vec<Value>, String>

Collect an iterable into a vector of values (arrays, strings, Map/Set). Generators and user Symbol.iterator objects go through iter_all, which holds no host borrow across resumes.

Source

pub fn enum_keys(&mut self, v: &Value) -> Vec<Value>

Enumerable string keys of an object/array (for for-in). Internal symbol-keyed props (@@…) are not enumerable.

Source§

impl JsHost

Source

pub fn is_generator_val(&self, v: &Value) -> bool

Source

pub fn gen_done(&self, id: u32) -> bool

Source§

impl JsHost

Source

pub fn ensure_error_protos(&mut self)

Lazily build the builtin error prototype chain: Error.prototype → Object.prototype, and every specific error’s prototype → Error.prototype. Populated once; instances link to these so e instanceof TypeError and e instanceof Error both hold.

Source§

impl JsHost

Source

pub fn func_arity(&self, v: &Value) -> usize

A function’s .length: the count of leading params before the first one with a default or the rest element.

Source

pub fn is_map(&self, v: &Value) -> bool

Source

pub fn is_set(&self, v: &Value) -> bool

Source§

impl JsHost

Source

pub fn new_promise(&mut self) -> Value

Allocate a fresh pending promise, returning its heap value.

Source

pub fn promise_id(&self, v: &Value) -> Option<u32>

Source

pub fn promise_state(&self, id: u32) -> PromiseState

Source

pub fn promise_value(&self, id: u32) -> Value

Source

pub fn promise_mark_handled(&mut self, id: u32)

Source

pub fn take_reactions(&mut self, id: u32) -> Vec<PromiseReaction>

Take the pending reactions of a promise (called on settle).

Source

pub fn add_reaction(&mut self, id: u32, r: PromiseReaction)

Source

pub fn settle_promise(&mut self, id: u32, state: PromiseState, value: Value)

Source

pub fn queue_micro(&mut self, cb: Value, args: Vec<Value>)

Source

pub fn queue_nexttick(&mut self, cb: Value, args: Vec<Value>)

Source

pub fn queue_micro_native(&mut self, f: Box<dyn FnOnce() -> Result<(), String>>)

Schedule a native (Rust) microtask — used by Promise reactions and async resumption.

Source

pub fn add_timer( &mut self, delay: f64, callback: Value, args: Vec<Value>, ) -> u64

Source

pub fn io_sender(&self) -> Sender<IoTask>

Clone the I/O sender for a background I/O thread.

Source

pub fn incr_handle(&mut self)

Register a live handle (listener/socket/ref’d resource) keeping the loop alive.

Source

pub fn decr_handle(&mut self)

Release a handle; the loop exits once this reaches 0 with empty queues.

Source

pub fn open_handles(&self) -> usize

Source

pub fn cancel_timer(&mut self, id: u64)

Trait Implementations§

Source§

impl Default for JsHost

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for JsHost

§

impl !Send for JsHost

§

impl !Sync for JsHost

§

impl !UnwindSafe for JsHost

§

impl Freeze for JsHost

§

impl Unpin for JsHost

§

impl UnsafeUnpin for JsHost

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

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

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more