Skip to content

Truly independent web browser

LibWeb: Add AllowSharedBufferSource

Callum Law22764bbc5ec5
diff --git a/Libraries/LibWeb/Bindings/Rust/src/webidl/buffers.rs b/Libraries/LibWeb/Bindings/Rust/src/webidl/buffers.rs
new file mode 100644
index 00000000000..63fff7b14cd
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/webidl/buffers.rs
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+use libjs_rust::api::{ArrayBuffer, Gc};
+
+use crate::bindings::conversions::{ArrayBufferView, BufferSource};
+
+/// The union of WebIDL/Buffers.idl, whose members the bindings convert.
+#[derive(Clone, Copy)]
+pub(crate) enum AllowSharedBufferSource {
+ ArrayBuffer(Gc<ArrayBuffer>),
+ SharedArrayBuffer(Gc<ArrayBuffer>),
+ ArrayBufferView(ArrayBufferView),
+}
+
+impl From<AllowSharedBufferSource> for BufferSource {
+ fn from(source: AllowSharedBufferSource) -> Self {
+ match source {
+ AllowSharedBufferSource::ArrayBuffer(buffer) | AllowSharedBufferSource::SharedArrayBuffer(buffer) => {
+ Self::ArrayBuffer(buffer)
+ }
+ AllowSharedBufferSource::ArrayBufferView(view) => view.into(),
+ }
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/webidl/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/webidl/mod.rs
index 985f2912687..3cf4ae8bd69 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/webidl/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/webidl/mod.rs
@@ -6,5 +6,6 @@
//! The serialization steps of the serializable interfaces of Web IDL, which LibWeb implements in C++.
+pub(crate) mod buffers;
pub(crate) mod dom_exception;
pub(crate) mod quota_exceeded_error;
diff --git a/Libraries/LibWeb/WebIDL/Buffers.idl b/Libraries/LibWeb/WebIDL/Buffers.idl
index 6354e16cbe8..f57534b12d8 100644
--- a/Libraries/LibWeb/WebIDL/Buffers.idl
+++ b/Libraries/LibWeb/WebIDL/Buffers.idl
@@ -6,3 +6,6 @@ typedef (Int8Array or Int16Array or Int32Array or
// https://webidl.spec.whatwg.org/#BufferSource
typedef (ArrayBufferView or ArrayBuffer) BufferSource;
+
+// https://webidl.spec.whatwg.org/#AllowSharedBufferSource
+typedef (ArrayBuffer or SharedArrayBuffer or [AllowShared] ArrayBufferView) AllowSharedBufferSource;
diff --git a/Meta/Generators/libweb_bindings/rust_types.py b/Meta/Generators/libweb_bindings/rust_types.py
index 7a921d5534b..ba8430c9c8f 100644
--- a/Meta/Generators/libweb_bindings/rust_types.py
+++ b/Meta/Generators/libweb_bindings/rust_types.py
@@ -208,7 +208,8 @@ def rust_module_path(idl_path: Path) -> str:
Encoding/TextEncoder.idl names crate::encoding::text_encoder."""
parts = idl_path.parts
namespace = parts[parts.index("LibWeb") + 1]
- return f"crate::{title_case_to_snake_case(namespace)}::{title_case_to_snake_case(idl_path.stem)}"
+ module = "webidl" if namespace == "WebIDL" else title_case_to_snake_case(namespace)
+ return f"crate::{module}::{title_case_to_snake_case(idl_path.stem)}"
def cpp_interface(idl_type: IDLType, context: GenerationContext) -> Optional[Interface]: