Skip to main content

JsRuntime

Struct JsRuntime 

Source
pub struct JsRuntime { /* private fields */ }
Expand description

A JS engine instance with DOM bindings installed.

Implementations§

Source§

impl JsRuntime

Source

pub fn new(dom: Rc<DomTree>) -> Self

Creates a runtime sharing the given DOM tree with the browser side.

Source

pub fn set_viewport(&mut self, width: f32, height: f32)

Updates the CSS-pixel viewport exposed through the Window API.

Source

pub fn set_language(&mut self, language: &str)

Updates the language preferences exposed through navigator.

Source

pub fn run_script(&mut self, source: &str)

Evaluates a script, logging JS errors instead of crashing the page.

Source

pub fn eval_value(&mut self, source: &str) -> JSValue

Evaluates an expression and returns its value, or undefined on error.

Source

pub fn set_document_url(&mut self, url: &str)

Updates the URL exposed through the window’s location object.

Source

pub fn set_page_origin(&mut self, origin: &str)

Updates the serialized origin exposed through the window’s location/window/document objects.

Source

pub fn dispatch_dom_content_loaded(&mut self) -> bool

Dispatches DOMContentLoaded to document listeners once.

Returns true only for the first dispatch attempt. Listener errors are logged and do not prevent the remaining listeners from running.

Source

pub fn dispatch_window_load(&mut self) -> bool

Dispatches the window load event once the page has finished loading.

Supports the body onload inline handler, the window.onload property, and addEventListener("load", ...) registrations in that order. Returns true only for the first dispatch attempt.

Source

pub fn run_due_timers(&mut self) -> bool

Runs timer callbacks whose deadlines have elapsed.

Returns whether at least one callback was invoked. Repeating timers are rescheduled before invocation so they can cancel themselves.

Source

pub fn needs_redraw(&self) -> bool

Returns whether a script mutated the DOM and a relayout is needed.

Source

pub fn take_needs_redraw(&self) -> bool

Clears and returns the redraw flag.

Source

pub fn take_iframe_fetch_requests(&mut self) -> Vec<JsIframeFetchRequest>

Takes iframe-loading requests queued by JavaScript since the previous call. Each must be resolved via resolve_iframe_fetch once fetched.

Source

pub fn resolve_iframe_fetch(&mut self, dom_id: u64, html: String)

Parses fetched iframe HTML, installs it as the iframe’s contentDocument and fires the iframe’s load event.

Source

pub fn reject_iframe_fetch(&mut self, dom_id: u64)

Marks an iframe load as failed so later contentDocument accesses do not keep re-queuing a fetch.

Source

pub fn snapshot(&self) -> DomSnapshot

Serializes the current mirror DOM for the browser side.

Nodes exposed to scripts keep their stable dom_id so the UI thread can rebuild the tree and re-register references on commit.

Source

pub fn snapshot_iframe_documents(&self) -> Vec<IframeContentSnapshot>

Serializes every iframe’s content document into movable snapshots so the layout can render each <iframe>’s content nested inside the host page.

Source

pub fn apply_dom(&mut self, snapshot: &DomSnapshot)

Replaces the mirror DOM with a snapshot produced by the browser side.

The mirror is rebuilt from snapshot and node references are re-registered so existing JS element handles keep resolving. JS-created (detached) nodes are preserved; they are not part of the committed DOM but may still be referenced from scripts.

Source

pub fn click_dom_id(&mut self, dom_id: u64) -> bool

Dispatches a click to the handlers registered on the element with the given JS-facing dom id. Returns whether at least one handler ran.

Source

pub fn click(&mut self, node: &NodeRef<HtmlNodeType>) -> bool

Dispatches a click to the handlers registered on node.

Both the onclick property and addEventListener("click", ...) are supported. The event bubbles through exposed ancestor elements so delegated listeners such as React’s root listener receive it. Returns whether at least one handler ran.

Source

pub fn scroll_dom_id(&mut self, dom_id: u64) -> bool

Dispatches a scroll event to the handlers registered on the element with the given JS-facing dom id. Returns whether at least one handler ran.

Source

pub fn scroll(&mut self, node: &NodeRef<HtmlNodeType>) -> bool

Dispatches a scroll event that bubbles through node’s exposed ancestors.

Both the onscroll property and addEventListener("scroll", ...) are supported. Returns whether at least one handler ran.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = Infallible

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

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

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more