Changeset 53445 in webkit
- Timestamp:
- Jan 18, 2010 5:49:42 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r53444 r53445 1 2010-01-18 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 HTMLInputElement::valueAsDate setter support for type=month. 6 https://bugs.webkit.org/show_bug.cgi?id=33021 7 8 Expose the following functions to be used by WebCore: 9 - WTF::msToyear() 10 - WTF::dayInYear() 11 - WTF::monthFromDayInYear() 12 - WTF::dayInMonthFromDayInYear() 13 14 * JavaScriptCore.exp: 15 * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: 16 * wtf/DateMath.cpp: 17 (WTF::msToYear): Remove "static inline". 18 (WTF::dayInYear): Remove "static inline". 19 (WTF::monthFromDayInYear): Remove "static inline". 20 (WTF::dayInMonthFromDayInYear): Remove "static inline". 21 * wtf/DateMath.h: Declare the above functions. 22 1 23 2010-01-18 Darin Adler <darin@apple.com> 2 24 -
trunk/JavaScriptCore/JavaScriptCore.exp
r53320 r53445 320 320 __ZN3WTF16fastZeroedMallocEm 321 321 __ZN3WTF18dateToDaysFrom1970Eiii 322 __ZN3WTF18monthFromDayInYearEib 322 323 __ZN3WTF19initializeThreadingEv 323 324 __ZN3WTF20fastMallocStatisticsEv … … 329 330 __ZN3WTF21RefCountedLeakCounterD1Ev 330 331 __ZN3WTF23callOnMainThreadAndWaitEPFvPvES0_ 332 __ZN3WTF23dayInMonthFromDayInYearEib 331 333 __ZN3WTF23waitForThreadCompletionEjPPv 332 334 __ZN3WTF27releaseFastMallocFreeMemoryEv … … 347 349 __ZN3WTF8CollatorD1Ev 348 350 __ZN3WTF8fastFreeEPv 351 __ZN3WTF8msToYearEd 352 __ZN3WTF9dayInYearEdi 349 353 __ZN3WTF9ByteArray6createEm 350 354 __ZNK3JSC10JSFunction23isHostFunctionNonInlineEv -
trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
r53320 r53445 87 87 ?currentTime@WTF@@YANXZ 88 88 ?dateToDaysFrom1970@WTF@@YANHHH@Z 89 ?dayInMonthFromDayInYear@WTF@@YAHH_N@Z 90 ?dayInYear@WTF@@YAHNH@Z 89 91 ?decrement@RefCountedLeakCounter@WTF@@QAEXXZ 90 92 ?defaultAttributes@PropertyDescriptor@JSC@@0IA … … 195 197 ?markChildren@JSWrapperObject@JSC@@EAEXAAVMarkStack@2@@Z 196 198 ?materializePropertyMap@Structure@JSC@@AAEXXZ 199 ?monthFromDayInYear@WTF@@YAHH_N@Z 200 ?msToYear@WTF@@YAHN@Z 197 201 ?name@InternalFunction@JSC@@QAEABVUString@2@PAVExecState@2@@Z 198 202 ?nonInlineNaN@JSC@@YANXZ -
trunk/JavaScriptCore/wtf/DateMath.cpp
r52791 r53445 173 173 } 174 174 175 static inlineint msToYear(double ms)175 int msToYear(double ms) 176 176 { 177 177 int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970); … … 184 184 } 185 185 186 static inlineint dayInYear(double ms, int year)186 int dayInYear(double ms, int year) 187 187 { 188 188 return static_cast<int>(msToDays(ms) - daysFrom1970ToYear(year)); … … 230 230 } 231 231 232 static inlineint monthFromDayInYear(int dayInYear, bool leapYear)232 int monthFromDayInYear(int dayInYear, bool leapYear) 233 233 { 234 234 const int d = dayInYear; … … 268 268 } 269 269 270 static inlineint dayInMonthFromDayInYear(int dayInYear, bool leapYear)270 int dayInMonthFromDayInYear(int dayInYear, bool leapYear) 271 271 { 272 272 const int d = dayInYear; -
trunk/JavaScriptCore/wtf/DateMath.h
r52524 r53445 79 79 // Returns the number of days from 1970-01-01 to the specified date. 80 80 double dateToDaysFrom1970(int year, int month, int day); 81 int msToYear(double ms); 82 int dayInYear(double ms, int year); 83 int monthFromDayInYear(int dayInYear, bool leapYear); 84 int dayInMonthFromDayInYear(int dayInYear, bool leapYear); 81 85 82 86 } // namespace WTF 83 87 84 88 using WTF::dateToDaysFrom1970; 89 using WTF::dayInMonthFromDayInYear; 90 using WTF::dayInYear; 85 91 using WTF::minutesPerHour; 92 using WTF::monthFromDayInYear; 86 93 using WTF::msPerDay; 87 94 using WTF::msPerSecond; 95 using WTF::msToYear; 88 96 using WTF::secondsPerMinute; 89 97 -
trunk/LayoutTests/ChangeLog
r53442 r53445 1 2010-01-18 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 HTMLInputElement::valueAsDate setter support for type=month. 6 https://bugs.webkit.org/show_bug.cgi?id=33021 7 8 Add setter tests to input-valueasdate-month.js, and update the 9 expectation. 10 11 * fast/forms/input-valueasdate-expected.txt: 12 * fast/forms/input-valueasdate-month-expected.txt: 13 * fast/forms/script-tests/input-valueasdate-month.js: 14 * fast/forms/script-tests/input-valueasdate.js: 15 1 16 2010-01-18 Enrica Casucci <enrica@apple.com> 2 17 -
trunk/LayoutTests/fast/forms/input-valueasdate-expected.txt
r52434 r53445 19 19 PASS input.valueAsDate.getTime() is 0 20 20 Sets other types: 21 PASS input.value AsDate = null threw exception Error: INVALID_STATE_ERR: DOM Exception 11.22 PASS input.value AsDate = undefined threw exception Error: INVALID_STATE_ERR: DOM Exception 11.23 PASS input.value AsDate = document threw exception Error: INVALID_STATE_ERR: DOM Exception 11.21 PASS input.value is "" 22 PASS input.value is "" 23 PASS input.value is "" 24 24 PASS successfullyParsed is true 25 25 -
trunk/LayoutTests/fast/forms/input-valueasdate-month-expected.txt
r52524 r53445 8 8 PASS valueAsDateFor("1970-01").getTime() is Date.UTC(1970, 0, 1) 9 9 PASS valueAsDateFor("2009-12").getTime() is Date.UTC(2009, 11, 1) 10 PASS setValueAsDateAndGetValue(1969, 11, 1) is "1969-12" 11 PASS setValueAsDateAndGetValue(1970, 0, 1) is "1970-01" 12 PASS setValueAsDateAndGetValue(2009, 11, 31) is "2009-12" 13 PASS setValueAsDateAndGetValue(10000, 0, 1) is "10000-01" 14 PASS setValueAsDateAndGetValue(794, 9, 22) is "" 15 PASS setValueAsDateAndGetValue(1582, 8, 30) is "" 16 PASS setValueAsDateAndGetValue(1582, 9, 1) is "1582-10" 17 PASS setValueAsDateAndGetValue(1582, 9, 31) is "1582-10" 18 PASS setValueAsDateAndGetValue(275760, 8, 13) is "275760-09" 19 PASS setValueAsDateAndGetValue(275760, 8, 14) is "" 20 Sets null to valueAsDate: 21 PASS input.value is "" 10 22 PASS successfullyParsed is true 11 23 -
trunk/LayoutTests/fast/forms/script-tests/input-valueasdate-month.js
r52524 r53445 9 9 } 10 10 11 function setValueAsDateAndGetValue(year, month, day) { 12 var date = new Date(); 13 date.setTime(Date.UTC(year, month, day)); 14 input.valueAsDate = date; 15 return input.value; 16 } 17 11 18 shouldBe('valueAsDateFor("")', 'null'); 12 19 shouldBe('valueAsDateFor("1969-12").getTime()', 'Date.UTC(1969, 11, 1, 0, 0, 0, 0)'); … … 14 21 shouldBe('valueAsDateFor("2009-12").getTime()', 'Date.UTC(2009, 11, 1)'); 15 22 23 shouldBe('setValueAsDateAndGetValue(1969, 11, 1)', '"1969-12"'); 24 shouldBe('setValueAsDateAndGetValue(1970, 0, 1)', '"1970-01"'); 25 shouldBe('setValueAsDateAndGetValue(2009, 11, 31)', '"2009-12"'); 26 shouldBe('setValueAsDateAndGetValue(10000, 0, 1)', '"10000-01"'); 27 28 shouldBe('setValueAsDateAndGetValue(794, 9, 22)', '""'); 29 shouldBe('setValueAsDateAndGetValue(1582, 8, 30)', '""'); 30 shouldBe('setValueAsDateAndGetValue(1582, 9, 1)', '"1582-10"'); 31 shouldBe('setValueAsDateAndGetValue(1582, 9, 31)', '"1582-10"'); 32 shouldBe('setValueAsDateAndGetValue(275760, 8, 13)', '"275760-09"'); 33 shouldBe('setValueAsDateAndGetValue(275760, 8, 14)', '""'); // Date of JavaScript can't represent this. 34 35 debug('Sets null to valueAsDate:'); 36 input.value = '2009-12'; 37 input.valueAsDate = null; 38 shouldBe('input.value', '""'); 39 16 40 var successfullyParsed = true; -
trunk/LayoutTests/fast/forms/script-tests/input-valueasdate.js
r52434 r53445 29 29 shouldBe('input.valueAsDate.getTime()', '0'); 30 30 debug('Sets other types:'); 31 shouldThrow('input.valueAsDate = null', 'invalidStateError'); 32 shouldThrow('input.valueAsDate = undefined', 'invalidStateError'); 33 shouldThrow('input.valueAsDate = document', 'invalidStateError'); 31 input.value = '1970-01'; 32 input.valueAsDate = null; 33 shouldBe('input.value', '""'); 34 input.value = '1970-01'; 35 input.valueAsDate = undefined; 36 shouldBe('input.value', '""'); 37 input.value = '1970-01'; 38 input.valueAsDate = document; 39 shouldBe('input.value', '""'); 40 34 41 35 42 var successfullyParsed = true; -
trunk/WebCore/ChangeLog
r53443 r53445 1 2010-01-18 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 HTMLInputElement::valueAsDate setter support for type=month. 6 https://bugs.webkit.org/show_bug.cgi?id=33021 7 8 Introduce ISODateTime::setMillisecondsSinceEpochForMonth() and 9 toString() for the Month type, and HTMLInputElement::setValueAsDate() 10 calls them. 11 12 * html/HTMLInputElement.cpp: 13 (WebCore::HTMLInputElement::setValueAsDate): 14 * html/ISODateTime.cpp: 15 (WebCore::beforeGregorianStartDate): 16 (WebCore::ISODateTime::addDay): Use beforeGregorianStartDate(). 17 (WebCore::ISODateTime::parseMonth): Use beforeGregorianStartDate(). 18 (WebCore::ISODateTime::setMillisecondsSinceEpochForDateInternal): 19 (WebCore::ISODateTime::setMillisecondsSinceEpochForMonth): 20 (WebCore::ISODateTime::toString): Implement only for the Month type. 21 * html/ISODateTime.h: 22 1 23 2010-01-18 Enrica Casucci <enrica@apple.com> 2 24 -
trunk/WebCore/html/HTMLInputElement.cpp
r52967 r53445 1396 1396 void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec) 1397 1397 { 1398 // FIXME: This is a temporary implementation to check Date binding. 1399 if (!isnan(value) && !isinf(value) && inputType() == MONTH) { 1400 setValue(String("1970-01")); 1398 ISODateTime dateTime; 1399 bool success; 1400 switch (inputType()) { 1401 case MONTH: 1402 success = dateTime.setMillisecondsSinceEpochForMonth(value); 1403 break; 1404 // FIXME: implementations for other supported types. 1405 default: 1406 ec = INVALID_STATE_ERR; 1401 1407 return; 1402 1408 } 1403 ec = INVALID_STATE_ERR; 1409 if (!success) { 1410 setValue(String()); 1411 return; 1412 } 1413 setValue(dateTime.toString()); 1404 1414 } 1405 1415 -
trunk/WebCore/html/ISODateTime.cpp
r52524 r53445 32 32 #include "ISODateTime.h" 33 33 34 #include "PlatformString.h" 34 35 #include <limits.h> 35 36 #include <wtf/ASCIICType.h> 36 37 #include <wtf/DateMath.h> 38 #include <wtf/MathExtras.h> 37 39 38 40 namespace WebCore { … … 137 139 end = start + digitsLength; 138 140 return true; 141 } 142 143 static bool beforeGregorianStartDate(int year, int month, int monthDay) 144 { 145 return year < gregorianStartYear 146 || year == gregorianStartYear && month < gregorianStartMonth 147 || year == gregorianStartYear && month == gregorianStartMonth && monthDay < gregorianStartDay; 139 148 } 140 149 … … 179 188 day = maxDayOfMonth(year, month); 180 189 } 181 if (year < gregorianStartYear 182 || (year == gregorianStartYear && month < gregorianStartMonth) 183 || (year == gregorianStartYear && month == gregorianStartMonth && day < gregorianStartDay)) 190 if (beforeGregorianStartDate(year, month, day)) 184 191 return false; 185 192 } … … 291 298 --month; 292 299 // No support for months before Gregorian calendar. 293 if ( m_year == gregorianStartYear && month < gregorianStartMonth)300 if (beforeGregorianStartDate(m_year, month, gregorianStartDay)) 294 301 return false; 295 302 m_month = month; … … 444 451 } 445 452 453 bool ISODateTime::setMillisecondsSinceEpochForDateInternal(double ms) 454 { 455 m_year = msToYear(ms); 456 int yearDay = dayInYear(ms, m_year); 457 m_month = monthFromDayInYear(yearDay, isLeapYear(m_year)); 458 m_monthDay = dayInMonthFromDayInYear(yearDay, isLeapYear(m_year)); 459 return true; 460 } 461 462 bool ISODateTime::setMillisecondsSinceEpochForMonth(double ms) 463 { 464 if (!isfinite(ms)) 465 return false; 466 if (!setMillisecondsSinceEpochForDateInternal(ms)) 467 return false; 468 // Ignore m_monthDay updated by setMillisecondsSinceEpochForDateInternal(). 469 if (beforeGregorianStartDate(m_year, m_month, gregorianStartDay)) 470 return false; 471 m_type = Month; 472 return true; 473 } 474 446 475 double ISODateTime::millisecondsSinceEpochForTime() const 447 476 { … … 477 506 } 478 507 508 String ISODateTime::toString() const 509 { 510 switch (m_type) { 511 case Month: 512 return String::format("%04d-%02d", m_year, m_month + 1); 513 514 // FIXME: implementations for other types. 515 default: 516 break; 517 } 518 ASSERT_NOT_REACHED(); 519 return String("(Invalid ISODateTime)"); 520 } 521 479 522 } // namespace WebCore -
trunk/WebCore/html/ISODateTime.h
r52524 r53445 37 37 namespace WebCore { 38 38 39 class String; 40 39 41 // An ISODateTime instance represents one of the following date and time combinations: 40 // * year-month41 // * year-month-day42 // * year-week43 // * hour-minute-second-millisecond44 // * year-month-day hour-minute-second-millisecond42 // * Month type: year-month 43 // * Date type: year-month-day 44 // * Week type: year-week 45 // * Time type: hour-minute-second-millisecond 46 // * DateTime or DateTimeLocal type: year-month-day hour-minute-second-millisecond 45 47 class ISODateTime { 46 48 public: … … 67 69 int week() const { return m_week; } 68 70 69 // The following six functions parse the input `src' whose length is 70 // `length', and updates some fields of this instance. The parsing starts at 71 // Returns an ISO 8601 representation for this instance. 72 String toString() const; 73 74 // The following six functions parse the input 'src' whose length is 75 // 'length', and updates some fields of this instance. The parsing starts at 71 76 // src[start] and examines characters before src[length]. 72 // `src' `date' must be non-null. The `src' string doesn't need to be77 // 'src' must be non-null. The 'src' string doesn't need to be 73 78 // null-terminated. 74 // The functions return true if the parsing succeeds, and set `end' to the79 // The functions return true if the parsing succeeds, and set 'end' to the 75 80 // next index after the last consumed. Extra leading characters cause parse 76 81 // failures, and the trailing extra characters don't cause parse failures. … … 88 93 // Sets year, month, monthDay, hour, minute, second and millisecond, and adjusts timezone. 89 94 bool parseDateTime(const UChar* src, unsigned length, unsigned start, unsigned& end); 95 96 // The following setMillisecondsSinceEpochFor*() function takes 97 // the number of milliseconds since 1970-01-01 00:00:00.000 UTC as 98 // the argument, and update all fields for the corresponding 99 // ISODateTime type. The function returns true if it succeeds, and 100 // false if it fails. 101 102 // For Month type. Updates m_year and m_month. 103 bool setMillisecondsSinceEpochForMonth(double ms); 104 // FIXME: Add setMillisecondsSinceEpochFor*() for other types. 90 105 91 106 // Returns the number of milliseconds from 1970-01-01 00:00:00 UTC. … … 105 120 // Helper for millisecondsSinceEpoch(). 106 121 double millisecondsSinceEpochForTime() const; 122 // Helper for setMillisecondsSinceEpochFor*(). 123 bool setMillisecondsSinceEpochForDateInternal(double ms); 107 124 108 125 // m_weekDay values
Note: See TracChangeset
for help on using the changeset viewer.