Sign in

    crater-browser-runtime

    Shared browser JS runtime contract and DOM serializer for crater

    Download zip
    Author
    Version
    0.17.1
    License
    Apache-2.0
    Last updated
    5 months ago
    Downloads
    366

    mizchi/crater-browser-runtime does not have a README file

    JsRuntime

    pub(open) trait JsRuntime {
    init(Self) -> Unit
    execute(Self, Int,
    DomTree
    , String, AsyncExecutionMode) -> JsResult raise JsError
    tick(Self, Int,
    DomTree
    ) -> JsResult raise JsError
    }

    JavaScript runtime abstraction

    JsError

    pub suberror JsError {
    NotSupported
    ExecutionError(String)
    SyntaxError(String)
    ReferenceError(String)
    }

    Error types for JS execution Note: Some variants are reserved for future use
    impl Show for JsError

    JsError::execution_error

    fn JsError::execution_error(msg : String) -> JsError

    Create an ExecutionError (for use by external JsRuntime implementations).

    AsyncExecutionMode

    pub(all) enum AsyncExecutionMode {
    ImmediateFlush
    DeferredFlush
    }

    JsContext

    pub struct JsContext {
    context_id : Int
    async_mode : AsyncExecutionMode
    dom :
    DomTree

    logs : Array[String]
    runtime : &JsRuntime
    }

    JavaScript execution context bound to a DomTree

    JsContext::clear_logs

    fn JsContext::clear_logs(self : JsContext) -> Unit

    Clear console logs

    JsContext::execute

    fn JsContext::execute(self : JsContext, code : String) -> JsResult raise JsError

    Execute JavaScript code with runtime abstraction

    JsContext::get_dom

    Get the DOM tree from context

    JsContext::get_logs

    fn JsContext::get_logs(self : JsContext) -> Array[String]

    Get captured console logs

    JsContext::new

    Create a new JS execution context with a DOM tree

    JsContext::new_deferred

    JsContext::new_with_runtime

    fn JsContext::new_with_runtime(dom :
    DomTree
    , runtime : &JsRuntime) -> JsContext

    Create a new JS execution context with explicit runtime

    JsContext::new_with_runtime_and_mode

    fn JsContext::new_with_runtime_and_mode(dom :
    DomTree
    , runtime : &JsRuntime, async_mode : AsyncExecutionMode) -> JsContext

    JsContext::tick

    fn JsContext::tick(self : JsContext) -> Bool raise JsError

    JsResult

    pub struct JsResult {
    value : String
    logs : Array[String]
    success : Bool
    }

    Result of JS execution

    JsResult::new

    fn JsResult::new(value : String, logs : Array[String], success : Bool) -> JsResult

    Create a new JS result value

    ScriptExecutor

    pub struct ScriptExecutor {
    dom :
    DomTree

    ctx : JsContext
    }

    Script executor that runs in the scheduler event loop

    ScriptExecutor::clear_logs

    fn ScriptExecutor::clear_logs(self : ScriptExecutor) -> Unit

    Clear accumulated logs

    ScriptExecutor::execute

    Execute a script task using ScriptExecutor

    ScriptExecutor::execute_source

    fn ScriptExecutor::execute_source(self : ScriptExecutor, source : String) -> JsResult raise JsError

    Execute inline JavaScript source immediately against the current DOM.

    ScriptExecutor::get_logs

    fn ScriptExecutor::get_logs(self : ScriptExecutor) -> Array[String]

    Get accumulated logs from the JS context

    ScriptExecutor::new

    Create a new script executor

    ScriptExecutor::new_deferred

    ScriptExecutor::new_with_runtime

    Create a script executor with explicit JS runtime implementation.

    ScriptExecutor::tick

    fn ScriptExecutor::tick(self : ScriptExecutor) -> Bool raise JsError

    create_dom_init_code

    fn create_dom_init_code(dom :
    DomTree
    ) -> String

    Create initialization code that populates mock DOM from DomTree This builds the HTML structure (html, head, body) with actual content

    enqueue_script

    fn enqueue_script(scheduler :
    Scheduler
    , source : String, blocking : Bool) ->
    TaskId

    Enqueue a script for execution

    enqueue_script_after

    fn enqueue_script_after(scheduler :
    Scheduler
    , source : String, dependencies : Array[
    TaskId
    ], blocking : Bool) ->
    TaskId

    Enqueue a script with dependencies

    execute_script_task

    Execute a script task and return the result for scheduler

    init_js_runtime

    fn init_js_runtime() -> Unit

    Initialize JS runtime with QuickJS

    process_script_tasks

    Process script tasks from scheduler

    serialize_dom_for_mock

    fn serialize_dom_for_mock(dom :
    DomTree
    ) -> String

    Serialize DomTree to JavaScript object creation code Returns JS code that reconstructs the DOM tree in the mock DOM

    serialize_dom_to_html

    fn serialize_dom_to_html(dom :
    DomTree
    ) -> String

    Serialize DomTree to HTML string for renderer reparse

    serialize_dom_to_snapshot_html

    fn serialize_dom_to_snapshot_html(dom :
    DomTree
    ) -> String

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io