-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normative: Date.prototype.toString throws on non-Date receiver #850
Conversation
JSC and V8 have been shipping the version of the specification included in this patch, so it is likely to be web-compatible. Throwing on receivers which are not Date instances is simpler and more consistent with other methods in ECMAScript. Closes tc39#849
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, consider me a vote for
+1, we might need to update test262, thou, but that's easy and fast. |
From section/annex D, should this be changed too? |
Tests in tc39/test262#924 |
I think the current behaviour is based on the discussion in https://mail.mozilla.org/pipermail/es-discuss/2014-June/037630.html. |
@anba Huh, based on the negative replies there, and the fact that RegExp was not similarly updated (until I developed evidence of web compatibility issues and patched it for ES2016), I assumed that this thread wasn't the one that led to the change. Anyway, although V8 received bug reports about RegExp.prototype.toString() throwing, I don't see any bug reports about Date.prototype.toString() throwing. I'm not sure how much of a user issue this is. Note that many other methods on Date throw on Date.prototype, and conversion to a string throws for many other objects in the system, e.g., Symbol.prototype. |
I think this is the thread that led to the current Date.prototype.toString method, at least based on when it took place. The messages are from June 2014 and in the next ES6 draft (rev 26), @allenwb added + 1. Let Q be this Date object.
+ 2. If Type(O) is Object and O does not have a [[DateValue]] internal slot, then
+ a. Let tv be NaN.
+ 3. Else,
a. Let tv be this time value.
4. Return ToDateString(tv) to Date.prototype.toString.
If the change is web-compatible, we probably should try to apply it. |
tests in tc39/test262#924 |
IIRC we got consensus on this change in the May 2017 TC39 meeting. There are tests. Is this ready to merge? |
Sorry I didn't see @leobalter's earlier comment. With tests, this is ready to go! |
JSC and V8 have been shipping the version of the specification
included in this patch, so it is likely to be web-compatible.
Throwing on receivers which are not Date instances is simpler
and more consistent with other methods in ECMAScript.
Closes #849