Commit 09f8e91e authored by oliver@apple.com's avatar oliver@apple.com

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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44929 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5f4ed313
2009-06-21 Oliver Hunt <oliver@apple.com>
Reviewed by Sam Weinig.
Bug 26594: JSC needs to support Date.toISOString
<https://bugs.webkit.org/show_bug.cgi?id=26594>
Add support for Date.toISOString.
* runtime/DatePrototype.cpp:
(JSC::dateProtoFuncToISOString):
2009-06-21 Oliver Hunt <oliver@apple.com>
Reviewed by NOBODY (Build fix).
......
......@@ -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))
......
2009-06-21 Oliver Hunt <oliver@apple.com>
Reviewed by Sam Weinig.
Bug 26594: JSC needs to support Date.toISOString
<https://bugs.webkit.org/show_bug.cgi?id=26594>
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 <sam@webkit.org>
Reviewed by Oliver Hunt.
......
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
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="resources/js-test-style.css">
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="resources/date-toisostring.js"></script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
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;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment