Changeset 195381 in webkit
- Timestamp:
- Jan 20, 2016 2:49:32 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r195380 r195381 1 2016-01-20 Andy VanWagoner <thetalecrafter@gmail.com> 2 3 [INTL] Implement Date.prototype.toLocaleTimeString in ECMA-402 4 https://bugs.webkit.org/show_bug.cgi?id=147613 5 6 Reviewed by Darin Adler. 7 8 Added tests for toLocaleTimeString. 9 10 * js/date-toLocaleString-expected.txt: 11 * js/script-tests/date-toLocaleString.js: 12 1 13 2016-01-20 Brady Eidson <beidson@apple.com> 2 14 -
trunk/LayoutTests/js/date-toLocaleString-expected.txt
r195330 r195381 50 50 PASS new Date(0).toLocaleDateString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' }) is "1/1/1970, 12:00 AM" 51 51 PASS new Date(0).toLocaleDateString('en', { timeZone: 'UTC', year:'numeric', month:'long' }) is "January 1970" 52 PASS Date.prototype.toLocaleTimeString.length is 0 53 PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').enumerable is false 54 PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').configurable is true 55 PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').writable is true 56 PASS Date.prototype.toLocaleTimeString.call(new Date) did not throw exception. 57 PASS Date.prototype.toLocaleTimeString.call() threw exception TypeError: Type error. 58 PASS Date.prototype.toLocaleTimeString.call(undefined) threw exception TypeError: Type error. 59 PASS Date.prototype.toLocaleTimeString.call(null) threw exception TypeError: Type error. 60 PASS Date.prototype.toLocaleTimeString.call(0) threw exception TypeError: Type error. 61 PASS Date.prototype.toLocaleTimeString.call(NaN) threw exception TypeError: Type error. 62 PASS Date.prototype.toLocaleTimeString.call(Infinity) threw exception TypeError: Type error. 63 PASS Date.prototype.toLocaleTimeString.call('1') threw exception TypeError: Type error. 64 PASS Date.prototype.toLocaleTimeString.call({}) threw exception TypeError: Type error. 65 PASS Date.prototype.toLocaleTimeString.call([]) threw exception TypeError: Type error. 66 PASS Date.prototype.toLocaleTimeString.call(Symbol()) threw exception TypeError: Type error. 67 PASS typeof new Date().toLocaleTimeString() === 'string' is true 68 PASS new Date(NaN).toLocaleTimeString() is "Invalid Date" 69 PASS new Date().toLocaleTimeString('i') threw exception RangeError: invalid language tag: i. 70 PASS new Date(0).toLocaleTimeString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' }) is "上午一二:〇〇:〇〇" 71 PASS new Date(0).toLocaleTimeString('en', { timeZone: 'UTC' }) is "12:00:00 AM" 72 PASS new Date(0).toLocaleTimeString('en', null) threw exception TypeError: null is not an object. 73 PASS new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' }) is "12:00 AM" 74 PASS new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', year:'numeric', month:'long' }) is "January 1970, 12:00:00 AM" 52 75 PASS successfullyParsed is true 53 76 -
trunk/LayoutTests/js/script-tests/date-toLocaleString.js
r195330 r195381 73 73 // If any date formats specified, just use them. 74 74 shouldBeEqualToString("new Date(0).toLocaleDateString('en', { timeZone: 'UTC', year:'numeric', month:'long' })", "January 1970"); 75 76 // Test toLocaleTimeString () 77 shouldBe("Date.prototype.toLocaleTimeString.length", "0"); 78 shouldBeFalse("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').enumerable"); 79 shouldBeTrue("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').configurable"); 80 shouldBeTrue("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleTimeString').writable"); 81 82 // Test thisTimeValue abrupt completion. 83 shouldNotThrow("Date.prototype.toLocaleTimeString.call(new Date)"); 84 shouldThrow("Date.prototype.toLocaleTimeString.call()"); 85 shouldThrow("Date.prototype.toLocaleTimeString.call(undefined)"); 86 shouldThrow("Date.prototype.toLocaleTimeString.call(null)"); 87 shouldThrow("Date.prototype.toLocaleTimeString.call(0)"); 88 shouldThrow("Date.prototype.toLocaleTimeString.call(NaN)"); 89 shouldThrow("Date.prototype.toLocaleTimeString.call(Infinity)"); 90 shouldThrow("Date.prototype.toLocaleTimeString.call('1')"); 91 shouldThrow("Date.prototype.toLocaleTimeString.call({})"); 92 shouldThrow("Date.prototype.toLocaleTimeString.call([])"); 93 shouldThrow("Date.prototype.toLocaleTimeString.call(Symbol())"); 94 95 shouldBeTrue("typeof new Date().toLocaleTimeString() === 'string'"); 96 97 shouldBeEqualToString("new Date(NaN).toLocaleTimeString()", "Invalid Date"); 98 99 // Test for DateTimeFormat behavior. 100 // Test that locale parameter is passed through properly. 101 shouldThrow("new Date().toLocaleTimeString('i')"); 102 shouldBeEqualToString("new Date(0).toLocaleTimeString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' })", "上午一二:〇〇:〇〇"); 103 104 // Defaults to hms 105 shouldBeEqualToString("new Date(0).toLocaleTimeString('en', { timeZone: 'UTC' })", "12:00:00 AM"); 106 107 // Test that options parameter is passed through properly. 108 shouldThrow("new Date(0).toLocaleTimeString('en', null)", "'TypeError: null is not an object'"); 109 // If time formats specifed, just use them. 110 shouldBeEqualToString("new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' })", "12:00 AM"); 111 // Adds hms if no time formats specified. 112 shouldBeEqualToString("new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', year:'numeric', month:'long' })", "January 1970, 12:00:00 AM"); -
trunk/Source/JavaScriptCore/ChangeLog
r195376 r195381 1 2016-01-20 Andy VanWagoner <thetalecrafter@gmail.com> 2 3 [INTL] Implement Date.prototype.toLocaleTimeString in ECMA-402 4 https://bugs.webkit.org/show_bug.cgi?id=147613 5 6 Reviewed by Darin Adler. 7 8 Implement toLocaleTimeString in builtin JavaScript. 9 10 * builtins/DatePrototype.js: 11 (toLocaleTimeString.toDateTimeOptionsTimeTime): 12 (toLocaleTimeString): 13 * runtime/DatePrototype.cpp: 14 (JSC::DatePrototype::finishCreation): 15 1 16 2016-01-20 Saam barati <sbarati@apple.com> 2 17 -
trunk/Source/JavaScriptCore/builtins/DatePrototype.js
r195330 r195381 132 132 return dateFormat.format(value); 133 133 } 134 135 function toLocaleTimeString(/* locales, options */) 136 { 137 "use strict"; 138 139 function toDateTimeOptionsTimeTime(opts) 140 { 141 // ToDateTimeOptions(options, "time", "time") 142 // http://www.ecma-international.org/ecma-402/2.0/#sec-InitializeDateTimeFormat 143 144 var options; 145 if (opts === undefined) 146 options = null; 147 else if (opts === null) 148 throw new @TypeError("null is not an object"); 149 else 150 options = @Object(opts); 151 152 // Check original instead of descendant to reduce lookups up the prototype chain. 153 var needsDefaults = !options || ( 154 options.hour === undefined && 155 options.minute === undefined && 156 options.second === undefined 157 ); 158 159 // Only create descendant if it will have own properties. 160 if (needsDefaults) { 161 options = @Object.create(options) 162 options.hour = "numeric"; 163 options.minute = "numeric"; 164 options.second = "numeric"; 165 } 166 167 return options; 168 } 169 170 // 13.3.3 Date.prototype.toLocaleTimeString ([locales [, options ]]) (ECMA-402 2.0) 171 // http://www.ecma-international.org/ecma-402/2.0/#sec-Date.prototype.toLocaleTimeString 172 173 var value = @thisTimeValue.@call(this); 174 if (@isNaN(value)) 175 return "Invalid Date"; 176 177 var options = toDateTimeOptionsTimeTime(arguments[1]); 178 var locales = arguments[0]; 179 180 var dateFormat = new @DateTimeFormat(locales, options); 181 return dateFormat.format(value); 182 } -
trunk/Source/JavaScriptCore/runtime/DatePrototype.cpp
r195330 r195381 495 495 JSC_BUILTIN_FUNCTION("toLocaleString", datePrototypeToLocaleStringCodeGenerator, DontEnum); 496 496 JSC_BUILTIN_FUNCTION("toLocaleDateString", datePrototypeToLocaleDateStringCodeGenerator, DontEnum); 497 JSC_BUILTIN_FUNCTION("toLocaleTimeString", datePrototypeToLocaleTimeStringCodeGenerator, DontEnum); 497 498 #else 498 499 UNUSED_PARAM(globalObject);
Note: See TracChangeset
for help on using the changeset viewer.