new Date(-0) has two allowed implementations

Simon Pieters simonp at
Tue Mar 19 08:05:24 PDT 2013


The spec allows two different behaviors for new Date(-0):

Return an implementation-dependent choice of either ToInteger(time) or
ToInteger(time) + (+0). (Adding a positive zero converts −0 to +0.)

jwalden said in #whatwg as to why:

implementation of new Date(-0) has two representations *only* so that
implementations can store dates, internally, as either an int64_t or a
double; SpiderMonkey stores internally as double but adds 0 in TimeClip so
-0 doesn't have weird behavior; for any implementation using double
representation it's easy to look like int64_t, but probably far harder the
other way; thus mandating +0 behavior is probably the thing the most
people'd be compatible with; I can't think of a good reason to support
this difference at the hardware level -- anyone using double
representation can do +0 to pretend to be int64_t-represented, and
implementations have to have double capabilities to represent math
generally, so I don't see why mandating as-if-by-int64_t would be
prevented by hardware issues

Could the spec be changed to require -0 to be converted to +0? Doing so
would make it easier to write test cases and would remove a possible
interop hole that Web pages can fall into (it seems unlikely that they
would, but, well, it's the Web we're talking about here).

Simon Pieters
Opera Software

More information about the es-discuss mailing list