Truly independent web browser
LibWeb: Run serialization steps of Rust interfaces in the current realm
Shannon Bootha7a5ccb258d3
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/structured_data.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/structured_data.rsindex 0f0373760db..d8c78e4517b 100644--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/structured_data.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/structured_data.rs@@ -399,12 +399,12 @@ pub(crate) trait Transferable: Interface {}pub(crate) fn serialization_steps<T: Serializable>(- vm: &Vm,+ cx: &CallContext,object: Gc<Object>,serialized: &mut SerializationWriter,for_storage: bool,) -> WebIdlResult<()> {- let mut cx = CallContext::new(vm, object.shape().realm());+ let mut cx = CallContext::new(cx.vm(), cx.realm());implementation_of::<T>(object).serialization_steps(&mut cx, serialized, for_storage).map_err(|exception| Exception::Thrown(exception.throw(&cx)))diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rsindex 9d8b3323cd0..4b6f147c01d 100644--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs@@ -1006,9 +1006,10 @@ impl<'memory> Serializer<'_, '_, 'memory> {)?;}SerializableSteps::Rust => {+ let realm = self.realm.expect("an object is serialized in a realm");serializable::serialization_steps(interface_name,- vm,+ &CallContext::new(vm, realm),object,&mut SerializationWriter::new(self),self.for_storage,diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/serializable.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/serializable.rsindex 5a634622914..d84820a6afb 100644--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/serializable.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/serializable.rs@@ -36,7 +36,7 @@ use crate::bindings::generated::serializable_objects as generated;// A standalone cargo build has no wrapper classes or interface identifiers to dispatch on.#[cfg(not(web_idl_bindings))]mod generated {- use libjs_rust::api::{Gc, Object, Value, Vm};+ use libjs_rust::api::{Gc, Object, Value};use super::{SerializableRegistryEntry, SerializableSteps};use crate::bindings::structured_data::{SerializationReader, SerializationWriter};@@ -70,7 +70,7 @@ mod generated {pub(crate) fn serialization_steps(_: u16,- _: &Vm,+ _: &CallContext,_: Gc<Object>,_: &mut SerializationWriter,_: bool,diff --git a/Meta/Generators/libweb_bindings/rust_structured_serialize.py b/Meta/Generators/libweb_bindings/rust_structured_serialize.pyindex 96c69f7f99c..9e1f4934c49 100644--- a/Meta/Generators/libweb_bindings/rust_structured_serialize.py+++ b/Meta/Generators/libweb_bindings/rust_structured_serialize.py@@ -43,7 +43,7 @@ def write_rust_serializable_dispatch(out: TextIO, interfaces: List[Interface], vout.write("""pub(crate) mod serializable_objects {- use libjs_rust::api::{Gc, Object, Value, Vm};+ use libjs_rust::api::{Gc, Object, Value};use crate::bindings::{CallContext, WebIdlResult};use crate::bindings::interface::is_exact_wrapper;use crate::bindings::structured_data::{self, SerializationReader, SerializationWriter};@@ -73,7 +73,7 @@ pub(crate) mod serializable_objects {pub(crate) fn serialization_steps(interface_name: u16,- vm: &Vm,+ cx: &CallContext,object: Gc<Object>,serialized: &mut SerializationWriter,for_storage: bool,@@ -83,7 +83,7 @@ pub(crate) mod serializable_objects {)for interface in rust_interfaces:out.write(- f" {values[interface.name]} => structured_data::serialization_steps::<{rust_interface_path(interface)}>(vm, object, serialized, for_storage),\n"+ f" {values[interface.name]} => structured_data::serialization_steps::<{rust_interface_path(interface)}>(cx, object, serialized, for_storage),\n")out.write(""" _ => unreachable!("the interface is a Rust serializable interface"),diff --git a/Tests/LibWeb/Text/expected/HTML/StructuredClone-serialization-steps-error-realm.txt b/Tests/LibWeb/Text/expected/HTML/StructuredClone-serialization-steps-error-realm.txtnew file mode 100644index 00000000000..27cae54d83c--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/StructuredClone-serialization-steps-error-realm.txt@@ -0,0 +1,2 @@+function: DataCloneError in the current realm+WebAssembly.Module: DataCloneError in the current realmdiff --git a/Tests/LibWeb/Text/input/HTML/StructuredClone-serialization-steps-error-realm.html b/Tests/LibWeb/Text/input/HTML/StructuredClone-serialization-steps-error-realm.htmlnew file mode 100644index 00000000000..8325a80a5d5--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/StructuredClone-serialization-steps-error-realm.html@@ -0,0 +1,22 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ asyncTest(done => {+ const iframe = document.createElement("iframe");+ iframe.onload = () => {+ const iframeWindow = iframe.contentWindow;+ const module = new WebAssembly.Module(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0]));+ for (const [name, value] of [["function", () => {}], ["WebAssembly.Module", module]]) {+ try {+ iframeWindow.history.pushState(value, "");+ println(`${name}: no exception`);+ } catch (e) {+ const realm = e instanceof iframeWindow.DOMException ? "current" : "other";+ println(`${name}: ${e.name} in the ${realm} realm`);+ }+ }+ done();+ };+ document.body.appendChild(iframe);+ });+</script>