Skip to content

Truly independent web browser

LibWeb/Bindings: Convert unsigned short values in the Rust bindings

Shannon Booth3a9bb4ea0898
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs
index 1614529d7ff..5a010e71262 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs
@@ -282,6 +282,13 @@ pub(crate) fn to_long(vm: &Vm, value: Value) -> ThrowCompletionOr<i32> {
value.to_i32(vm)
}
+/// A JS value converted to an unsigned short, https://webidl.spec.whatwg.org/#js-unsigned-short
+pub(crate) fn to_unsigned_short(vm: &Vm, value: Value) -> ThrowCompletionOr<u16> {
+ // 1. Let x be ? ConvertToInt(V, 16, "unsigned").
+ // 2. Return the IDL unsigned short value that represents the same numeric value as x.
+ value.to_u16(vm)
+}
+
/// A JS value converted to an unsigned long, https://webidl.spec.whatwg.org/#js-unsigned-long
pub(crate) fn to_unsigned_long(vm: &Vm, value: Value) -> ThrowCompletionOr<u32> {
// 1. Let x be ? ConvertToInt(V, 32, "unsigned"), which is ToUint32 without the extended attributes that change
diff --git a/Meta/Generators/libweb_bindings/rust_bindings.py b/Meta/Generators/libweb_bindings/rust_bindings.py
index 9e5fa7463a1..f7715511034 100644
--- a/Meta/Generators/libweb_bindings/rust_bindings.py
+++ b/Meta/Generators/libweb_bindings/rust_bindings.py
@@ -1179,7 +1179,7 @@ RUST_BINDINGS_IMPORTS = """ #![allow(unused_imports)]
to_cpp_interface_in_union, to_dom_string,
to_dom_string_treating_null_as_empty, to_double, to_float, to_long, to_long_enforcing_range, to_long_long,
to_long_long_clamping, to_long_long_enforcing_range, to_object, to_promise, to_shared_array_buffer, to_typed_array,
- to_unrestricted_double, to_unrestricted_float, to_unsigned_long, to_unsigned_long_clamping,
+ to_unrestricted_double, to_unrestricted_float, to_unsigned_long, to_unsigned_long_clamping, to_unsigned_short,
to_unsigned_long_enforcing_range,
to_unsigned_long_long, to_unsigned_long_long_enforcing_range, to_usv_string, to_window_proxy,
window_proxy_from_object, window_proxy_to_js,
@@ -2625,7 +2625,7 @@ pub(crate) mod definitions {
to_byte_string, to_cpp_interface,
to_dom_string, to_dom_string_treating_null_as_empty, to_double, to_enumeration_value, to_float, to_long,
to_long_enforcing_range, to_long_long, to_long_long_enforcing_range, to_object, to_shared_array_buffer, to_typed_array,
- to_unrestricted_double, to_unrestricted_float, to_unsigned_long, to_unsigned_long_clamping,
+ to_unrestricted_double, to_unrestricted_float, to_unsigned_long, to_unsigned_long_clamping, to_unsigned_short,
to_unsigned_long_enforcing_range,
to_unsigned_long_long, to_unsigned_long_long_enforcing_range, to_usv_string, to_window_proxy,
window_proxy_from_object, window_proxy_to_js,