Browse Source

style(boa): minor cleanup (#838)

pull/849/head
neeldug 4 years ago committed by GitHub
parent
commit
98deb58aae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      boa/src/builtins/array/mod.rs
  2. 10
      boa/src/builtins/number/mod.rs

10
boa/src/builtins/array/mod.rs

@ -1088,14 +1088,14 @@ impl Array {
let initial_value = args.get(1).cloned().unwrap_or_else(Value::undefined);
let mut length = this.get_field("length").to_length(interpreter)?;
if length == 0 {
if initial_value.is_undefined() {
return interpreter.throw_type_error(
return if initial_value.is_undefined() {
interpreter.throw_type_error(
"reduceRight was called on an empty array and with no initial value",
);
)
} else {
// early return to prevent usize subtraction errors
return Ok(initial_value);
}
Ok(initial_value)
};
}
let mut k = length - 1;
let mut accumulator = if initial_value.is_undefined() {

10
boa/src/builtins/number/mod.rs

@ -354,7 +354,7 @@ impl Number {
fraction -= digit as f64;
// Round to even.
if fraction + delta > 1.0
&& (fraction > 0.5 || (fraction - 0.5) < f64::EPSILON && digit & 1 != 0)
&& (fraction > 0.5 || (fraction - 0.5).abs() < f64::EPSILON && digit & 1 != 0)
{
loop {
// We need to back trace already written digits in case of carry-over.
@ -523,12 +523,12 @@ impl Number {
if radix == 0 {
if s.starts_with("0x") || s.starts_with("0X") {
if let Ok(i) = i32::from_str_radix(&s[2..], 16) {
return Ok(Value::integer(i));
return if let Ok(i) = i32::from_str_radix(&s[2..], 16) {
Ok(Value::integer(i))
} else {
// String can't be parsed.
return Ok(Value::from(f64::NAN));
}
Ok(Value::from(f64::NAN))
};
} else {
radix = 10
};

Loading…
Cancel
Save