Files
moli/moli-webapi/src/embedding.rs
T
ldm0 7d07c2b283 fix(svg): preserve value list items with native receivers
Install Length, Number and Point list operations on their interface prototypes and use generated WebIDL receiver checks. Share per-index synchronization and readonly attachment/detachment across all SVG value lists, copying attached items into the destination realm. Normalize native Proxy arguments and retained value receivers, synchronize SVGLength and DOMPoint reads and writes, and use WebIDL float conversions for lengths. Cover live/windowless HTML/XML documents in both realms with frozen behavior probes and registered native Proxy regressions.
2026-11-20 22:47:48 +08:00

91 lines
3.3 KiB
Rust

//! Native capabilities supplied by the runtime for a realm.
use std::rc::Rc;
pub type WebIdlCallbackResult<'s> =
Result<Option<v8::Local<'s, v8::Value>>, v8::Local<'s, v8::Value>>;
pub type WebIdlCallbackInvocation<'s> = for<'i> fn(
&mut v8::PinScope<'s, 'i>,
v8::Local<'s, v8::Function>,
v8::Local<'s, v8::Value>,
&[v8::Local<'s, v8::Value>],
) -> WebIdlCallbackResult<'s>;
/// Bridges value bindings to the embedder without retaining its host or V8 handles.
/// Callbacks execute in the current (callee) realm, including for borrowed methods.
pub struct RealmCallbacks {
/// Synchronizes a live SVG point from its owner before reading or writing it.
pub point_accessed: for<'s, 'i> fn(&mut v8::PinScope<'s, 'i>, v8::Local<'s, v8::Object>),
/// Writes a live SVG point back to its owner; ordinary points need no action.
pub point_mutated: for<'s, 'i> fn(&mut v8::PinScope<'s, 'i>, v8::Local<'s, v8::Object>),
pub runtime: Option<&'static RealmRuntime>,
}
/// Capabilities needed by bindings that interact with the owning execution context.
pub struct RealmRuntime {
pub abort_signal_owner:
for<'s, 'i> fn(
&mut v8::PinScope<'s, 'i>,
v8::Local<'s, v8::Object>,
) -> Option<&'static crate::abort_signal::AbortSignalOwner>,
pub structured_clone_value: for<'s, 'i> fn(
&mut v8::PinScope<'s, 'i>,
v8::Local<'s, v8::Value>,
) -> Option<v8::Local<'s, v8::Value>>,
pub owner_terminating: fn(&mut v8::PinScope<'_, '_>) -> bool,
pub trace_callback: for<'s, 'i> fn(
&mut v8::PinScope<'s, 'i>,
moli_webidl::WebIdlCallbackFunction,
) -> v8::Local<'s, v8::Object>,
pub invoke_traced_callback: for<'s, 'i> fn(
&mut v8::PinScope<'s, 'i>,
v8::Local<'s, v8::Object>,
v8::Local<'s, v8::Value>,
&[v8::Local<'s, v8::Value>],
WebIdlCallbackInvocation<'s>,
) -> Option<WebIdlCallbackResult<'s>>,
pub blob: crate::blob::BlobRuntime,
pub form_data: crate::form_data::FormDataRuntime,
}
/// Installs the runtime's native capabilities before author code can use this realm.
pub fn install_realm_callbacks(scope: &mut v8::PinScope<'_, '_>, callbacks: RealmCallbacks) {
scope.get_current_context().set_slot(Rc::new(callbacks));
}
pub(crate) fn realm_callbacks(scope: &mut v8::PinScope<'_, '_>) -> Option<Rc<RealmCallbacks>> {
scope.get_current_context().get_slot::<RealmCallbacks>()
}
pub(crate) fn realm_runtime(scope: &mut v8::PinScope<'_, '_>) -> Option<&'static RealmRuntime> {
realm_callbacks(scope)?.runtime
}
pub(crate) fn throw_dom_exception_value(
scope: &mut v8::PinScope<'_, '_>,
message: &str,
name: &'static str,
) {
let exception =
crate::dom_exception::new_most_derived_dom_exception_value(scope, message, name);
scope.throw_exception(exception);
}
pub(crate) fn reflect_point_mutation<'s>(
scope: &mut v8::PinScope<'s, '_>,
point: v8::Local<'s, v8::Object>,
) {
if let Some(callbacks) = realm_callbacks(scope) {
(callbacks.point_mutated)(scope, point);
}
}
pub(crate) fn sync_point<'s>(
scope: &mut v8::PinScope<'s, '_>,
point: v8::Local<'s, v8::Object>,
) {
if let Some(callbacks) = scope.get_current_context().get_slot::<RealmCallbacks>() {
(callbacks.point_accessed)(scope, point);
}
}