⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

ScriptEngine

Struct ScriptEngine 

Source
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: JsVm

JavaScript virtual machine

§gc: GcHeap

Garbage collector heap

§dom_api: DomApi

DOM API bridge

§last_error: Option<String>

Last error message

Implementations§

Source§

impl ScriptEngine

Source

pub fn new() -> Self

Source

pub fn execute_script(&mut self, source: &str) -> Result<(), String>

Execute a JavaScript source string. Returns Ok(()) on success, Err(message) on failure.

Source

pub fn process_script_tags(&mut self, html: &str) -> usize

Extract inline JavaScript from <script> tags and execute each. Returns the number of scripts successfully executed.

Source

pub fn tick(&mut self)

Process a single tick of the event loop:

  1. Process expired timers
  2. Execute microtasks
  3. Run GC if needed
Source

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.

Source

pub fn process_click(&mut self, x: i32, y: i32)

Process a click at pixel coordinates

Source

pub fn queue_microtask(&mut self, callback_id: usize)

Schedule a microtask

Source

pub fn console_output(&self) -> Vec<String>

Get the console output from both JS VM and DOM API

Source

pub fn clear_console(&mut self)

Clear console output

Source

pub fn scripts_executed(&self) -> usize

Number of scripts executed

Source

pub fn ticks_processed(&self) -> u64

Number of ticks processed

Source

pub fn set_global(&mut self, name: &str, value: JsValue)

Set a global variable in the JS VM

Source

pub fn get_global(&self, name: &str) -> Option<&JsValue>

Get a global variable from the JS VM

Trait Implementations§

Source§

impl Default for ScriptEngine

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for ScriptEngine

§

impl RefUnwindSafe for ScriptEngine

§

impl Send for ScriptEngine

§

impl Sync for ScriptEngine

§

impl Unpin for ScriptEngine

§

impl UnwindSafe for ScriptEngine

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.