Specify Date.UTC when called with fewer than two arguments#642
Specify Date.UTC when called with fewer than two arguments#642bterlson merged 2 commits intotc39:masterfrom
Conversation
|
Followup of whatwg/javascript#31 |
|
See also: chakra-core/ChakraCore#1318, whatwg/javascript#31. |
|
Note that, according to the proposed semantics, when Date.UTC is called with 1 argument, step 1 may have side-effects, although the final result will always be either NaN or an abrupt completion: Date.UTC({ valueOf: function() { throw "hey!" } })(Firefox, Chrome and Safari throw "hey!" in that testcase.) |
|
@claudepache Thanks for pointing that test case out. Edge also throws "hey!" in that case. |
|
Consensus is Date.UTC() returns NaN and Date.UTC(2017) === Date.UTC(2017, 0). This PR needs a slight update for this. |
| @@ -25643,7 +25643,7 @@ <h1>Date.prototype</h1> | |||
| <!-- es6num="20.3.3.4" --> | |||
| <emu-clause id="sec-date.utc"> | |||
| <h1>Date.UTC ( _year_, _month_ [ , _date_ [ , _hours_ [ , _minutes_ [ , _seconds_ [ , _ms_ ] ] ] ] ] )</h1> | |||
According to TC39 consensus at 9/2016 meeting
|
I've updated the PR. |
| <emu-alg> | ||
| 1. Let _y_ be ? ToNumber(_year_). | ||
| 1. Let _m_ be ? ToNumber(_month_). | ||
| 1. If _month_ is supplied, let _m_ be ? ToNumber(_month_); else let _m_ be 0. |
There was a problem hiding this comment.
@bterlson I just want to confirm this for clarification: we'll have a different behavior for supplied but undefined month. Like the following expected values:
Date.UTC(2016) // 1451606400000
Date.UTC(2016, 0) // 1451606400000
Date.UTC(2016, undefined) // NaNThis will be consistent with the other parameters, but Date.UTC will never be perfect.
There was a problem hiding this comment.
This is also consistent with the Date constructor:
new Date(2016, 0) // Fri Jan 01 2016 00:00:00 GMT+0100 (CET)
new Date(2016, undefined) // Invalid DateThere was a problem hiding this comment.
Yeah, this is just how it is :-P
|
Is this patch ready to land? Should it go in ES2017? Seems all good to me. |
After tc39/ecma262#642, Date.UTC no longer requires the month argument to be specified. The spec provides 0 as its default value. This CL updates the builtins-date.cc code to reflect that and drops the test suppression for test262/built-ins/Date/UTC/return-value. BUG=v8:5534 Review-Url: https://codereview.chromium.org/2689173003 Cr-Commit-Position: refs/heads/master@{#43193}
|
@claudepache @bterlson can we land this? |
|
@evilpie yep seems good to me. @littledan unless you object I was planning on bringing this to the es2017 branch since we have consensus on the semantics from a long while back. |
|
Also merged into es2017. |
No description provided.