Skip to content

Commit

Permalink
Merge 5a344a9 into e49be36
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Jul 16, 2020
2 parents e49be36 + 5a344a9 commit b78a596
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
45 changes: 23 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions boa/src/builtins/value/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ pub(crate) fn log_string_from(x: &Value, print_internals: bool) -> String {
match v.borrow().data {
ObjectData::String(ref string) => format!("String {{ \"{}\" }}", string),
ObjectData::Boolean(boolean) => format!("Boolean {{ {} }}", boolean),
ObjectData::Number(rational) => {
if rational.is_sign_negative() && rational == 0.0 {
"Number { -0 }".to_string()
} else {
let mut buffer = ryu_js::Buffer::new();
format!("Number {{ {} }}", buffer.format(rational))
}
}
ObjectData::Array => {
let len = i32::from(
&v.borrow()
Expand Down Expand Up @@ -185,7 +193,16 @@ impl Display for Value {
}
}

/// This is different from the ECMAScript compliant number to string, in the printing of `-0`.
///
/// This function prints `-0` as `-0` instead of pasitive `0` as the specification says.
/// This is done to make it easer for the user of the REPL to identify what is a `-0` vs `0`,
/// since the REPL is not bound to the ECMAScript specification we can do this.
fn format_rational(v: f64, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut buffer = ryu_js::Buffer::new();
write!(f, "{}", buffer.format(v))
if v.is_sign_negative() && v == 0.0 {
f.write_str("-0")
} else {
let mut buffer = ryu_js::Buffer::new();
write!(f, "{}", buffer.format(v))
}
}

0 comments on commit b78a596

Please sign in to comment.