[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.19-706-ge5415e9
tkent at chromium.org
tkent at chromium.org
Thu Feb 4 21:34:19 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 61568a66994a3fc1abe4821449e57fb65fac302d
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Feb 1 01:56:12 2010 +0000
2010-01-31 Kent Tamura <tkent at chromium.org>
Reviewed by Darin Adler.
Fix valueAsNumber calculation for type=month.
https://bugs.webkit.org/show_bug.cgi?id=34304
valueAsNumber calculation for type=month which was checked in as
r53893 was the number of milliseconds since UNIX epoch, and it was
wrong. The correct way is the number months since UNIX epoch.
* fast/forms/input-valueasnumber-month-expected.txt:
* fast/forms/script-tests/input-valueasnumber-month.js:
2010-01-31 Kent Tamura <tkent at chromium.org>
Reviewed by Darin Adler.
Fix valueAsNumber calculation for type=month.
https://bugs.webkit.org/show_bug.cgi?id=34304
valueAsNumber calculation for type=month which was checked in as
r53893 was the number of milliseconds since UNIX epoch, and it was
wrong. The correct way is the number months since UNIX epoch.
* html/DateComponents.cpp:
(WebCore::DateComponents::setMonthsSinceEpoch):
(WebCore::DateComponents::monthsSinceEpoch):
* html/DateComponents.h: Declare setMonthsSinceEpoch() and monthsSinceEpoch().
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parseToDouble):
Switch to monthsSinceEpoch() for type=MONTH.
(WebCore::HTMLInputElement::valueAsDate):
Add code with millisecondsSinceEpoch() for MONTH because
parseToDouble() changed its behavior.
(WebCore::HTMLInputElement::setValueAsNumber):
Use setMonthsSinceEpoch() for MONTH.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index a9ee2c1..b3b56b3 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,17 @@
+2010-01-31 Kent Tamura <tkent at chromium.org>
+
+ Reviewed by Darin Adler.
+
+ Fix valueAsNumber calculation for type=month.
+ https://bugs.webkit.org/show_bug.cgi?id=34304
+
+ valueAsNumber calculation for type=month which was checked in as
+ r53893 was the number of milliseconds since UNIX epoch, and it was
+ wrong. The correct way is the number months since UNIX epoch.
+
+ * fast/forms/input-valueasnumber-month-expected.txt:
+ * fast/forms/script-tests/input-valueasnumber-month.js:
+
2010-01-28 Ojan Vafai <ojan at chromium.org>
Reviewed by Darin Adler.
diff --git a/LayoutTests/fast/forms/input-valueasnumber-month-expected.txt b/LayoutTests/fast/forms/input-valueasnumber-month-expected.txt
index 605741f..5abf265 100644
--- a/LayoutTests/fast/forms/input-valueasnumber-month-expected.txt
+++ b/LayoutTests/fast/forms/input-valueasnumber-month-expected.txt
@@ -4,18 +4,22 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS valueAsNumberFor("") is Number.NaN
-PASS valueAsNumberFor("1969-12") is Date.UTC(1969, 11, 1, 0, 0, 0, 0)
-PASS valueAsNumberFor("1970-01") is Date.UTC(1970, 0, 1)
-PASS valueAsNumberFor("2009-12") is Date.UTC(2009, 11, 1)
-PASS setValueAsNumberAndGetValue(1969, 11, 1) is "1969-12"
-PASS setValueAsNumberAndGetValue(1970, 0, 1) is "1970-01"
-PASS setValueAsNumberAndGetValue(2009, 11, 31) is "2009-12"
-PASS setValueAsNumberAndGetValue(10000, 0, 1) is "10000-01"
-PASS setValueAsNumberAndGetValue(794, 9, 22) is ""
-PASS setValueAsNumberAndGetValue(1582, 8, 30) is ""
-PASS setValueAsNumberAndGetValue(1582, 9, 1) is "1582-10"
-PASS setValueAsNumberAndGetValue(1582, 9, 31) is "1582-10"
-PASS setValueAsNumberAndGetValue(275760, 8, 13) is "275760-09"
+PASS valueAsNumberFor("1969-01") is -12
+PASS valueAsNumberFor("1969-12") is -1
+PASS valueAsNumberFor("1970-01") is 0
+PASS valueAsNumberFor("1970-12") is 11
+PASS valueAsNumberFor("1971-01") is 12
+PASS valueAsNumberFor("2009-12") is (2009-1970)*12+11
+PASS input.valueAsNumber = -1; input.value is "1969-12"
+PASS input.valueAsNumber = 0; input.value is "1970-01"
+PASS setValueAsNumberAndGetValue(2009, 12) is "2009-12"
+PASS setValueAsNumberAndGetValue(10000, 1) is "10000-01"
+PASS setValueAsNumberAndGetValue(794, 9) is ""
+PASS setValueAsNumberAndGetValue(1582, 9) is ""
+PASS setValueAsNumberAndGetValue(1582, 10) is "1582-10"
+PASS setValueAsNumberAndGetValue(1582, 11) is "1582-11"
+PASS setValueAsNumberAndGetValue(275760, 9) is "275760-09"
+PASS setValueAsNumberAndGetValue(2147483647, 12) is "2147483647-12"
Tests to set invalid values to valueAsNumber:
PASS input.value = ""; input.valueAsNumber = null; input.value is "1970-01"
PASS input.valueAsNumber = "foo" threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
diff --git a/LayoutTests/fast/forms/script-tests/input-valueasnumber-month.js b/LayoutTests/fast/forms/script-tests/input-valueasnumber-month.js
index f0c57ce..cc7e5af 100644
--- a/LayoutTests/fast/forms/script-tests/input-valueasnumber-month.js
+++ b/LayoutTests/fast/forms/script-tests/input-valueasnumber-month.js
@@ -8,26 +8,31 @@ function valueAsNumberFor(stringValue) {
return input.valueAsNumber;
}
-function setValueAsNumberAndGetValue(year, month, day) {
- input.valueAsNumber = Date.UTC(year, month, day);
+function setValueAsNumberAndGetValue(y, m) {
+ input.valueAsNumber = (y - 1970) * 12 + m - 1;
return input.value;
}
shouldBe('valueAsNumberFor("")', 'Number.NaN');
-shouldBe('valueAsNumberFor("1969-12")', 'Date.UTC(1969, 11, 1, 0, 0, 0, 0)');
-shouldBe('valueAsNumberFor("1970-01")', 'Date.UTC(1970, 0, 1)');
-shouldBe('valueAsNumberFor("2009-12")', 'Date.UTC(2009, 11, 1)');
-
-shouldBe('setValueAsNumberAndGetValue(1969, 11, 1)', '"1969-12"');
-shouldBe('setValueAsNumberAndGetValue(1970, 0, 1)', '"1970-01"');
-shouldBe('setValueAsNumberAndGetValue(2009, 11, 31)', '"2009-12"');
-shouldBe('setValueAsNumberAndGetValue(10000, 0, 1)', '"10000-01"');
-
-shouldBe('setValueAsNumberAndGetValue(794, 9, 22)', '""');
-shouldBe('setValueAsNumberAndGetValue(1582, 8, 30)', '""');
-shouldBe('setValueAsNumberAndGetValue(1582, 9, 1)', '"1582-10"');
-shouldBe('setValueAsNumberAndGetValue(1582, 9, 31)', '"1582-10"');
-shouldBe('setValueAsNumberAndGetValue(275760, 8, 13)', '"275760-09"');
+shouldBe('valueAsNumberFor("1969-01")', '-12');
+shouldBe('valueAsNumberFor("1969-12")', '-1');
+shouldBe('valueAsNumberFor("1970-01")', '0');
+shouldBe('valueAsNumberFor("1970-12")', '11');
+shouldBe('valueAsNumberFor("1971-01")', '12');
+shouldBe('valueAsNumberFor("2009-12")', '(2009-1970)*12+11');
+
+shouldBe('input.valueAsNumber = -1; input.value', '"1969-12"');
+shouldBe('input.valueAsNumber = 0; input.value', '"1970-01"');
+shouldBe('setValueAsNumberAndGetValue(2009, 12)', '"2009-12"');
+shouldBe('setValueAsNumberAndGetValue(10000, 1)', '"10000-01"');
+
+shouldBe('setValueAsNumberAndGetValue(794, 9)', '""');
+shouldBe('setValueAsNumberAndGetValue(1582, 9)', '""');
+shouldBe('setValueAsNumberAndGetValue(1582, 10)', '"1582-10"');
+shouldBe('setValueAsNumberAndGetValue(1582, 11)', '"1582-11"');
+shouldBe('setValueAsNumberAndGetValue(275760, 9)', '"275760-09"');
+shouldBe('setValueAsNumberAndGetValue(2147483647, 12)', '"2147483647-12"');
+
// Date.UTC() of V8 throws an exception for the following value though JavaScriptCore doesn't.
// shouldBe('setValueAsNumberAndGetValue(275760, 8, 14)', '"275760-09"');
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 9115a2d..240f69c 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,27 @@
+2010-01-31 Kent Tamura <tkent at chromium.org>
+
+ Reviewed by Darin Adler.
+
+ Fix valueAsNumber calculation for type=month.
+ https://bugs.webkit.org/show_bug.cgi?id=34304
+
+ valueAsNumber calculation for type=month which was checked in as
+ r53893 was the number of milliseconds since UNIX epoch, and it was
+ wrong. The correct way is the number months since UNIX epoch.
+
+ * html/DateComponents.cpp:
+ (WebCore::DateComponents::setMonthsSinceEpoch):
+ (WebCore::DateComponents::monthsSinceEpoch):
+ * html/DateComponents.h: Declare setMonthsSinceEpoch() and monthsSinceEpoch().
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::parseToDouble):
+ Switch to monthsSinceEpoch() for type=MONTH.
+ (WebCore::HTMLInputElement::valueAsDate):
+ Add code with millisecondsSinceEpoch() for MONTH because
+ parseToDouble() changed its behavior.
+ (WebCore::HTMLInputElement::setValueAsNumber):
+ Use setMonthsSinceEpoch() for MONTH.
+
2010-01-31 Dan Bernstein <mitz at apple.com>
Reviewed by Timothy Hatcher.
diff --git a/WebCore/html/DateComponents.cpp b/WebCore/html/DateComponents.cpp
index c272002..9c62d30 100644
--- a/WebCore/html/DateComponents.cpp
+++ b/WebCore/html/DateComponents.cpp
@@ -37,6 +37,8 @@
#include <wtf/DateMath.h>
#include <wtf/MathExtras.h>
+using namespace std;
+
namespace WebCore {
// The oldest day of Gregorian Calendar is 1582-10-15. We don't support dates older than it.
@@ -537,6 +539,25 @@ bool DateComponents::setMillisecondsSinceMidnight(double ms)
return true;
}
+bool DateComponents::setMonthsSinceEpoch(double months)
+{
+ if (!isfinite(months))
+ return false;
+ months = round(months);
+ double doubleMonth = positiveFmod(months, 12);
+ double doubleYear = 1970 + (months - doubleMonth) / 12;
+ if (doubleYear < gregorianStartYear || numeric_limits<int>::max() < doubleYear)
+ return false;
+ int year = static_cast<int>(doubleYear);
+ int month = static_cast<int>(doubleMonth);
+ if (beforeGregorianStartDate(year, month, gregorianStartDay))
+ return false;
+ m_year = year;
+ m_month = month;
+ m_type = Month;
+ return true;
+}
+
// Offset from January 1st to Monday of the ISO 8601's first week.
// ex. If January 1st is Friday, such Monday is 3 days later. Returns 3.
static int offsetTo1stWeekStart(int year)
@@ -605,6 +626,12 @@ double DateComponents::millisecondsSinceEpoch() const
return invalidMilliseconds();
}
+double DateComponents::monthsSinceEpoch() const
+{
+ ASSERT(m_type == Month);
+ return (m_year - 1970) * 12 + m_month;
+}
+
String DateComponents::toStringForTime(SecondFormat format) const
{
ASSERT(m_type == DateTime || m_type == DateTimeLocal || m_type == Time);
diff --git a/WebCore/html/DateComponents.h b/WebCore/html/DateComponents.h
index 7e4ff7b..aff8855 100644
--- a/WebCore/html/DateComponents.h
+++ b/WebCore/html/DateComponents.h
@@ -124,10 +124,16 @@ public:
// For Time type. Updates m_hour, m_minute, m_second and m_millisecond.
bool setMillisecondsSinceMidnight(double ms);
+ // Another initializer for Month type. Updates m_year and m_month.
+ bool setMonthsSinceEpoch(double months);
+
// Returns the number of milliseconds from 1970-01-01 00:00:00 UTC.
// For a DateComponents initialized with parseDateTimeLocal(),
// millisecondsSinceEpoch() returns a value for UTC timezone.
double millisecondsSinceEpoch() const;
+ // Returns the number of months from 1970-01.
+ // Do not call this for types other than Month.
+ double monthsSinceEpoch() const;
static inline double invalidMilliseconds() { return std::numeric_limits<double>::quiet_NaN(); }
private:
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index 43ec943..3b7d3cc 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -1489,7 +1489,6 @@ double HTMLInputElement::parseToDouble(const String& src, double defaultValue) c
case DATE:
case DATETIME:
case DATETIMELOCAL:
- case MONTH:
case TIME:
case WEEK: {
DateComponents date;
@@ -1499,6 +1498,14 @@ double HTMLInputElement::parseToDouble(const String& src, double defaultValue) c
ASSERT(isfinite(msec));
return msec;
}
+ case MONTH: {
+ DateComponents date;
+ if (!formStringToDateComponents(inputType(), src, &date))
+ return defaultValue;
+ double months = date.monthsSinceEpoch();
+ ASSERT(isfinite(months));
+ return months;
+ }
case NUMBER:
case RANGE: {
double numberValue;
@@ -1535,10 +1542,17 @@ double HTMLInputElement::valueAsDate() const
switch (inputType()) {
case DATE:
case DATETIME:
- case MONTH:
case TIME:
case WEEK:
return parseToDouble(value(), DateComponents::invalidMilliseconds());
+ case MONTH: {
+ DateComponents date;
+ if (!formStringToDateComponents(inputType(), value(), &date))
+ return DateComponents::invalidMilliseconds();
+ double msec = date.millisecondsSinceEpoch();
+ ASSERT(isfinite(msec));
+ return msec;
+ }
case BUTTON:
case CHECKBOX:
@@ -1665,11 +1679,19 @@ void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec)
switch (inputType()) {
case DATE:
case DATETIME:
- case MONTH:
case TIME:
case WEEK:
setValueAsDate(newValue, ec);
return;
+ case MONTH: {
+ DateComponents date;
+ if (!date.setMonthsSinceEpoch(newValue)) {
+ setValue(String());
+ return;
+ }
+ setValue(date.toString());
+ return;
+ }
case DATETIMELOCAL: {
DateComponents date;
if (!date.setMillisecondsSinceEpochForDateTimeLocal(newValue)) {
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list