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>,
    /* 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>

Implementations§

Source§

impl JsHost

Source

pub fn new() -> JsHost

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 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 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 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(&self, tag: i64, a: &Value, b: &Value) -> Value

Bitwise/shift ops with JS ToInt32/ToUint32 semantics.

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 and strings).

Source

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

Enumerable keys of an object/array (for for-in).

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> 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> 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, 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<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