Changeset 44929 in webkit


Ignore:
Timestamp:
Jun 21, 2009 10:08:10 PM (15 years ago)
Author:
oliver@apple.com
Message:

Bug 26594: JSC needs to support Date.toISOString
<https://bugs.webkit.org/show_bug.cgi?id=26594>

Reviewed by Sam Weinig

Add support for Date.toISOString.

Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r44924 r44929  
     12009-06-21  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Bug 26594: JSC needs to support Date.toISOString
     6        <https://bugs.webkit.org/show_bug.cgi?id=26594>
     7
     8        Add support for Date.toISOString.
     9
     10        * runtime/DatePrototype.cpp:
     11        (JSC::dateProtoFuncToISOString):
     12
    1132009-06-21  Oliver Hunt  <oliver@apple.com>
    214
  • trunk/JavaScriptCore/runtime/DatePrototype.cpp

    r44866 r44929  
    114114static JSValue JSC_HOST_CALL dateProtoFuncToTimeString(ExecState*, JSObject*, JSValue, const ArgList&);
    115115static JSValue JSC_HOST_CALL dateProtoFuncToUTCString(ExecState*, JSObject*, JSValue, const ArgList&);
     116static JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState*, JSObject*, JSValue, const ArgList&);
    116117
    117118}
     
    343344@begin dateTable
    344345  toString              dateProtoFuncToString                DontEnum|Function       0
     346  toISOString           dateProtoFuncToISOString             DontEnum|Function       0
    345347  toUTCString           dateProtoFuncToUTCString             DontEnum|Function       0
    346348  toDateString          dateProtoFuncToDateString            DontEnum|Function       0
     
    439441}
    440442
     443JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
     444{
     445    if (!thisValue.isObject(&DateInstance::info))
     446        return throwError(exec, TypeError);
     447   
     448    const bool utc = true;
     449   
     450    DateInstance* thisDateObj = asDateInstance(thisValue);
     451    double milli = thisDateObj->internalNumber();
     452    if (!isfinite(milli))
     453        return jsNontrivialString(exec, "Invalid Date");
     454   
     455    GregorianDateTime t;
     456    thisDateObj->msToGregorianDateTime(milli, utc, t);
     457    // Maximum amount of space we need in buffer: 6 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second)
     458    // 6 for formatting and one for null termination = 23.  We add one extra character to allow us to force null termination.
     459    char buffer[24];
     460    snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02dZ", 1900 + t.year, t.month + 1, t.monthDay, t.hour, t.minute, t.second);
     461    buffer[sizeof(buffer) - 1] = 0;
     462    return jsNontrivialString(exec, buffer);
     463}
     464
    441465JSValue JSC_HOST_CALL dateProtoFuncToDateString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
    442466{
  • trunk/LayoutTests/ChangeLog

    r44928 r44929  
     12009-06-21  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Bug 26594: JSC needs to support Date.toISOString
     6        <https://bugs.webkit.org/show_bug.cgi?id=26594>
     7
     8        A few basic correctness tests for Date.toISOString.
     9
     10        * fast/js/date-toisostring-expected.txt: Added.
     11        * fast/js/date-toisostring.html: Added.
     12        * fast/js/resources/date-toisostring.js: Added.
     13
    1142009-06-21  Sam Weinig  <sam@webkit.org>
    215
Note: See TracChangeset for help on using the changeset viewer.