From f603128e55dc5681e499e1d1de995171d9083937 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Sun, 27 Dec 2020 01:27:10 +0100 Subject: [PATCH] LibJS: Fix old object numeric key test now that toString() is correct --- Libraries/LibJS/Runtime/Value.cpp | 8 +++----- Libraries/LibJS/Tests/object-basic.js | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 2bb790bb36e..205f56d186a 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -134,15 +134,13 @@ static String double_to_string(double d) auto number_string = number_string_builder.to_string(); - // HACK: (sunverwerth) I'm not sure how the ECMAScript spec deals with numbers that - // can not be exactly represented in IEE754 so I'm cutting off after the 15th fractional digit. - // Otherwise 3.14.toString() would come out as "3.140000000000000124344978758017532527446746826171875" - // Chrome and Firefox output the expected "3.14" here + // FIXME: Remove this hack. + // FIXME: Instead find the shortest round-trippable representation. + // Remove decimals after the 15th position if (end_index > intpart_end + 15) { exponent += end_index - intpart_end - 15; end_index = intpart_end + 15; } - // HACK end // remove leading zeroes while (start_index < end_index && number_string[start_index] == '0') { diff --git a/Libraries/LibJS/Tests/object-basic.js b/Libraries/LibJS/Tests/object-basic.js index c9dfc83fdd0..36c047682f3 100644 --- a/Libraries/LibJS/Tests/object-basic.js +++ b/Libraries/LibJS/Tests/object-basic.js @@ -87,8 +87,7 @@ describe("correct behavior", () => { test("floating point keys", () => { const math = { 3.14: "pi" }; expect(math["3.14"]).toBe("pi"); - // FIXME: Floating point literals are coerced to i32 - // expect(math[3.14]).toBe("pi"); + expect(math[3.14]).toBe("pi"); }); test("keywords as property keys", () => {