Truly independent web browser
LibJS: Range check code points before narrowing in fromCodePoint
Shannon Booth5fcf92b88b0c
diff --git a/Libraries/LibJS/Rust/src/runtime/string_constructor.rs b/Libraries/LibJS/Rust/src/runtime/string_constructor.rsindex a21a9af2d28..3a81e74a313 100644--- a/Libraries/LibJS/Rust/src/runtime/string_constructor.rs+++ b/Libraries/LibJS/Rust/src/runtime/string_constructor.rs@@ -14,7 +14,7 @@ use crate::layout::cell::Gc;use crate::layout::object::Object;use crate::layout::value::Value;use crate::runtime::abstract_operations::{get_prototype_from_constructor, length_of_array_like};-use crate::runtime::completion::{Must, ThrowCompletionOr};+use crate::runtime::completion::ThrowCompletionOr;use crate::runtime::error::ErrorKind;use crate::runtime::error_types::ErrorType;use crate::runtime::function_object::FunctionObject;@@ -184,10 +184,9 @@ impl StringConstructor {return vm.throw_completion(ErrorKind::RangeError, ErrorType::InvalidCodePoint, &[&next_code_point]);}- let code_point = next_code_point.to_i32(vm).must();-// c. If ℝ(nextCP) < 0 or ℝ(nextCP) > 0x10FFFF, throw a RangeError exception.- if !(0..=0x10FFFF).contains(&code_point) {+ let code_point = next_code_point.as_f64();+ if !(0.0..=f64::from(0x10FFFF)).contains(&code_point) {return vm.throw_completion(ErrorKind::RangeError, ErrorType::InvalidCodePoint, &[&next_code_point]);}diff --git a/Tests/LibJS/Runtime/builtins/String/String.fromCodePoint.js b/Tests/LibJS/Runtime/builtins/String/String.fromCodePoint.jsindex 0fdae660f0a..0d361b054bb 100644--- a/Tests/LibJS/Runtime/builtins/String/String.fromCodePoint.js+++ b/Tests/LibJS/Runtime/builtins/String/String.fromCodePoint.js@@ -25,4 +25,8 @@ test("errors", () => {expect(() => {String.fromCodePoint(0x123ffff);}).toThrowWithMessage(RangeError, "must be an integer no less than 0 and no greater than 0x10FFFF");++ expect(() => {+ String.fromCodePoint(2 ** 32 + 65);+ }).toThrowWithMessage(RangeError, "must be an integer no less than 0 and no greater than 0x10FFFF");});