Skip to main content

JsEngine

Struct JsEngine 

Source
pub struct JsEngine {
Show 36 fields pub globals: BTreeMap<String, JsValue>, pub root_scope: Rc<RefCell<Scope>>, pub current_scope: Rc<RefCell<Scope>>, pub document: Document, pub console_logs: Vec<String>, pub user_functions: HashMap<String, JsClosure>, pub closures: HashMap<u64, JsClosure>, pub next_closure_id: u64, pub call_depth: usize, pub live_nodes: RefCell<HashMap<u64, DomNode>>, pub anon_counter: usize, pub classes: HashMap<String, ClassDef>, pub promises: HashMap<u64, JsPromise<JsValue>>, pub promise_controllers: HashMap<u64, (ResolveFn<JsValue>, RejectFn)>, pub next_promise_id: u64, pub pending_throw: Option<JsValue>, pub next_symbol_id: u64, pub symbol_registry: HashMap<String, SymbolId>, pub object_prototype: BTreeMap<String, JsValue>, pub array_prototype: BTreeMap<String, JsValue>, pub function_prototype: BTreeMap<String, JsValue>, pub string_prototype: BTreeMap<String, JsValue>, pub error_prototype: BTreeMap<String, JsValue>, pub memory_limit_bytes: Option<usize>, pub allocated_memory_bytes: usize, pub freeze_prototypes: bool, pub allow_prototype_mutation: bool, pub eval_depth: usize, pub is_strict: bool, pub weak_maps: RefCell<HashMap<u64, HashMap<usize, JsValue>>>, pub next_weak_id: u64, pub weak_sets: RefCell<HashMap<u64, HashSet<usize>>>, pub weak_refs: RefCell<WeakObjectMap>, pub generators: RefCell<HashMap<u64, GeneratorInstance>>, pub next_generator_id: u64, pub pending_yield: Option<JsValue>,
}

Fields§

§globals: BTreeMap<String, JsValue>§root_scope: Rc<RefCell<Scope>>§current_scope: Rc<RefCell<Scope>>§document: Document§console_logs: Vec<String>§user_functions: HashMap<String, JsClosure>§closures: HashMap<u64, JsClosure>§next_closure_id: u64§call_depth: usize§live_nodes: RefCell<HashMap<u64, DomNode>>§anon_counter: usize§classes: HashMap<String, ClassDef>§promises: HashMap<u64, JsPromise<JsValue>>§promise_controllers: HashMap<u64, (ResolveFn<JsValue>, RejectFn)>§next_promise_id: u64§pending_throw: Option<JsValue>§next_symbol_id: u64§symbol_registry: HashMap<String, SymbolId>§object_prototype: BTreeMap<String, JsValue>§array_prototype: BTreeMap<String, JsValue>§function_prototype: BTreeMap<String, JsValue>§string_prototype: BTreeMap<String, JsValue>§error_prototype: BTreeMap<String, JsValue>§memory_limit_bytes: Option<usize>§allocated_memory_bytes: usize§freeze_prototypes: bool§allow_prototype_mutation: bool§eval_depth: usize§is_strict: bool§weak_maps: RefCell<HashMap<u64, HashMap<usize, JsValue>>>§next_weak_id: u64§weak_sets: RefCell<HashMap<u64, HashSet<usize>>>§weak_refs: RefCell<WeakObjectMap>§generators: RefCell<HashMap<u64, GeneratorInstance>>§next_generator_id: u64§pending_yield: Option<JsValue>

Implementations§

Source§

impl JsEngine

Source

pub fn execute_statement(&mut self, stmt: &Stmt) -> Result<JsValue, String>

Source

pub fn execute_stmt_flow( &mut self, stmt: &Stmt, ) -> Result<StatementFlow, String>

Source

pub fn call_value( &mut self, callee: &JsValue, args: Vec<JsValue>, ) -> Result<JsValue, String>

Source

pub fn call_value_with_this( &mut self, callee: &JsValue, args: Vec<JsValue>, this_val: Option<JsValue>, ) -> Result<JsValue, String>

Source

pub fn eval_expr(&mut self, expr: &Expr) -> Result<JsValue, String>

Source

pub fn call_closure( &mut self, closure: &JsClosure, args: Vec<JsValue>, ) -> Result<JsValue, String>

Source

pub fn call_closure_with_this( &mut self, closure: &JsClosure, args: Vec<JsValue>, this_val: Option<JsValue>, ) -> Result<JsValue, String>

Source

pub fn step_generator( &mut self, gen_id: u64, _next_arg: Option<JsValue>, ) -> Result<JsValue, String>

Source

pub fn to_bigint(&self, val: &JsValue) -> Result<JsValue, String>

Source

pub fn call_function( &mut self, name: &str, args: Vec<JsValue>, ) -> Result<JsValue, String>

Source§

impl JsEngine

Source

pub fn new() -> Self

Source

pub fn with_document(doc: Document) -> Self

Source

pub fn with_memory_limit(self, limit_bytes: usize) -> Self

Sets a strict memory allocation threshold in bytes (e.g. 64MB for sandbox).

Source

pub fn set_freeze_prototypes(&mut self, freeze: bool)

Enables or disables prototype freezing to prevent prototype pollution.

Source

pub fn with_allow_prototype_mutation(self, allow: bool) -> Self

Sets whether prototype mutation is allowed on root Object.prototype or via proto.

Source

pub fn set_allow_prototype_mutation(&mut self, allow: bool)

Toggles prototype mutation permissions on root prototypes and proto.

Source

pub fn allocate_bytes(&mut self, bytes: usize) -> Result<(), String>

Tracks heap memory allocations and enforces memory limit quotas.

Source

pub fn prune_dead_closures(&mut self)

Source

pub fn maybe_prune_closures(&mut self)

Source

pub fn compile_regex(&self, pattern: &str, flags: &str) -> Result<Regex, String>

Source

pub fn create_regex_value( &self, pattern: &str, flags: &str, ) -> Result<JsValue, String>

Source

pub fn create_promise_value(&mut self, promise: JsPromise<JsValue>) -> JsValue

Source

pub fn tick_engine_timers(&mut self) -> usize

Source

pub fn tick_timers(&mut self) -> usize

Source

pub fn resolve_constructor( &self, class_name: &str, ) -> Option<(Vec<String>, Vec<Stmt>, Option<String>)>

Source

pub fn resolve_method( &self, class_name: &str, method_name: &str, ) -> Option<(Vec<String>, Vec<Stmt>, Option<String>)>

Source

pub fn is_instance_of(&self, instance: &JsValue, class_name: &str) -> bool

Source

pub fn instantiate_class( &mut self, class_name: &str, args: Vec<JsValue>, ) -> Result<JsValue, String>

Source

pub fn eval(&mut self, script: &str) -> Result<JsValue, String>

Source

pub fn dom_node_to_js(&self, node: &DomNode) -> JsValue

Source

pub fn create_error_from_string(&self, err_msg: &str) -> JsValue

Trait Implementations§

Source§

impl Default for JsEngine

Source§

fn default() -> Self

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

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.