Reviewers: Erik Corry,
Description:
Fix bug in date code where -0 was not mapped to 0. This caused the
runtime system to throw an exception because it expected smi arguments.
Please review this at http://codereview.chromium.org/2848038/show
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M src/date.js
M src/macros.py
M src/runtime.cc
M test/mjsunit/date.js
Index: src/date.js
===================================================================
--- src/date.js (revision 5011)
+++ src/date.js (working copy)
@@ -347,9 +347,10 @@
function MakeDay(year, month, date) {
if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return
$NaN;
- year = TO_INTEGER(year);
- month = TO_INTEGER(month);
- date = TO_INTEGER(date);
+ // Convert to integer and map -0 to 0.
+ year = TO_INTEGER_MAP_MINUS_ZERO(year);
+ month = TO_INTEGER_MAP_MINUS_ZERO(month);
+ date = TO_INTEGER_MAP_MINUS_ZERO(date);
if (year < kMinYear || year > kMaxYear ||
month < kMinMonth || month > kMaxMonth ||
Index: src/macros.py
===================================================================
--- src/macros.py (revision 5011)
+++ src/macros.py (working copy)
@@ -120,6 +120,7 @@
# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg));
+macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ?
arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
macro TO_UINT32(arg) = (arg >>> 0);
macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg :
NonStringToString(arg));
Index: src/runtime.cc
===================================================================
--- src/runtime.cc (revision 5011)
+++ src/runtime.cc (working copy)
@@ -5368,9 +5368,6 @@
}
-
-
-
static Object* Runtime_NumberToIntegerMapMinusZero(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 1);
Index: test/mjsunit/date.js
===================================================================
--- test/mjsunit/date.js (revision 5011)
+++ test/mjsunit/date.js (working copy)
@@ -154,7 +154,12 @@
testToLocaleTimeString();
+// Test that -0 is treated correctly in MakeDay.
+var d = new Date();
+assertDoesNotThrow("d.setDate(-0)");
+assertDoesNotThrow("new Date(-0, -0, -0, -0, -0, -0. -0)");
+
// Modified test from WebKit
// LayoutTests/fast/js/script-tests/date-utc-timeclip.js:
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev