[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

tkent at chromium.org tkent at chromium.org
Thu Apr 8 00:47:33 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit a33bf62b7c172cd19071d35628032ef28be3d1e9
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Dec 23 11:05:04 2009 +0000

    2009-12-23  Kent Tamura  <tkent at chromium.org>
    
            Reviewed by Darin Adler.
    
            HTMLInputElement::valueAsDate getter support.
            https://bugs.webkit.org/show_bug.cgi?id=32876
    
            To implement the valueAsDate getter,
            - Add a method to calculate milliseconds from 1970-01-01 to ISODateTime.
            - Introduce m_type field to ISODateTime.
    
            Tests: fast/forms/input-valueasdate-date.html
                   fast/forms/input-valueasdate-datetime.html
                   fast/forms/input-valueasdate-datetimelocal.html
                   fast/forms/input-valueasdate-month.html
                   fast/forms/input-valueasdate-time.html
                   fast/forms/input-valueasdate-week.html
    
            * html/HTMLInputElement.cpp:
            (WebCore::HTMLInputElement::valueAsDate):
              Implement it with ISODateTime::millisecondsSinceEpoch().
            (WebCore::HTMLInputElement::formStringToISODateTime):
              Early exit for a null String. This avoids assertion failures in ISODateTime::parse*().
            * html/ISODateTime.cpp:
            (WebCore::ISODateTime::parseMonth): Sets m_type.
            (WebCore::ISODateTime::parseDate): ditto.
            (WebCore::ISODateTime::parseWeek): ditto.
            (WebCore::ISODateTime::parseTime): ditto.
            (WebCore::ISODateTime::parseDateTimeLocal): ditto.
            (WebCore::ISODateTime::parseDateTime): ditto.
            (WebCore::ISODateTime::millisecondsSinceEpochForTime): Added.
            (WebCore::ISODateTime::millisecondsSinceEpoch): Added.
            * html/ISODateTime.h:
            (WebCore::ISODateTime::ISODateTime):
            (WebCore::ISODateTime::invalidMilliseconds):
    
    2009-12-23  Kent Tamura  <tkent at chromium.org>
    
            Reviewed by Darin Adler.
    
            HTMLInputElement::valueAsDate getter support.
            https://bugs.webkit.org/show_bug.cgi?id=32876
    
            Tests for the valueAsDate getter with various types.
    
            * fast/forms/input-valueasdate-date-expected.txt: Added.
            * fast/forms/input-valueasdate-date.html: Added.
            * fast/forms/input-valueasdate-datetime-expected.txt: Added.
            * fast/forms/input-valueasdate-datetime.html: Added.
            * fast/forms/input-valueasdate-datetimelocal-expected.txt: Added.
            * fast/forms/input-valueasdate-datetimelocal.html: Added.
            * fast/forms/input-valueasdate-month-expected.txt: Added.
            * fast/forms/input-valueasdate-month.html: Added.
            * fast/forms/input-valueasdate-time-expected.txt: Added.
            * fast/forms/input-valueasdate-time.html: Added.
            * fast/forms/input-valueasdate-week-expected.txt: Added.
            * fast/forms/input-valueasdate-week.html: Added.
            * fast/forms/script-tests/input-valueasdate-date.js: Added.
            * fast/forms/script-tests/input-valueasdate-datetime.js: Added.
            * fast/forms/script-tests/input-valueasdate-datetimelocal.js: Added.
            * fast/forms/script-tests/input-valueasdate-month.js: Added.
            * fast/forms/script-tests/input-valueasdate-time.js: Added.
            * fast/forms/script-tests/input-valueasdate-week.js: Added.
    
    2009-12-23  Kent Tamura  <tkent at chromium.org>
    
            Reviewed by Darin Adler.
    
            HTMLInputElement::valueAsDate getter support.
            https://bugs.webkit.org/show_bug.cgi?id=32876
    
            Expose dateToDaysFrom1970().
    
            * JavaScriptCore.exp:
            * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
            * wtf/DateMath.cpp:
            (WTF::dateToDaysFrom1970):
            * wtf/DateMath.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52524 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 642c786..0d041d3 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,18 @@
+2009-12-23  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        HTMLInputElement::valueAsDate getter support.
+        https://bugs.webkit.org/show_bug.cgi?id=32876
+
+        Expose dateToDaysFrom1970().
+
+        * JavaScriptCore.exp:
+        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
+        * wtf/DateMath.cpp:
+        (WTF::dateToDaysFrom1970):
+        * wtf/DateMath.h:
+
 2009-12-22  Darin Adler  <darin at apple.com>
 
         Reviewed by Mark Rowe.
diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp
index 6a06215..30b174c 100644
--- a/JavaScriptCore/JavaScriptCore.exp
+++ b/JavaScriptCore/JavaScriptCore.exp
@@ -316,6 +316,7 @@ __ZN3WTF15ThreadConditionC1Ev
 __ZN3WTF15ThreadConditionD1Ev
 __ZN3WTF16callOnMainThreadEPFvPvES0_
 __ZN3WTF16fastZeroedMallocEm
+__ZN3WTF18dateToDaysFrom1970Eiii
 __ZN3WTF19initializeThreadingEv
 __ZN3WTF20fastMallocStatisticsEv
 __ZN3WTF21RefCountedLeakCounter16suppressMessagesEPKc
diff --git a/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def b/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
index ea22f34..e692c60 100644
--- a/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
+++ b/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
@@ -86,6 +86,7 @@ EXPORTS
     ?createTypeError at JSC@@YA?AVJSValue at 1@PAVExecState at 1@PBD at Z
     ?currentThread at WTF@@YAIXZ
     ?currentTime at WTF@@YANXZ
+    ?dateToDaysFrom1970 at WTF@@YANHHH at Z
     ?decrement at RefCountedLeakCounter@WTF@@QAEXXZ
     ?defaultAttributes at PropertyDescriptor@JSC@@0IA
     ?defaultValue at JSObject@JSC@@UBE?AVJSValue at 2@PAVExecState at 2@W4PreferredPrimitiveType at 2@@Z
diff --git a/JavaScriptCore/wtf/DateMath.cpp b/JavaScriptCore/wtf/DateMath.cpp
index df416d1..1f9c0e4 100644
--- a/JavaScriptCore/wtf/DateMath.cpp
+++ b/JavaScriptCore/wtf/DateMath.cpp
@@ -310,7 +310,7 @@ static inline double timeToMS(double hour, double min, double sec, double ms)
     return (((hour * minutesPerHour + min) * secondsPerMinute + sec) * msPerSecond + ms);
 }
 
-static double dateToDaysFrom1970(int year, int month, int day)
+double dateToDaysFrom1970(int year, int month, int day)
 {
     year += month / 12;
 
diff --git a/JavaScriptCore/wtf/DateMath.h b/JavaScriptCore/wtf/DateMath.h
index 6d4ac1e..3a9de22 100644
--- a/JavaScriptCore/wtf/DateMath.h
+++ b/JavaScriptCore/wtf/DateMath.h
@@ -76,8 +76,17 @@ const double msPerHour = 60.0 * 60.0 * 1000.0;
 const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
 const double msPerMonth = 2592000000.0;
 
+// Returns the number of days from 1970-01-01 to the specified date.
+double dateToDaysFrom1970(int year, int month, int day);
+
 } // namespace WTF
 
+using WTF::dateToDaysFrom1970;
+using WTF::minutesPerHour;
+using WTF::msPerDay;
+using WTF::msPerSecond;
+using WTF::secondsPerMinute;
+
 #if USE(JSC)
 namespace JSC {
 class ExecState;
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 48d0fd4..6c0e442 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,31 @@
+2009-12-23  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        HTMLInputElement::valueAsDate getter support.
+        https://bugs.webkit.org/show_bug.cgi?id=32876
+
+        Tests for the valueAsDate getter with various types.
+
+        * fast/forms/input-valueasdate-date-expected.txt: Added.
+        * fast/forms/input-valueasdate-date.html: Added.
+        * fast/forms/input-valueasdate-datetime-expected.txt: Added.
+        * fast/forms/input-valueasdate-datetime.html: Added.
+        * fast/forms/input-valueasdate-datetimelocal-expected.txt: Added.
+        * fast/forms/input-valueasdate-datetimelocal.html: Added.
+        * fast/forms/input-valueasdate-month-expected.txt: Added.
+        * fast/forms/input-valueasdate-month.html: Added.
+        * fast/forms/input-valueasdate-time-expected.txt: Added.
+        * fast/forms/input-valueasdate-time.html: Added.
+        * fast/forms/input-valueasdate-week-expected.txt: Added.
+        * fast/forms/input-valueasdate-week.html: Added.
+        * fast/forms/script-tests/input-valueasdate-date.js: Added.
+        * fast/forms/script-tests/input-valueasdate-datetime.js: Added.
+        * fast/forms/script-tests/input-valueasdate-datetimelocal.js: Added.
+        * fast/forms/script-tests/input-valueasdate-month.js: Added.
+        * fast/forms/script-tests/input-valueasdate-time.js: Added.
+        * fast/forms/script-tests/input-valueasdate-week.js: Added.
+
 2009-12-22  Kenneth Russell  <kbr at google.com>
 
         Reviewed by Eric Seidel.
diff --git a/LayoutTests/fast/forms/input-valueasdate-date-expected.txt b/LayoutTests/fast/forms/input-valueasdate-date-expected.txt
new file mode 100644
index 0000000..108de8b
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-date-expected.txt
@@ -0,0 +1,13 @@
+Tests for .valueAsDate with <input type=date>.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS valueAsDateFor("") is null
+PASS valueAsDateFor("1969-12-31").getTime() is Date.UTC(1969, 11, 31)
+PASS valueAsDateFor("1970-01-01").getTime() is Date.UTC(1970, 0, 1)
+PASS valueAsDateFor("2009-12-22").getTime() is Date.UTC(2009, 11, 22)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-valueasdate-date.html b/LayoutTests/fast/forms/input-valueasdate-date.html
new file mode 100644
index 0000000..2e01a63
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-date.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/input-valueasdate-date.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/input-valueasdate-datetime-expected.txt b/LayoutTests/fast/forms/input-valueasdate-datetime-expected.txt
new file mode 100644
index 0000000..95e5fe8
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-datetime-expected.txt
@@ -0,0 +1,13 @@
+Tests for .valueAsDate with <input type=datetime>.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS valueAsDateFor("") is null
+PASS valueAsDateFor("1969-12-31T12:34:56.789Z").getTime() is Date.UTC(1969, 11, 31, 12, 34, 56, 789)
+PASS valueAsDateFor("1970-01-01T00:00:00.000Z").getTime() is Date.UTC(1970, 0, 1, 0, 0, 0)
+PASS valueAsDateFor("2009-12-22T11:32:11Z").getTime() is Date.UTC(2009, 11, 22, 11, 32, 11)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-valueasdate-datetime.html b/LayoutTests/fast/forms/input-valueasdate-datetime.html
new file mode 100644
index 0000000..21a9b8c
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-datetime.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/input-valueasdate-datetime.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/input-valueasdate-datetimelocal-expected.txt b/LayoutTests/fast/forms/input-valueasdate-datetimelocal-expected.txt
new file mode 100644
index 0000000..cab9f16
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-datetimelocal-expected.txt
@@ -0,0 +1,13 @@
+Tests for .valueAsDate with <input type=datetimelocal>.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS valueAsDateFor("") is null
+PASS valueAsDateFor("1969-12-31T12:34:56.789") is null
+PASS valueAsDateFor("1970-01-01T00:00:00.000") is null
+PASS valueAsDateFor("2009-12-22T11:32:11") is null
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-valueasdate-datetimelocal.html b/LayoutTests/fast/forms/input-valueasdate-datetimelocal.html
new file mode 100644
index 0000000..f5eb2f7
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-datetimelocal.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/input-valueasdate-datetimelocal.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/input-valueasdate-month-expected.txt b/LayoutTests/fast/forms/input-valueasdate-month-expected.txt
new file mode 100644
index 0000000..8dd71e7
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-month-expected.txt
@@ -0,0 +1,13 @@
+Tests for .valueAsDate with <input type=month>.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS valueAsDateFor("") is null
+PASS valueAsDateFor("1969-12").getTime() is Date.UTC(1969, 11, 1, 0, 0, 0, 0)
+PASS valueAsDateFor("1970-01").getTime() is Date.UTC(1970, 0, 1)
+PASS valueAsDateFor("2009-12").getTime() is Date.UTC(2009, 11, 1)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-valueasdate-month.html b/LayoutTests/fast/forms/input-valueasdate-month.html
new file mode 100644
index 0000000..0bcd055
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-month.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/input-valueasdate-month.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/input-valueasdate-time-expected.txt b/LayoutTests/fast/forms/input-valueasdate-time-expected.txt
new file mode 100644
index 0000000..189e8ca
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-time-expected.txt
@@ -0,0 +1,13 @@
+Tests for .valueAsDate with <input type=time>.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS valueAsDateFor("") is null
+PASS valueAsDateFor("00:00:00.000").getTime() is Date.UTC(1970, 0, 1, 0, 0, 0, 0)
+PASS valueAsDateFor("04:35").getTime() is Date.UTC(1970, 0, 1, 4, 35, 0, 0)
+PASS valueAsDateFor("23:59:59.999").getTime() is Date.UTC(1970, 0, 1, 23, 59, 59, 999)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-valueasdate-time.html b/LayoutTests/fast/forms/input-valueasdate-time.html
new file mode 100644
index 0000000..dbeda1a
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-time.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/input-valueasdate-time.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/input-valueasdate-week-expected.txt b/LayoutTests/fast/forms/input-valueasdate-week-expected.txt
new file mode 100644
index 0000000..a4e9c8b
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-week-expected.txt
@@ -0,0 +1,17 @@
+Tests for .valueAsDate with <input type=week>.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS valueAsDateFor("") is null
+PASS valueAsDateFor("2007-W01").getTime() is Date.UTC(2007, 0, 1)
+PASS valueAsDateFor("2008-W01").getTime() is Date.UTC(2007, 11, 31)
+PASS valueAsDateFor("2003-W01").getTime() is Date.UTC(2002, 11, 30)
+PASS valueAsDateFor("2004-W01").getTime() is Date.UTC(2003, 11, 29, 0, 0, 0, 0)
+PASS valueAsDateFor("2010-W01").getTime() is Date.UTC(2010, 0, 4)
+PASS valueAsDateFor("2005-W01").getTime() is Date.UTC(2005, 0, 3)
+PASS valueAsDateFor("2006-W01").getTime() is Date.UTC(2006, 0, 2)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-valueasdate-week.html b/LayoutTests/fast/forms/input-valueasdate-week.html
new file mode 100644
index 0000000..ea8bcd9
--- /dev/null
+++ b/LayoutTests/fast/forms/input-valueasdate-week.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/input-valueasdate-week.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/script-tests/input-valueasdate-date.js b/LayoutTests/fast/forms/script-tests/input-valueasdate-date.js
new file mode 100644
index 0000000..f07f773
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-valueasdate-date.js
@@ -0,0 +1,16 @@
+description('Tests for .valueAsDate with &lt;input type=date>.');
+
+var input = document.createElement('input');
+input.type = 'date';
+
+function valueAsDateFor(stringValue) {
+    input.value = stringValue;
+    return input.valueAsDate;
+}
+
+shouldBe('valueAsDateFor("")', 'null');
+shouldBe('valueAsDateFor("1969-12-31").getTime()', 'Date.UTC(1969, 11, 31)');
+shouldBe('valueAsDateFor("1970-01-01").getTime()', 'Date.UTC(1970, 0, 1)');
+shouldBe('valueAsDateFor("2009-12-22").getTime()', 'Date.UTC(2009, 11, 22)');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/input-valueasdate-datetime.js b/LayoutTests/fast/forms/script-tests/input-valueasdate-datetime.js
new file mode 100644
index 0000000..c264f87
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-valueasdate-datetime.js
@@ -0,0 +1,16 @@
+description('Tests for .valueAsDate with &lt;input type=datetime>.');
+
+var input = document.createElement('input');
+input.type = 'datetime';
+
+function valueAsDateFor(stringValue) {
+    input.value = stringValue;
+    return input.valueAsDate;
+}
+
+shouldBe('valueAsDateFor("")', 'null');
+shouldBe('valueAsDateFor("1969-12-31T12:34:56.789Z").getTime()', 'Date.UTC(1969, 11, 31, 12, 34, 56, 789)');
+shouldBe('valueAsDateFor("1970-01-01T00:00:00.000Z").getTime()', 'Date.UTC(1970, 0, 1, 0, 0, 0)');
+shouldBe('valueAsDateFor("2009-12-22T11:32:11Z").getTime()', 'Date.UTC(2009, 11, 22, 11, 32, 11)');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/input-valueasdate-datetimelocal.js b/LayoutTests/fast/forms/script-tests/input-valueasdate-datetimelocal.js
new file mode 100644
index 0000000..b12cc71
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-valueasdate-datetimelocal.js
@@ -0,0 +1,16 @@
+description('Tests for .valueAsDate with &lt;input type=datetimelocal>.');
+
+var input = document.createElement('input');
+input.type = 'datetime-local';
+
+function valueAsDateFor(stringValue) {
+    input.value = stringValue;
+    return input.valueAsDate;
+}
+
+shouldBe('valueAsDateFor("")', 'null');
+shouldBe('valueAsDateFor("1969-12-31T12:34:56.789")', 'null');
+shouldBe('valueAsDateFor("1970-01-01T00:00:00.000")', 'null');
+shouldBe('valueAsDateFor("2009-12-22T11:32:11")', 'null');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/input-valueasdate-month.js b/LayoutTests/fast/forms/script-tests/input-valueasdate-month.js
new file mode 100644
index 0000000..63cb281
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-valueasdate-month.js
@@ -0,0 +1,16 @@
+description('Tests for .valueAsDate with &lt;input type=month>.');
+
+var input = document.createElement('input');
+input.type = 'month';
+
+function valueAsDateFor(stringValue) {
+    input.value = stringValue;
+    return input.valueAsDate;
+}
+
+shouldBe('valueAsDateFor("")', 'null');
+shouldBe('valueAsDateFor("1969-12").getTime()', 'Date.UTC(1969, 11, 1, 0, 0, 0, 0)');
+shouldBe('valueAsDateFor("1970-01").getTime()', 'Date.UTC(1970, 0, 1)');
+shouldBe('valueAsDateFor("2009-12").getTime()', 'Date.UTC(2009, 11, 1)');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/input-valueasdate-time.js b/LayoutTests/fast/forms/script-tests/input-valueasdate-time.js
new file mode 100644
index 0000000..59144cb
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-valueasdate-time.js
@@ -0,0 +1,16 @@
+description('Tests for .valueAsDate with &lt;input type=time>.');
+
+var input = document.createElement('input');
+input.type = 'time';
+
+function valueAsDateFor(stringValue) {
+    input.value = stringValue;
+    return input.valueAsDate;
+}
+
+shouldBe('valueAsDateFor("")', 'null');
+shouldBe('valueAsDateFor("00:00:00.000").getTime()', 'Date.UTC(1970, 0, 1, 0, 0, 0, 0)');
+shouldBe('valueAsDateFor("04:35").getTime()', 'Date.UTC(1970, 0, 1, 4, 35, 0, 0)');
+shouldBe('valueAsDateFor("23:59:59.999").getTime()', 'Date.UTC(1970, 0, 1, 23, 59, 59, 999)');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/input-valueasdate-week.js b/LayoutTests/fast/forms/script-tests/input-valueasdate-week.js
new file mode 100644
index 0000000..f9c469e
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-valueasdate-week.js
@@ -0,0 +1,27 @@
+description('Tests for .valueAsDate with &lt;input type=week>.');
+
+var input = document.createElement('input');
+input.type = 'week';
+
+function valueAsDateFor(stringValue) {
+    input.value = stringValue;
+    return input.valueAsDate;
+}
+
+shouldBe('valueAsDateFor("")', 'null');
+// January 1st is Monday. W01 starts on January 1nd.
+shouldBe('valueAsDateFor("2007-W01").getTime()', 'Date.UTC(2007, 0, 1)');
+// January 1st is Tuesday. W01 starts on December 31th.
+shouldBe('valueAsDateFor("2008-W01").getTime()', 'Date.UTC(2007, 11, 31)');
+// January 1st is Wednesday. W01 starts on December 29th.
+shouldBe('valueAsDateFor("2003-W01").getTime()', 'Date.UTC(2002, 11, 30)');
+// January 1st is Thursday. W01 starts on December 29th.
+shouldBe('valueAsDateFor("2004-W01").getTime()', 'Date.UTC(2003, 11, 29, 0, 0, 0, 0)');
+// January 1st is Friday. W01 starts on January 4th.
+shouldBe('valueAsDateFor("2010-W01").getTime()', 'Date.UTC(2010, 0, 4)');
+// January 1st is Saturday. W01 starts on January 3rd.
+shouldBe('valueAsDateFor("2005-W01").getTime()', 'Date.UTC(2005, 0, 3)');
+// January 1st is Sunday. W01 starts on January 2nd.
+shouldBe('valueAsDateFor("2006-W01").getTime()', 'Date.UTC(2006, 0, 2)');
+
+var successfullyParsed = true;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 5e08d7f..22226eb 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,39 @@
+2009-12-23  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        HTMLInputElement::valueAsDate getter support.
+        https://bugs.webkit.org/show_bug.cgi?id=32876
+
+        To implement the valueAsDate getter,
+        - Add a method to calculate milliseconds from 1970-01-01 to ISODateTime.
+        - Introduce m_type field to ISODateTime.
+
+        Tests: fast/forms/input-valueasdate-date.html
+               fast/forms/input-valueasdate-datetime.html
+               fast/forms/input-valueasdate-datetimelocal.html
+               fast/forms/input-valueasdate-month.html
+               fast/forms/input-valueasdate-time.html
+               fast/forms/input-valueasdate-week.html
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::valueAsDate):
+          Implement it with ISODateTime::millisecondsSinceEpoch().
+        (WebCore::HTMLInputElement::formStringToISODateTime):
+          Early exit for a null String. This avoids assertion failures in ISODateTime::parse*().
+        * html/ISODateTime.cpp:
+        (WebCore::ISODateTime::parseMonth): Sets m_type.
+        (WebCore::ISODateTime::parseDate): ditto.
+        (WebCore::ISODateTime::parseWeek): ditto.
+        (WebCore::ISODateTime::parseTime): ditto.
+        (WebCore::ISODateTime::parseDateTimeLocal): ditto.
+        (WebCore::ISODateTime::parseDateTime): ditto.
+        (WebCore::ISODateTime::millisecondsSinceEpochForTime): Added.
+        (WebCore::ISODateTime::millisecondsSinceEpoch): Added.
+        * html/ISODateTime.h:
+        (WebCore::ISODateTime::ISODateTime):
+        (WebCore::ISODateTime::invalidMilliseconds):
+
 2009-12-22  Daniel Bates  <dbates at webkit.org>
 
         Reviewed by Eric Seidel.
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index b3b9b9c..b2c88c5 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -1376,10 +1376,21 @@ void HTMLInputElement::setValue(const String& value, bool sendChangeEvent)
 
 double HTMLInputElement::valueAsDate() const
 {
-    // FIXME: This is a temporary implementation to check Date binding.
-    if (inputType() == MONTH)
-        return 0.0;
-    return std::numeric_limits<double>::quiet_NaN();
+    switch (inputType()) {
+    // valueAsDate doesn't work for the DATETIMELOCAL type according to the standard.
+    case DATE:
+    case DATETIME:
+    case MONTH:
+    case TIME:
+    case WEEK: {
+        ISODateTime dateTime;
+        if (!formStringToISODateTime(inputType(), value(), &dateTime))
+            return ISODateTime::invalidMilliseconds();
+        return dateTime.millisecondsSinceEpoch();
+    }
+    default:
+        return ISODateTime::invalidMilliseconds();
+    }
 }
 
 void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec)
@@ -2129,6 +2140,8 @@ bool HTMLInputElement::formStringToDouble(const String& src, double* out)
 
 bool HTMLInputElement::formStringToISODateTime(InputType type, const String& formString, ISODateTime* out)
 {
+    if (formString.isEmpty())
+        return false;
     ISODateTime ignoredResult;
     if (!out)
         out = &ignoredResult;
diff --git a/WebCore/html/ISODateTime.cpp b/WebCore/html/ISODateTime.cpp
index 4c28ac0..bef4808 100644
--- a/WebCore/html/ISODateTime.cpp
+++ b/WebCore/html/ISODateTime.cpp
@@ -33,6 +33,7 @@
 
 #include <limits.h>
 #include <wtf/ASCIICType.h>
+#include <wtf/DateMath.h>
 
 namespace WebCore {
 
@@ -293,6 +294,7 @@ bool ISODateTime::parseMonth(const UChar* src, unsigned length, unsigned start,
         return false;
     m_month = month;
     end = index + 2;
+    m_type = Month;
     return true;
 }
 
@@ -317,6 +319,7 @@ bool ISODateTime::parseDate(const UChar* src, unsigned length, unsigned start, u
         return false;
     m_monthDay = day;
     end = index + 2;
+    m_type = Date;
     return true;
 }
 
@@ -345,6 +348,7 @@ bool ISODateTime::parseWeek(const UChar* src, unsigned length, unsigned start, u
         return false;
     m_week = week;
     end = index + 2;
+    m_type = Week;
     return true;
 }
 
@@ -399,6 +403,7 @@ bool ISODateTime::parseTime(const UChar* src, unsigned length, unsigned start, u
     m_second = second;
     m_millisecond = millisecond;
     end = index;
+    m_type = Time;
     return true;
 }
 
@@ -413,7 +418,10 @@ bool ISODateTime::parseDateTimeLocal(const UChar* src, unsigned length, unsigned
     if (src[index] != 'T')
         return false;
     ++index;
-    return parseTime(src, length, index, end);
+    if (!parseTime(src, length, index, end))
+        return false;
+    m_type = DateTimeLocal;
+    return true;
 }
 
 bool ISODateTime::parseDateTime(const UChar* src, unsigned length, unsigned start, unsigned& end)
@@ -429,7 +437,43 @@ bool ISODateTime::parseDateTime(const UChar* src, unsigned length, unsigned star
     ++index;
     if (!parseTime(src, length, index, index))
         return false;
-    return parseTimeZone(src, length, index, end);
+    if (!parseTimeZone(src, length, index, end))
+        return false;
+    m_type = DateTime;
+    return true;
+}
+
+double ISODateTime::millisecondsSinceEpochForTime() const
+{
+    ASSERT(m_type == Time || m_type == DateTime);
+    return ((m_hour * minutesPerHour + m_minute) * secondsPerMinute + m_second) * msPerSecond + m_millisecond;
+}
+
+double ISODateTime::millisecondsSinceEpoch() const
+{
+    switch (m_type) {
+    case Date:
+        return dateToDaysFrom1970(m_year, m_month, m_monthDay) * msPerDay;
+    case DateTime:
+    case DateTimeLocal:
+        return dateToDaysFrom1970(m_year, m_month, m_monthDay) * msPerDay + millisecondsSinceEpochForTime();
+    case Month:
+        return dateToDaysFrom1970(m_year, m_month, 1) * msPerDay;
+    case Time:
+        return millisecondsSinceEpochForTime();
+    case Week: {
+        // 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.
+        int offsetTo1stWeekStart = 1 - dayOfWeek(m_year, 0, 1);
+        if (offsetTo1stWeekStart <= -4)
+            offsetTo1stWeekStart += 7;
+        return (dateToDaysFrom1970(m_year, 0, 1) + offsetTo1stWeekStart + (m_week - 1) * 7) * msPerDay;
+    }
+    case Invalid:
+        break;
+    }
+    ASSERT_NOT_REACHED();
+    return invalidMilliseconds();
 }
 
 } // namespace WebCore
diff --git a/WebCore/html/ISODateTime.h b/WebCore/html/ISODateTime.h
index ee4cfb9..3cd01cb 100644
--- a/WebCore/html/ISODateTime.h
+++ b/WebCore/html/ISODateTime.h
@@ -31,6 +31,7 @@
 #ifndef ISODateTime_h
 #define ISODateTime_h
 
+#include <limits>
 #include <wtf/unicode/Unicode.h>
 
 namespace WebCore {
@@ -52,6 +53,7 @@ public:
         , m_month(0)
         , m_year(0)
         , m_week(0)
+        , m_type(Invalid)
     {
     }
 
@@ -86,6 +88,12 @@ public:
     // Sets year, month, monthDay, hour, minute, second and millisecond, and adjusts timezone.
     bool parseDateTime(const UChar* src, unsigned length, unsigned start, unsigned& end);
 
+    // Returns the number of milliseconds from 1970-01-01 00:00:00 UTC.
+    // For an ISODateTime initialized with parseDateTimeLocal(),
+    // millisecondsSinceEpoch() returns a value for UTC timezone.
+    double millisecondsSinceEpoch() const;
+    static inline double invalidMilliseconds() { return std::numeric_limits<double>::quiet_NaN(); }
+
 private:
     // Returns the maximum week number in this ISODateTime's year.
     // The result is either of 52 and 53.
@@ -94,6 +102,8 @@ private:
     bool addDay(int);
     bool addMinute(int);
     bool parseTimeZone(const UChar* src, unsigned length, unsigned start, unsigned& end);
+    // Helper for millisecondsSinceEpoch().
+    double millisecondsSinceEpochForTime() const;
 
     // m_weekDay values
     enum {
@@ -114,6 +124,17 @@ private:
     int m_month;  // 0:January - 11:December
     int m_year;  //  1582 -
     int m_week;  // 1 - 53
+
+    enum Type {
+        Invalid,
+        Date,
+        DateTime,
+        DateTimeLocal,
+        Month,
+        Time,
+        Week,
+    };
+    Type m_type;
 };
 
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list