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

Throw when passed strings on Object.prototype #21

Merged
merged 1 commit into from Jan 3, 2021

Conversation

EvanHahn
Copy link
Contributor

Because 'constructor' in Object.prototype, status('constructor') would return Object.prototype.constructor. This was true for any all-lowercase key, which is currently __proto__ and constructor.

Here's the meat of the change:

-  var map = {}
+  var map = Object.create(null)

Copy link
Contributor

@dougwilson dougwilson left a comment

Choose a reason for hiding this comment

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

Unfortunately this object is a public API, so changing the prototype within the same major version is going to be painful. Can we implement the same behavior with something like Object.prototype.hasOwnProperty instead?

@EvanHahn
Copy link
Contributor Author

Updated with a new utility function, getOwn. Let me know if you'd prefer something lighter-weight.

@dougwilson
Copy link
Contributor

Thanks @EvanHahn ! I updated the PR to perform the check on all the lookups as well, so they are all guarded now as appropriate.

@dougwilson dougwilson merged commit 90c1829 into jshttp:master Jan 3, 2021
EvanHahn added a commit to EvanHahn/evanhahn-dot-com that referenced this pull request Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants