ChakraCore icon indicating copy to clipboard operation
ChakraCore copied to clipboard

Date constructor with negative value argument

Open gfablima opened this issue 6 years ago • 7 comments

OS: Ubuntu 16.04 x86 chakra: 1.11.0.0-beta

Hi everyone,

I found an inconsistence on Date() with a negative value. I was looking on ES6 specification about this issue but I didn't found an answer, maybe the correct way is convert the -0 to +0 as V8 and SpiderMonkey do.

Steps to reproduce:

d = new Date(-0);
print(Object.is(d.getTime(), +0))

Actual results: false

Expected results: true

V8 and SpiderMonkey works as expected.

gfablima avatar Jul 10 '18 15:07 gfablima

I took a quick look at this. Relevant spec https://tc39.github.io/ecma262/#sec-date-value in particular point 4.(d) and then https://tc39.github.io/ecma262/#sec-timeclip

I believe that v8 and spidermonkey are correct and the fix would be to edit the date constructor here (after the if/else): https://github.com/Microsoft/ChakraCore/blob/d5479383f757b86676ef30ec50b1a8050d325e13/lib/Runtime/Library/JavascriptDate.cpp#L175-L183 To specifically check for -0 and convert to +0.

rhuanjl avatar Jul 10 '18 16:07 rhuanjl

Confirmed we're the only engine that diverges from spec here.

>eshost --tags jsvu -ise "Object.is(new Date(-0).getTime(), +0)"
## Source
print(Object.is(new Date(-0).getTime(), +0))

#### jsvu-ch
false

#### jsvu-jsc, jsvu-sm, jsvu-v8, jsvu-xs
true

dilijev avatar Jul 10 '18 22:07 dilijev

I believe TimeClip is new -- I added it in Intl.cpp for use in DateTimeFormat, but it looks like it should be moved to somewhere more common and used in regular date parsing too.

jackhorton avatar Jul 12 '18 17:07 jackhorton

cinfuzz

igor-simoes avatar Aug 08 '18 15:08 igor-simoes

Marking this as a good first issue, should be less than 10 lines of code to fix though will also needed a test case which will be at leats the same again.

My previous comment highlights where the code change is needed - though also should check if can share code with Intl.cpp per jack's comment.

rhuanjl avatar Apr 08 '20 22:04 rhuanjl

Can I work on this issue?

Nazeeh21 avatar Aug 30 '21 20:08 Nazeeh21

Can I work on this issue?

Go for it, Read all the previous comments for a starting point - also please check the contributing guidelines. Tag me if you have any questions and if/when you open a PR.

rhuanjl avatar Aug 31 '21 06:08 rhuanjl