`Date.UTC()` with fewer than two arguments

RESOLVED FIXED in Firefox 54

Status

()

Core
JavaScript Engine
RESOLVED FIXED
3 years ago
20 days ago

People

(Reporter: Mathias Bynens, Assigned: André Bargull)

Tracking

(Blocks: 1 bug, {dev-doc-complete})

unspecified
mozilla54
x86
Mac OS X
dev-doc-complete
Points:
---

Firefox Tracking Flags

(firefox54 fixed)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Reporter)

Description

3 years ago
The behavior for `Date.UTC()` is undefined even in the ES6 draft spec. But it would be good to align with other implementations.

Results for:

    [ Date.UTC(), Date.UTC(1) ]

Safari/JavaScriptCore: [ NaN, NaN ]
Chrome/Opera/V8: [ NaN, NaN ]
Safari/JavaScriptCore: [ NaN, NaN ]
Old Opera/Carakan: [ NaN, NaN ]

Only Firefox and IE11 return a non-`NaN` value: [ -2208988800000, -2177452800000 ]

Consider returning `NaN` in such cases to match the majority of other engines.
(Reporter)

Updated

3 years ago
This is why a spec is needed.

Date.UTC(0) returns the same thing as Date.UTC(undefined) and Date.UTC() in at least Firefox and Chrome.  So this is not just about missing arguments; it's about different behavior after you coerce the argument to a number.

So what is the actual behavior you're asking us to implement?
Flags: needinfo?(mathias)
Oh, I see, fewer than two arguments, ok.
Flags: needinfo?(mathias)
(Reporter)

Comment 3

3 years ago
(In reply to Boris from comment #1)
> So what is the actual behavior you're asking us to implement?

(In reply to Boris from comment #2)
> Oh, I see, fewer than two arguments, ok.

I don’t actually have a preference – I’d just like all implementations to align. The simplest way to make that happen is to convince Firefox/SpiderMonkey and IE/Chakra to return `NaN` for `Date.UTC` calls with fewer than two arguments, but if everyone else is willing to change, that’s fine too.

The spec bug is here, in case you have a strong opinion: https://bugs.ecmascript.org/show_bug.cgi?id=3112

Comment 4

3 months ago
This is now specced, and we should update our implementation: https://tc39.github.io/ecma262/#sec-date.utc
(Assignee)

Updated

2 months ago
Blocks: 652780
(Assignee)

Updated

2 months ago
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
(Assignee)

Updated

2 months ago
(Assignee)

Comment 5

2 months ago
Created attachment 8837575 [details] [diff] [review]
bug1050755.patch

This is covered by test262, so I didn't need to write new tests. \o/

I'll update the patch to use the correct git hash as soon as https://github.com/tc39/ecma262/pull/642 is merged.
Attachment #8837575 - Flags: review?(shu)

Comment 6

2 months ago
Comment on attachment 8837575 [details] [diff] [review]
bug1050755.patch

Review of attachment 8837575 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks for the patch.
Attachment #8837575 - Flags: review?(shu) → review+
The pull request has been merged.
(Assignee)

Comment 8

2 months ago
Created attachment 8841722 [details] [diff] [review]
bug1050755.patch

Updated patch to apply cleanly on inbound, no functional changes. Carrying r+ from shu.
Attachment #8837575 - Attachment is obsolete: true
Attachment #8841722 - Flags: review+
(Assignee)

Comment 9

2 months ago
(In reply to Tom Schuster [:evilpie] from comment #7)
> The pull request has been merged.

Thanks for pinging bterlson to merge the PR!
(Assignee)

Comment 10

2 months ago
Try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=98e20233106bdb669ea02ca4cf6745faa48c6e94
Keywords: checkin-needed
Keywords: dev-doc-needed

Comment 11

2 months ago
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/4db4dc2a4620
Allow to call Date.UTC with fewer than two arguments per ES2017. r=shu
Keywords: checkin-needed

Comment 12

2 months ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/4db4dc2a4620
Status: ASSIGNED → RESOLVED
Last Resolved: 2 months ago
status-firefox54: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
https://developer.mozilla.org/en-US/Firefox/Releases/54#JavaScript
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC#Compatibility_notes
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.