Skip to content
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

Increase readability (Date.parse) + fix: Date.parse should be non-enumerable #310

Closed
wants to merge 3 commits into from

Conversation

human0821
Copy link

No description provided.

@ljharb
Copy link
Member

ljharb commented Jun 17, 2015

Please split this up into multiple PRs - this diff is not readable, so I can't easily review it.

Also, since Date.parse starts out non-enumerable, simply assigning over it preserves the non-enumerability. Can you add some tests that would fail without your changes?

var DateShimParse = function parse(string) {

var match, year, month, day, hour, minute, second, millisecond
,isLocalTime, signOffset, hourOffset, minuteOffset, result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma first is never acceptable here, and please either put every variable on the same line (regardless of line length, which doesn't matter), or put each variable on its own line.

var DateShimParse = function parse(string) {

var match, year, month, day, hour, minute, second, millisecond, isLocalTime, signOffset, hourOffset, minuteOffset, result;
match = isoDateExpression.exec(string);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do var match here, instead of initializing all the variables at the top of the function - that's not a style we insist on.

@ljharb
Copy link
Member

ljharb commented Jun 17, 2015

The Date shims are very complex - this will need to be tested in ES3 and ES5 versions of IE, Safari, Opera, Firefox, Chrome, etc before merging, and definitely will require automated tests to be added.

@human0821
Copy link
Author

Due to the fact that automated tests are required the commit should be closed then. But at least it worth noting that original Date.parse method has internal DontEnum attribute which is set to true by default (non-enumerable). Current shim unfortunately has this attribute set to false (enumerable).

@human0821 human0821 closed this Jun 17, 2015
@ljharb
Copy link
Member

ljharb commented Jun 17, 2015

I'll double check that - in which browsers? In my understanding, the way JS engines work is that a non-enumerable property that is assigned to using the internal [[Put]] operation does not change the enumerable descriptor value.

@ljharb
Copy link
Member

ljharb commented Jun 17, 2015

Wow, you are totally correct, thanks! Fix incoming.

ljharb added a commit that referenced this pull request Jun 17, 2015
@ljharb ljharb self-assigned this Jun 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants