Skip to main content

ScriptEngine

Trait ScriptEngine 

Source
pub trait ScriptEngine: Send {
    // Required methods
    fn init(&mut self, document: &mut BaseDocument);
    fn execute(
        &mut self,
        code: &str,
        language: ScriptLanguage,
        context: &ExecutionContext,
    ) -> Result<ScriptValue, ScriptError>;
    fn handle_event(&mut self, event: &DomEvent) -> EventHandled;
    fn tick(&mut self) -> Result<bool, ScriptError>;
    fn set_error_handler(&mut self, callback: Option<ScriptErrorCallback>);
}
Expand description

Script engine trait - implement for Boa, V8, NanoVM, etc.

Required Methods§

Source

fn init(&mut self, document: &mut BaseDocument)

Initialize the engine with a document

Source

fn execute( &mut self, code: &str, language: ScriptLanguage, context: &ExecutionContext, ) -> Result<ScriptValue, ScriptError>

Execute code in the specified language

Source

fn handle_event(&mut self, event: &DomEvent) -> EventHandled

Handle a DOM event (keyboard, mouse, etc.) Returns whether the event was consumed

Source

fn tick(&mut self) -> Result<bool, ScriptError>

Poll for async work - called by document poll() Returns true if more work pending

Source

fn set_error_handler(&mut self, callback: Option<ScriptErrorCallback>)

Register an error callback

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§