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
impl JsHost
pub fn new() -> JsHost
pub fn null(&self) -> Value
pub fn is_null(&self, v: &Value) -> bool
pub fn program_offsets(&self) -> (usize, usize)
pub fn load_program(&mut self, funcs: Vec<FuncDef>, tries: Vec<TryDef>)
pub fn try_def(&self, id: usize) -> Option<TryDef>
pub fn alloc(&mut self, obj: JsObj) -> Value
pub fn get(&self, v: &Value) -> Option<&JsObj>
pub fn get_mut(&mut self, v: &Value) -> Option<&mut JsObj>
pub fn new_str(&mut self, s: impl Into<String>) -> Value
pub fn new_array(&mut self, items: Vec<Value>) -> Value
pub fn new_object(&mut self, props: IndexMap<String, Value>) -> Value
pub fn as_str(&self, v: &Value) -> Option<String>
Sourcepub fn read_name(&self, name: &str) -> Option<Value>
pub fn read_name(&self, name: &str) -> Option<Value>
Scope-chain read: local + enclosing chain, then globals.
pub fn read_global(&self, name: &str) -> Option<Value>
Sourcepub fn set_name(&mut self, name: &str, val: Value)
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).
Sourcepub fn declare_name(&mut self, name: &str, val: Value)
pub fn declare_name(&mut self, name: &str, val: Value)
Declare a new binding in the current scope (let/const/var).
pub fn set_global(&mut self, name: &str, val: Value)
pub fn del_name(&mut self, name: &str)
pub fn current_this(&self) -> Option<Value>
pub fn current_env_capture(&self) -> Env
pub fn take_error(&mut self) -> Option<String>
pub fn raise_str(&mut self, class: &str, msg: &str) -> String
Source§impl JsHost
impl JsHost
Sourcepub fn truthy(&self, v: &Value) -> bool
pub fn truthy(&self, v: &Value) -> bool
JS truthiness: false / 0 / -0 / NaN / “” / null / undefined are falsy.
Sourcepub fn to_number(&self, v: &Value) -> f64
pub fn to_number(&self, v: &Value) -> f64
Coerce to a number (ToNumber): the arithmetic-context conversion.
Sourcepub fn str_of(&self, v: &Value) -> String
pub fn str_of(&self, v: &Value) -> String
String(v) — the string-coercion form (raw, unquoted).
Sourcepub fn console_format(&self, v: &Value) -> String
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.
Sourcepub fn inspect(&self, v: &Value) -> String
pub fn inspect(&self, v: &Value) -> String
util.inspect-style rendering (nested; strings quoted).
Sourcepub fn strict_eq(&self, a: &Value, b: &Value) -> bool
pub fn strict_eq(&self, a: &Value, b: &Value) -> bool
Strict equality (===): same type and same value, no coercion.
Sourcepub fn is_nullish(&self, v: &Value) -> bool
pub fn is_nullish(&self, v: &Value) -> bool
Whether v is null or undefined.
Sourcepub fn loose_eq(&self, a: &Value, b: &Value) -> bool
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.