Browse Source

Fix `BigInt.prototype.toString()` radix checks (#885)

pull/886/head
George Roman 4 years ago committed by GitHub
parent
commit
71bc080f63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      boa/src/builtins/bigint/mod.rs
  2. 9
      boa/src/builtins/bigint/tests.rs

2
boa/src/builtins/bigint/mod.rs

@ -140,7 +140,7 @@ impl BigInt {
} else { } else {
10 10
}; };
if radix < 2 && radix > 36 { if radix < 2 || radix > 36 {
return ctx return ctx
.throw_range_error("radix must be an integer at least 2 and no greater than 36"); .throw_range_error("radix must be an integer at least 2 and no greater than 36");
} }

9
boa/src/builtins/bigint/tests.rs

@ -212,6 +212,15 @@ fn to_string() {
assert_eq!(forward(&mut engine, "1000n.toString(36)"), "\"rs\""); assert_eq!(forward(&mut engine, "1000n.toString(36)"), "\"rs\"");
} }
#[test]
fn to_string_invalid_radix() {
let mut engine = Context::new();
assert_throws(&mut engine, "10n.toString(null)", "RangeError");
assert_throws(&mut engine, "10n.toString(-1)", "RangeError");
assert_throws(&mut engine, "10n.toString(37)", "RangeError");
}
#[test] #[test]
fn as_int_n() { fn as_int_n() {
let mut engine = Context::new(); let mut engine = Context::new();

Loading…
Cancel
Save