diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog index 316488e749ef2292b5b5b8a4087ec0c7d5d9d2a5..4341655c791f875fa42629fbe345f2ae06fbae3f 100644 --- a/JavaScriptCore/ChangeLog +++ b/JavaScriptCore/ChangeLog @@ -1,3 +1,15 @@ +2009-06-21 Oliver Hunt + + Reviewed by Sam Weinig. + + Bug 26594: JSC needs to support Date.toISOString + + + Add support for Date.toISOString. + + * runtime/DatePrototype.cpp: + (JSC::dateProtoFuncToISOString): + 2009-06-21 Oliver Hunt Reviewed by NOBODY (Build fix). diff --git a/JavaScriptCore/runtime/DatePrototype.cpp b/JavaScriptCore/runtime/DatePrototype.cpp index 7b159a0ecc439aac476223b7c55a776259383706..098379cbe0c30924e68c015d610bedfa9c636af3 100644 --- a/JavaScriptCore/runtime/DatePrototype.cpp +++ b/JavaScriptCore/runtime/DatePrototype.cpp @@ -113,6 +113,7 @@ static JSValue JSC_HOST_CALL dateProtoFuncToLocaleTimeString(ExecState*, JSObjec static JSValue JSC_HOST_CALL dateProtoFuncToString(ExecState*, JSObject*, JSValue, const ArgList&); static JSValue JSC_HOST_CALL dateProtoFuncToTimeString(ExecState*, JSObject*, JSValue, const ArgList&); static JSValue JSC_HOST_CALL dateProtoFuncToUTCString(ExecState*, JSObject*, JSValue, const ArgList&); +static JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState*, JSObject*, JSValue, const ArgList&); } @@ -342,6 +343,7 @@ const ClassInfo DatePrototype::info = {"Date", &DateInstance::info, 0, ExecState /* Source for DatePrototype.lut.h @begin dateTable toString dateProtoFuncToString DontEnum|Function 0 + toISOString dateProtoFuncToISOString DontEnum|Function 0 toUTCString dateProtoFuncToUTCString DontEnum|Function 0 toDateString dateProtoFuncToDateString DontEnum|Function 0 toTimeString dateProtoFuncToTimeString DontEnum|Function 0 @@ -438,6 +440,28 @@ JSValue JSC_HOST_CALL dateProtoFuncToUTCString(ExecState* exec, JSObject*, JSVal return jsNontrivialString(exec, formatDateUTCVariant(t) + " " + formatTime(t, utc)); } +JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) +{ + if (!thisValue.isObject(&DateInstance::info)) + return throwError(exec, TypeError); + + const bool utc = true; + + DateInstance* thisDateObj = asDateInstance(thisValue); + double milli = thisDateObj->internalNumber(); + if (!isfinite(milli)) + return jsNontrivialString(exec, "Invalid Date"); + + GregorianDateTime t; + thisDateObj->msToGregorianDateTime(milli, utc, t); + // Maximum amount of space we need in buffer: 6 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second) + // 6 for formatting and one for null termination = 23. We add one extra character to allow us to force null termination. + char buffer[24]; + 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); + buffer[sizeof(buffer) - 1] = 0; + return jsNontrivialString(exec, buffer); +} + JSValue JSC_HOST_CALL dateProtoFuncToDateString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) { if (!thisValue.isObject(&DateInstance::info)) diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 33615c289cba8ee9078ecaeb5f86e4bcde2f8d06..416f9492ee6745ed94b712292323da442b2d6b4f 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,16 @@ +2009-06-21 Oliver Hunt + + Reviewed by Sam Weinig. + + Bug 26594: JSC needs to support Date.toISOString + + + A few basic correctness tests for Date.toISOString. + + * fast/js/date-toisostring-expected.txt: Added. + * fast/js/date-toisostring.html: Added. + * fast/js/resources/date-toisostring.js: Added. + 2009-06-21 Sam Weinig Reviewed by Oliver Hunt. diff --git a/LayoutTests/fast/js/date-toisostring-expected.txt b/LayoutTests/fast/js/date-toisostring-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e8abd775b79bf2a2e623c0e876e2330c4d74686 --- /dev/null +++ b/LayoutTests/fast/js/date-toisostring-expected.txt @@ -0,0 +1,18 @@ +Tests for Date.toISOString + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS Date.toISOString.call({}) threw exception TypeError: Result of expression 'Date.toISOString' [undefined] is not an object.. +PASS Date.toISOString.call(0) threw exception TypeError: Result of expression 'Date.toISOString' [undefined] is not an object.. +PASS new Date(0).toISOString() is '1970-01-01T00:00:00Z' +PASS new Date('1 January 1500 UTC').toISOString() is '1500-01-01T00:00:00Z' +PASS new Date('1 January 2000 UTC').toISOString() is '2000-01-01T00:00:00Z' +PASS new Date('1 January 4000 UTC').toISOString() is '4000-01-01T00:00:00Z' +PASS new Date('1 January 100000 UTC').toISOString() is '100000-01-01T00:00:00Z' +PASS new Date('10 March 2000 UTC').toISOString() is '2000-03-10T00:00:00Z' +PASS new Date(NaN).toISOString() is 'Invalid Date' +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/js/date-toisostring.html b/LayoutTests/fast/js/date-toisostring.html new file mode 100644 index 0000000000000000000000000000000000000000..404ee18e47b4532a2c6837cd88ce441c0da7f006 --- /dev/null +++ b/LayoutTests/fast/js/date-toisostring.html @@ -0,0 +1,13 @@ + + + + + + + +

+
+ + + + diff --git a/LayoutTests/fast/js/resources/date-toisostring.js b/LayoutTests/fast/js/resources/date-toisostring.js new file mode 100644 index 0000000000000000000000000000000000000000..6166f2526ddfe93fcb8f3e4d7caf8054a1006af2 --- /dev/null +++ b/LayoutTests/fast/js/resources/date-toisostring.js @@ -0,0 +1,14 @@ +description("Tests for Date.toISOString"); + +shouldThrow("Date.toISOString.call({})"); +shouldThrow("Date.toISOString.call(0)"); + +shouldBe("new Date(0).toISOString()", "'1970-01-01T00:00:00Z'"); +shouldBe("new Date('1 January 1500 UTC').toISOString()", "'1500-01-01T00:00:00Z'"); +shouldBe("new Date('1 January 2000 UTC').toISOString()", "'2000-01-01T00:00:00Z'"); +shouldBe("new Date('1 January 4000 UTC').toISOString()", "'4000-01-01T00:00:00Z'"); +shouldBe("new Date('1 January 100000 UTC').toISOString()", "'100000-01-01T00:00:00Z'"); +shouldBe("new Date('10 March 2000 UTC').toISOString()", "'2000-03-10T00:00:00Z'"); +shouldBe("new Date(NaN).toISOString()", "'Invalid Date'"); + +successfullyParsed = true;