<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[195381] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/195381">195381</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-01-20 14:49:32 -0800 (Wed, 20 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[INTL] Implement Date.prototype.toLocaleTimeString in ECMA-402
https://bugs.webkit.org/show_bug.cgi?id=147613

Patch by Andy VanWagoner &lt;thetalecrafter@gmail.com&gt; on 2016-01-20
Reviewed by Darin Adler.

Source/JavaScriptCore:

Implement toLocaleTimeString in builtin JavaScript.

* builtins/DatePrototype.js:
(toLocaleTimeString.toDateTimeOptionsTimeTime):
(toLocaleTimeString):
* runtime/DatePrototype.cpp:
(JSC::DatePrototype::finishCreation):

LayoutTests:

Added tests for toLocaleTimeString.

* js/date-toLocaleString-expected.txt:
* js/script-tests/date-toLocaleString.js:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsjsdatetoLocaleStringexpectedtxt">trunk/LayoutTests/js/date-toLocaleString-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsdatetoLocaleStringjs">trunk/LayoutTests/js/script-tests/date-toLocaleString.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebuiltinsDatePrototypejs">trunk/Source/JavaScriptCore/builtins/DatePrototype.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeDatePrototypecpp">trunk/Source/JavaScriptCore/runtime/DatePrototype.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (195380 => 195381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/LayoutTests/ChangeLog        2016-01-20 22:49:32 UTC (rev 195381)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-01-20  Andy VanWagoner  &lt;thetalecrafter@gmail.com&gt;
+
+        [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:
+
</ins><span class="cx"> 2016-01-20  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Modern IDB: Make storage/indexeddb/modern tests more modern.
</span></span></pre></div>
<a id="trunkLayoutTestsjsdatetoLocaleStringexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/date-toLocaleString-expected.txt (195380 => 195381)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -49,6 +49,29 @@
</span><span class="cx"> PASS new Date(0).toLocaleDateString('en', null) threw exception TypeError: null is not an object.
</span><span class="cx"> PASS new Date(0).toLocaleDateString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' }) is &quot;1/1/1970, 12:00 AM&quot;
</span><span class="cx"> PASS new Date(0).toLocaleDateString('en', { timeZone: 'UTC', year:'numeric', month:'long' }) is &quot;January 1970&quot;
</span><ins>+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 &quot;Invalid Date&quot;
+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 &quot;上午一二:〇〇:〇〇&quot;
+PASS new Date(0).toLocaleTimeString('en', { timeZone: 'UTC' }) is &quot;12:00:00 AM&quot;
+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 &quot;12:00 AM&quot;
+PASS new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', year:'numeric', month:'long' }) is &quot;January 1970, 12:00:00 AM&quot;
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsdatetoLocaleStringjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/date-toLocaleString.js (195380 => 195381)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -72,3 +72,41 @@
</span><span class="cx"> shouldBeEqualToString(&quot;new Date(0).toLocaleDateString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' })&quot;, &quot;1/1/1970, 12:00 AM&quot;);
</span><span class="cx"> // If any date formats specified, just use them.
</span><span class="cx"> shouldBeEqualToString(&quot;new Date(0).toLocaleDateString('en', { timeZone: 'UTC', year:'numeric', month:'long' })&quot;, &quot;January 1970&quot;);
</span><ins>+
+// Test toLocaleTimeString ()
+shouldBe(&quot;Date.prototype.toLocaleTimeString.length&quot;, &quot;0&quot;);
+shouldBeFalse(&quot;Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').enumerable&quot;);
+shouldBeTrue(&quot;Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').configurable&quot;);
+shouldBeTrue(&quot;Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').writable&quot;);
+
+// Test thisTimeValue abrupt completion.
+shouldNotThrow(&quot;Date.prototype.toLocaleTimeString.call(new Date)&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call()&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call(undefined)&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call(null)&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call(0)&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call(NaN)&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call(Infinity)&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call('1')&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call({})&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call([])&quot;);
+shouldThrow(&quot;Date.prototype.toLocaleTimeString.call(Symbol())&quot;);
+
+shouldBeTrue(&quot;typeof new Date().toLocaleTimeString() === 'string'&quot;);
+
+shouldBeEqualToString(&quot;new Date(NaN).toLocaleTimeString()&quot;, &quot;Invalid Date&quot;);
+
+// Test for DateTimeFormat behavior.
+// Test that locale parameter is passed through properly.
+shouldThrow(&quot;new Date().toLocaleTimeString('i')&quot;);
+shouldBeEqualToString(&quot;new Date(0).toLocaleTimeString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' })&quot;, &quot;上午一二:〇〇:〇〇&quot;);
+
+// Defaults to hms
+shouldBeEqualToString(&quot;new Date(0).toLocaleTimeString('en', { timeZone: 'UTC' })&quot;, &quot;12:00:00 AM&quot;);
+
+// Test that options parameter is passed through properly.
+shouldThrow(&quot;new Date(0).toLocaleTimeString('en', null)&quot;, &quot;'TypeError: null is not an object'&quot;);
+// If time formats specifed, just use them.
+shouldBeEqualToString(&quot;new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' })&quot;, &quot;12:00 AM&quot;);
+// Adds hms if no time formats specified.
+shouldBeEqualToString(&quot;new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', year:'numeric', month:'long' })&quot;, &quot;January 1970, 12:00:00 AM&quot;);
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (195380 => 195381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-01-20 22:49:32 UTC (rev 195381)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2016-01-20  Andy VanWagoner  &lt;thetalecrafter@gmail.com&gt;
+
+        [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):
+
</ins><span class="cx"> 2016-01-20  Saam barati  &lt;sbarati@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Hook the sampling profiler into the Timelines UI
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsDatePrototypejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/builtins/DatePrototype.js (195380 => 195381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/DatePrototype.js        2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/Source/JavaScriptCore/builtins/DatePrototype.js        2016-01-20 22:49:32 UTC (rev 195381)
</span><span class="lines">@@ -131,3 +131,52 @@
</span><span class="cx">     var dateFormat = new @DateTimeFormat(locales, options);
</span><span class="cx">     return dateFormat.format(value);
</span><span class="cx"> }
</span><ins>+
+function toLocaleTimeString(/* locales, options */)
+{
+    &quot;use strict&quot;;
+
+    function toDateTimeOptionsTimeTime(opts)
+    {
+        // ToDateTimeOptions(options, &quot;time&quot;, &quot;time&quot;)
+        // 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(&quot;null is not an object&quot;);
+        else
+            options = @Object(opts);
+
+        // Check original instead of descendant to reduce lookups up the prototype chain.
+        var needsDefaults = !options || (
+            options.hour === undefined &amp;&amp;
+            options.minute === undefined &amp;&amp;
+            options.second === undefined
+        );
+
+        // Only create descendant if it will have own properties.
+        if (needsDefaults) {
+            options = @Object.create(options)
+            options.hour = &quot;numeric&quot;;
+            options.minute = &quot;numeric&quot;;
+            options.second = &quot;numeric&quot;;
+        }
+
+        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 &quot;Invalid Date&quot;;
+
+    var options = toDateTimeOptionsTimeTime(arguments[1]);
+    var locales = arguments[0];
+
+    var dateFormat = new @DateTimeFormat(locales, options);
+    return dateFormat.format(value);
+}
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeDatePrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/DatePrototype.cpp (195380 => 195381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/DatePrototype.cpp        2016-01-20 22:27:08 UTC (rev 195380)
+++ trunk/Source/JavaScriptCore/runtime/DatePrototype.cpp        2016-01-20 22:49:32 UTC (rev 195381)
</span><span class="lines">@@ -494,6 +494,7 @@
</span><span class="cx"> #if ENABLE(INTL)
</span><span class="cx">     JSC_BUILTIN_FUNCTION(&quot;toLocaleString&quot;, datePrototypeToLocaleStringCodeGenerator, DontEnum);
</span><span class="cx">     JSC_BUILTIN_FUNCTION(&quot;toLocaleDateString&quot;, datePrototypeToLocaleDateStringCodeGenerator, DontEnum);
</span><ins>+    JSC_BUILTIN_FUNCTION(&quot;toLocaleTimeString&quot;, datePrototypeToLocaleTimeStringCodeGenerator, DontEnum);
</ins><span class="cx"> #else
</span><span class="cx">     UNUSED_PARAM(globalObject);
</span><span class="cx"> #endif // ENABLE(INTL)
</span></span></pre>
</div>
</div>

</body>
</html>