Diff
Modified: trunk/LayoutTests/ChangeLog (195380 => 195381)
--- trunk/LayoutTests/ChangeLog 2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/LayoutTests/ChangeLog 2016-01-20 22:49:32 UTC (rev 195381)
@@ -1,3 +1,15 @@
+2016-01-20 Andy VanWagoner <thetalecraf...@gmail.com>
+
+ [INTL] Implement Date.prototype.toLocaleTimeString in ECMA-402
+ https://bugs.webkit.org/show_bug.cgi?id=147613
+
+ Reviewed by Darin Adler.
+
+ Added tests for toLocaleTimeString.
+
+ * js/date-toLocaleString-expected.txt:
+ * js/script-tests/date-toLocaleString.js:
+
2016-01-20 Brady Eidson <beid...@apple.com>
Modern IDB: Make storage/indexeddb/modern tests more modern.
Modified: trunk/LayoutTests/js/date-toLocaleString-expected.txt (195380 => 195381)
--- trunk/LayoutTests/js/date-toLocaleString-expected.txt 2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/LayoutTests/js/date-toLocaleString-expected.txt 2016-01-20 22:49:32 UTC (rev 195381)
@@ -49,6 +49,29 @@
PASS new Date(0).toLocaleDateString('en', null) threw exception TypeError: null is not an object.
PASS new Date(0).toLocaleDateString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' }) is "1/1/1970, 12:00 AM"
PASS new Date(0).toLocaleDateString('en', { timeZone: 'UTC', year:'numeric', month:'long' }) is "January 1970"
+PASS Date.prototype.toLocaleTimeString.length is 0
+PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').enumerable is false
+PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').configurable is true
+PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').writable is true
+PASS Date.prototype.toLocaleTimeString.call(new Date) did not throw exception.
+PASS Date.prototype.toLocaleTimeString.call() threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call(undefined) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call(null) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call(0) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call(NaN) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call(Infinity) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call('1') threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call({}) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call([]) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleTimeString.call(Symbol()) threw exception TypeError: Type error.
+PASS typeof new Date().toLocaleTimeString() === 'string' is true
+PASS new Date(NaN).toLocaleTimeString() is "Invalid Date"
+PASS new Date().toLocaleTimeString('i') threw exception RangeError: invalid language tag: i.
+PASS new Date(0).toLocaleTimeString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' }) is "上午一二:〇〇:〇〇"
+PASS new Date(0).toLocaleTimeString('en', { timeZone: 'UTC' }) is "12:00:00 AM"
+PASS new Date(0).toLocaleTimeString('en', null) threw exception TypeError: null is not an object.
+PASS new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' }) is "12:00 AM"
+PASS new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', year:'numeric', month:'long' }) is "January 1970, 12:00:00 AM"
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/js/script-tests/date-toLocaleString.js (195380 => 195381)
--- trunk/LayoutTests/js/script-tests/date-toLocaleString.js 2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/LayoutTests/js/script-tests/date-toLocaleString.js 2016-01-20 22:49:32 UTC (rev 195381)
@@ -72,3 +72,41 @@
shouldBeEqualToString("new Date(0).toLocaleDateString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' })", "1/1/1970, 12:00 AM");
// If any date formats specified, just use them.
shouldBeEqualToString("new Date(0).toLocaleDateString('en', { timeZone: 'UTC', year:'numeric', month:'long' })", "January 1970");
+
+// Test toLocaleTimeString ()
+shouldBe("Date.prototype.toLocaleTimeString.length", "0");
+shouldBeFalse("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').enumerable");
+shouldBeTrue("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').configurable");
+shouldBeTrue("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').writable");
+
+// Test thisTimeValue abrupt completion.
+shouldNotThrow("Date.prototype.toLocaleTimeString.call(new Date)");
+shouldThrow("Date.prototype.toLocaleTimeString.call()");
+shouldThrow("Date.prototype.toLocaleTimeString.call(undefined)");
+shouldThrow("Date.prototype.toLocaleTimeString.call(null)");
+shouldThrow("Date.prototype.toLocaleTimeString.call(0)");
+shouldThrow("Date.prototype.toLocaleTimeString.call(NaN)");
+shouldThrow("Date.prototype.toLocaleTimeString.call(Infinity)");
+shouldThrow("Date.prototype.toLocaleTimeString.call('1')");
+shouldThrow("Date.prototype.toLocaleTimeString.call({})");
+shouldThrow("Date.prototype.toLocaleTimeString.call([])");
+shouldThrow("Date.prototype.toLocaleTimeString.call(Symbol())");
+
+shouldBeTrue("typeof new Date().toLocaleTimeString() === 'string'");
+
+shouldBeEqualToString("new Date(NaN).toLocaleTimeString()", "Invalid Date");
+
+// Test for DateTimeFormat behavior.
+// Test that locale parameter is passed through properly.
+shouldThrow("new Date().toLocaleTimeString('i')");
+shouldBeEqualToString("new Date(0).toLocaleTimeString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' })", "上午一二:〇〇:〇〇");
+
+// Defaults to hms
+shouldBeEqualToString("new Date(0).toLocaleTimeString('en', { timeZone: 'UTC' })", "12:00:00 AM");
+
+// Test that options parameter is passed through properly.
+shouldThrow("new Date(0).toLocaleTimeString('en', null)", "'TypeError: null is not an object'");
+// If time formats specifed, just use them.
+shouldBeEqualToString("new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' })", "12:00 AM");
+// Adds hms if no time formats specified.
+shouldBeEqualToString("new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', year:'numeric', month:'long' })", "January 1970, 12:00:00 AM");
Modified: trunk/Source/_javascript_Core/ChangeLog (195380 => 195381)
--- trunk/Source/_javascript_Core/ChangeLog 2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-01-20 22:49:32 UTC (rev 195381)
@@ -1,3 +1,18 @@
+2016-01-20 Andy VanWagoner <thetalecraf...@gmail.com>
+
+ [INTL] Implement Date.prototype.toLocaleTimeString in ECMA-402
+ https://bugs.webkit.org/show_bug.cgi?id=147613
+
+ Reviewed by Darin Adler.
+
+ Implement toLocaleTimeString in builtin _javascript_.
+
+ * builtins/DatePrototype.js:
+ (toLocaleTimeString.toDateTimeOptionsTimeTime):
+ (toLocaleTimeString):
+ * runtime/DatePrototype.cpp:
+ (JSC::DatePrototype::finishCreation):
+
2016-01-20 Saam barati <sbar...@apple.com>
Web Inspector: Hook the sampling profiler into the Timelines UI
Modified: trunk/Source/_javascript_Core/builtins/DatePrototype.js (195380 => 195381)
--- trunk/Source/_javascript_Core/builtins/DatePrototype.js 2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/Source/_javascript_Core/builtins/DatePrototype.js 2016-01-20 22:49:32 UTC (rev 195381)
@@ -131,3 +131,52 @@
var dateFormat = new @DateTimeFormat(locales, options);
return dateFormat.format(value);
}
+
+function toLocaleTimeString(/* locales, options */)
+{
+ "use strict";
+
+ function toDateTimeOptionsTimeTime(opts)
+ {
+ // ToDateTimeOptions(options, "time", "time")
+ // http://www.ecma-international.org/ecma-402/2.0/#sec-InitializeDateTimeFormat
+
+ var options;
+ if (opts === undefined)
+ options = null;
+ else if (opts === null)
+ throw new @TypeError("null is not an object");
+ else
+ options = @Object(opts);
+
+ // Check original instead of descendant to reduce lookups up the prototype chain.
+ var needsDefaults = !options || (
+ options.hour === undefined &&
+ options.minute === undefined &&
+ options.second === undefined
+ );
+
+ // Only create descendant if it will have own properties.
+ if (needsDefaults) {
+ options = @Object.create(options)
+ options.hour = "numeric";
+ options.minute = "numeric";
+ options.second = "numeric";
+ }
+
+ return options;
+ }
+
+ // 13.3.3 Date.prototype.toLocaleTimeString ([locales [, options ]]) (ECMA-402 2.0)
+ // http://www.ecma-international.org/ecma-402/2.0/#sec-Date.prototype.toLocaleTimeString
+
+ var value = @thisTimeValue.@call(this);
+ if (@isNaN(value))
+ return "Invalid Date";
+
+ var options = toDateTimeOptionsTimeTime(arguments[1]);
+ var locales = arguments[0];
+
+ var dateFormat = new @DateTimeFormat(locales, options);
+ return dateFormat.format(value);
+}
Modified: trunk/Source/_javascript_Core/runtime/DatePrototype.cpp (195380 => 195381)
--- trunk/Source/_javascript_Core/runtime/DatePrototype.cpp 2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/Source/_javascript_Core/runtime/DatePrototype.cpp 2016-01-20 22:49:32 UTC (rev 195381)
@@ -494,6 +494,7 @@
#if ENABLE(INTL)
JSC_BUILTIN_FUNCTION("toLocaleString", datePrototypeToLocaleStringCodeGenerator, DontEnum);
JSC_BUILTIN_FUNCTION("toLocaleDateString", datePrototypeToLocaleDateStringCodeGenerator, DontEnum);
+ JSC_BUILTIN_FUNCTION("toLocaleTimeString", datePrototypeToLocaleTimeStringCodeGenerator, DontEnum);
#else
UNUSED_PARAM(globalObject);
#endif // ENABLE(INTL)