pub struct ScriptEngine {
pub vm: JsVm,
pub gc: GcHeap,
pub dom_api: DomApi,
pub last_error: Option<String>,
/* private fields */
}Expand description
The script engine integrating all JS components
Fields§
§vm: JsVmJavaScript virtual machine
gc: GcHeapGarbage collector heap
dom_api: DomApiDOM API bridge
last_error: Option<String>Last error message
Implementations§
Source§impl ScriptEngine
impl ScriptEngine
pub fn new() -> Self
Sourcepub fn execute_script(&mut self, source: &str) -> Result<(), String>
pub fn execute_script(&mut self, source: &str) -> Result<(), String>
Execute a JavaScript source string. Returns Ok(()) on success, Err(message) on failure.
Extract inline JavaScript from <script> tags and execute each.
Returns the number of scripts successfully executed.
Sourcepub fn tick(&mut self)
pub fn tick(&mut self)
Process a single tick of the event loop:
- Process expired timers
- Execute microtasks
- Run GC if needed
Sourcepub fn process_event(&mut self, event_type: EventType, target_node: NodeId)
pub fn process_event(&mut self, event_type: EventType, target_node: NodeId)
Process a DOM event: dispatch it through the event system, then invoke any JS callbacks that were triggered.
Sourcepub fn process_click(&mut self, x: i32, y: i32)
pub fn process_click(&mut self, x: i32, y: i32)
Process a click at pixel coordinates
Sourcepub fn queue_microtask(&mut self, callback_id: usize)
pub fn queue_microtask(&mut self, callback_id: usize)
Schedule a microtask
Sourcepub fn console_output(&self) -> Vec<String>
pub fn console_output(&self) -> Vec<String>
Get the console output from both JS VM and DOM API
Sourcepub fn clear_console(&mut self)
pub fn clear_console(&mut self)
Clear console output
Sourcepub fn scripts_executed(&self) -> usize
pub fn scripts_executed(&self) -> usize
Number of scripts executed
Sourcepub fn ticks_processed(&self) -> u64
pub fn ticks_processed(&self) -> u64
Number of ticks processed
Sourcepub fn set_global(&mut self, name: &str, value: JsValue)
pub fn set_global(&mut self, name: &str, value: JsValue)
Set a global variable in the JS VM
Sourcepub fn get_global(&self, name: &str) -> Option<&JsValue>
pub fn get_global(&self, name: &str) -> Option<&JsValue>
Get a global variable from the JS VM