Truly independent web browser
Meta+LibWeb: Convert restricted doubles in the Rust bindings
Andreas Kling98afa16fde30
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rsindex 0d2426e920c..9817b43e222 100644--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs@@ -289,6 +289,26 @@ pub(crate) fn to_unrestricted_float(vm: &Vm, value: Value) -> ThrowCompletionOr<Ok(x as f32)}+/// A JS value converted to a double, https://webidl.spec.whatwg.org/#js-double+///+/// The identifier is the name of the parameter or member that the value is of, which the error names.+pub(crate) fn to_double(vm: &Vm, value: Value, identifier: &str) -> ThrowCompletionOr<f64> {+ // 1. Let x be ? ToNumber(V).+ let x = value.to_double(vm)?;++ // 2. If x is NaN, +∞, or −∞, then throw a TypeError.+ if !x.is_finite() {+ return vm.throw_completion(+ ErrorKind::TypeError,+ ErrorType::InvalidRestrictedFloatingPointParameter,+ &[&identifier],+ );+ }++ // 3. Return the IDL double value that represents the same numeric value as x.+ Ok(x)+}+/// A JS value converted to an unrestricted double, https://webidl.spec.whatwg.org/#js-unrestricted-doublepub(crate) fn to_unrestricted_double(vm: &Vm, value: Value) -> ThrowCompletionOr<f64> {// 1. Let x be ? ToNumber(V).diff --git a/Meta/Generators/libweb_bindings/rust_bindings.py b/Meta/Generators/libweb_bindings/rust_bindings.pyindex 0a6aa8eab5d..4af68fff863 100644--- a/Meta/Generators/libweb_bindings/rust_bindings.py+++ b/Meta/Generators/libweb_bindings/rust_bindings.py@@ -393,8 +393,8 @@ def write_rust_interface(use crate::bindings::conversions::{{ArrayBufferView, BufferSource, BufferSourceRules, CppInterface, EmptyDictionary, FromJs, ToJs, UsvString,implements_cpp_interface, record_to_js, rooted_sequence_to_js, sequence_from_js, sequence_to_js,- to_array_buffer_view, to_boolean, to_buffer_source, to_cpp_interface, to_dom_string, to_float, to_long,- to_long_long, to_typed_array, to_unrestricted_double, to_unrestricted_float, to_unsigned_long,+ to_array_buffer_view, to_boolean, to_buffer_source, to_cpp_interface, to_dom_string, to_double, to_float,+ to_long, to_long_long, to_typed_array, to_unrestricted_double, to_unrestricted_float, to_unsigned_long,to_unsigned_long_long, to_usv_string,}};use crate::bindings::interface::{{@@ -814,7 +814,7 @@ pub(crate) mod definitions {dictionary_member, dictionary_object, enumeration_value_to_js, implements_cpp_interface, iterator_method,record_to_js, rooted_sequence_to_js, sequence_from_iterable, sequence_from_js, sequence_to_js,throw_no_union_types_matched, to_array_buffer_view, to_boolean, to_buffer_source, to_cpp_interface,- to_dom_string, to_enumeration_value, to_float, to_long, to_long_long, to_typed_array,+ to_dom_string, to_double, to_enumeration_value, to_float, to_long, to_long_long, to_typed_array,to_unrestricted_double, to_unrestricted_float, to_unsigned_long, to_unsigned_long_long, to_usv_string,};use crate::bindings::interface::{Ref, create_dictionary_object, set_dictionary_member, to_interface};diff --git a/Meta/Generators/libweb_bindings/rust_to_idl_value.py b/Meta/Generators/libweb_bindings/rust_to_idl_value.pyindex 6ecfdb06b0a..12ba630a31c 100644--- a/Meta/Generators/libweb_bindings/rust_to_idl_value.py+++ b/Meta/Generators/libweb_bindings/rust_to_idl_value.py@@ -96,6 +96,8 @@ def rust_to_idl_value(return f'to_float(vm, {value}, "{identifier}")'if name == "unrestricted float":return f"to_unrestricted_float(vm, {value})"+ if name == "double":+ return f'to_double(vm, {value}, "{identifier}")'if name == "unrestricted double":return f"to_unrestricted_double(vm, {value})"if name in TYPED_ARRAY_NAMES:diff --git a/Meta/Generators/libweb_bindings/rust_types.py b/Meta/Generators/libweb_bindings/rust_types.pyindex 6f35193dedb..2aaebcc4de6 100644--- a/Meta/Generators/libweb_bindings/rust_types.py+++ b/Meta/Generators/libweb_bindings/rust_types.py@@ -47,7 +47,7 @@ SUPPORTED_TYPE_EXTENDED_ATTRIBUTES = {"AllowShared", "AllowResizable"}INTEGER_TYPES = {"long": "i32", "unsigned long": "u32", "long long": "i64", "unsigned long long": "u64"}# The floating point types, with the Rust type of their values.-FLOATING_POINT_TYPES = {"float": "f32", "unrestricted float": "f32", "unrestricted double": "f64"}+FLOATING_POINT_TYPES = {"float": "f32", "unrestricted float": "f32", "double": "f64", "unrestricted double": "f64"}# The types whose values are plain data, with the Rust type of their values. None of these Rust types is or holds a# cell, which holds_cells() relies on.