pub struct JsRuntime { /* private fields */ }Expand description
A JS engine instance with DOM bindings installed.
Implementations§
Source§impl JsRuntime
impl JsRuntime
Sourcepub fn new(dom: Rc<DomTree>) -> Self
pub fn new(dom: Rc<DomTree>) -> Self
Creates a runtime sharing the given DOM tree with the browser side.
Sourcepub fn set_viewport(&mut self, width: f32, height: f32)
pub fn set_viewport(&mut self, width: f32, height: f32)
Updates the CSS-pixel viewport exposed through the Window API.
Sourcepub fn set_language(&mut self, language: &str)
pub fn set_language(&mut self, language: &str)
Updates the language preferences exposed through navigator.
Sourcepub fn run_script(&mut self, source: &str)
pub fn run_script(&mut self, source: &str)
Evaluates a script, logging JS errors instead of crashing the page.
Sourcepub fn eval_value(&mut self, source: &str) -> JSValue
pub fn eval_value(&mut self, source: &str) -> JSValue
Evaluates an expression and returns its value, or undefined on error.
Sourcepub fn set_document_url(&mut self, url: &str)
pub fn set_document_url(&mut self, url: &str)
Updates the URL exposed through the window’s location object.
Sourcepub fn set_page_origin(&mut self, origin: &str)
pub fn set_page_origin(&mut self, origin: &str)
Updates the serialized origin exposed through the window’s
location/window/document objects.
Sourcepub fn dispatch_dom_content_loaded(&mut self) -> bool
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.
Sourcepub fn dispatch_window_load(&mut self) -> bool
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.
Sourcepub fn run_due_timers(&mut self) -> bool
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.
Sourcepub fn needs_redraw(&self) -> bool
pub fn needs_redraw(&self) -> bool
Returns whether a script mutated the DOM and a relayout is needed.
Sourcepub fn take_needs_redraw(&self) -> bool
pub fn take_needs_redraw(&self) -> bool
Clears and returns the redraw flag.
Sourcepub fn take_iframe_fetch_requests(&mut self) -> Vec<JsIframeFetchRequest>
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.
Sourcepub fn resolve_iframe_fetch(&mut self, dom_id: u64, html: String)
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.
Sourcepub fn reject_iframe_fetch(&mut self, dom_id: u64)
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.
Sourcepub fn snapshot(&self) -> DomSnapshot
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.
Sourcepub fn snapshot_iframe_documents(&self) -> Vec<IframeContentSnapshot>
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.
Sourcepub fn apply_dom(&mut self, snapshot: &DomSnapshot)
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.
Sourcepub fn click_dom_id(&mut self, dom_id: u64) -> bool
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.
Sourcepub fn click(&mut self, node: &NodeRef<HtmlNodeType>) -> bool
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.
Sourcepub fn scroll_dom_id(&mut self, dom_id: u64) -> bool
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.
Sourcepub fn scroll(&mut self, node: &NodeRef<HtmlNodeType>) -> bool
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§
impl !RefUnwindSafe for JsRuntime
impl !Send for JsRuntime
impl !Sync for JsRuntime
impl !UnwindSafe for JsRuntime
impl Freeze for JsRuntime
impl Unpin for JsRuntime
impl UnsafeUnpin for JsRuntime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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