LibWeb/WebIDL: Throw correct error when converting integers

When an integer doesn't fit within the range of an integral type
defined by WebIDL, the spec says to throw a `TypeError`, not a
`RangeError`.
This commit is contained in:
Diego Frias 2024-08-17 15:56:38 -07:00 committed by Ali Mohammad Pur
parent 4e7d3026d2
commit 3be7e88903
Notes: github-actions[bot] 2024-08-18 21:36:08 +00:00
2 changed files with 2 additions and 2 deletions

View file

@ -1,3 +1,3 @@
Made memory [object WebAssembly.Memory] with buffer [object ArrayBuffer] (byteLength 655360)
After growing buffer (byteLength 983040)
Got error: 'RangeError: Number '4294967296' is outside of allowed range of 0 to 4294967295'
Got error: 'TypeError: Number '4294967296' is outside of allowed range of 0 to 4294967295'

View file

@ -384,7 +384,7 @@ JS::ThrowCompletionOr<T> convert_to_int(JS::VM& vm, JS::Value value, EnforceRang
// 3. If x < lowerBound or x > upperBound, then throw a TypeError.
if (x < lower_bound || x > upper_bound)
return vm.throw_completion<JS::RangeError>(MUST(String::formatted("Number '{}' is outside of allowed range of {} to {}", x, lower_bound, upper_bound)));
return vm.throw_completion<JS::TypeError>(MUST(String::formatted("Number '{}' is outside of allowed range of {} to {}", x, lower_bound, upper_bound)));
// 4. Return x.
return x;