JavaScriptCore:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jan 2006 16:47:02 +0000 (16:47 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jan 2006 16:47:02 +0000 (16:47 +0000)
        Reviewed by Geoff, landed by Darin.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5307
          Number.toFixed doesn't round 0.5 up

        * kjs/number_object.cpp: (NumberProtoFunc::callAsFunction):
        Fixed a ">" that should have been a ">=".

LayoutTests:

        Reviewed by Geoff, reworked and landed by Darin.

        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=5307
          Number.toFixed doesn't round 0.5 up

        * fast/js/number-tofixed-expected.txt: Added.
        * fast/js/number-tofixed.html: Added.
        * fast/js/resources/number-tofixed.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@11999 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/number_object.cpp
LayoutTests/ChangeLog
LayoutTests/fast/js/number-tofixed-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/number-tofixed.html [new file with mode: 0644]
LayoutTests/fast/js/resources/number-tofixed.js [new file with mode: 0644]

index b90111f..2663424 100644 (file)
@@ -1,3 +1,13 @@
+2006-01-11  Ricci Adams  <ricciadams@apple.com>
+
+        Reviewed by Geoff, landed by Darin.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5307
+          Number.toFixed doesn't round 0.5 up
+
+        * kjs/number_object.cpp: (NumberProtoFunc::callAsFunction):
+        Fixed a ">" that should have been a ">=".
+
 2006-01-11  Justin Haygood  <justin@xiondigital.net>
 
         Reviewed and landed by Darin.
index a74a1c4..d6fa54c 100644 (file)
@@ -212,7 +212,7 @@ JSValue *NumberProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, con
           return jsString(s+UString::from(x));
       
       double n = floor(x*pow(10.0, f));
-      if (fabs(n / pow(10.0, f) - x) > fabs((n + 1) / pow(10.0, f) - x))
+      if (fabs(n / pow(10.0, f) - x) >= fabs((n + 1) / pow(10.0, f) - x))
           n++;
       
       UString m = integer_part_noexp(n);
index 6ad06d7..fd184d8 100644 (file)
@@ -1,3 +1,14 @@
+2006-01-11  Ricci Adams  <ricciadams@apple.com>
+
+        Reviewed by Geoff, reworked and landed by Darin.
+
+        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=5307
+          Number.toFixed doesn't round 0.5 up
+
+        * fast/js/number-tofixed-expected.txt: Added.
+        * fast/js/number-tofixed.html: Added.
+        * fast/js/resources/number-tofixed.js: Added.
+
 2006-01-09  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Darin.
diff --git a/LayoutTests/fast/js/number-tofixed-expected.txt b/LayoutTests/fast/js/number-tofixed-expected.txt
new file mode 100644 (file)
index 0000000..c7264a3
--- /dev/null
@@ -0,0 +1,16 @@
+This test checks a few Number.toFixed cases, including 5307: Number.toFixed does not round 0.5 up.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS (0).toFixed(0) is '0'
+PASS 0.49.toFixed(0) is '0'
+PASS 0.5.toFixed(0) is '1'
+PASS 0.51.toFixed(0) is '1'
+PASS (-0.49).toFixed(0) is '-0'
+PASS (-0.5).toFixed(0) is '-1'
+PASS (-0.51).toFixed(0) is '-1'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/number-tofixed.html b/LayoutTests/fast/js/number-tofixed.html
new file mode 100644 (file)
index 0000000..f871247
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/number-tofixed.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/resources/number-tofixed.js b/LayoutTests/fast/js/resources/number-tofixed.js
new file mode 100644 (file)
index 0000000..d87a375
--- /dev/null
@@ -0,0 +1,13 @@
+description('This test checks a few Number.toFixed cases, including <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=5307">5307: Number.toFixed does not round 0.5 up</a>.');
+
+shouldBe("(0).toFixed(0)", "'0'");
+
+shouldBe("0.49.toFixed(0)", "'0'");
+shouldBe("0.5.toFixed(0)", "'1'");
+shouldBe("0.51.toFixed(0)", "'1'");
+
+shouldBe("(-0.49).toFixed(0)", "'-0'");
+shouldBe("(-0.5).toFixed(0)", "'-1'");
+shouldBe("(-0.51).toFixed(0)", "'-1'");
+
+var successfullyParsed = true;