X Tutup
Skip to content

Throw when passed strings on Object.prototype#21

Merged
dougwilson merged 1 commit intojshttp:masterfrom
EvanHahn:avoid-object-prototype
Jan 3, 2021
Merged

Throw when passed strings on Object.prototype#21
dougwilson merged 1 commit intojshttp:masterfrom
EvanHahn:avoid-object-prototype

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?

@dougwilson dougwilson added the pr label Dec 25, 2020
@EvanHahn EvanHahn force-pushed the avoid-object-prototype branch from f67b43e to afa5f0b Compare December 25, 2020 19:22
@EvanHahn
Copy link
Contributor Author

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

@dougwilson dougwilson force-pushed the avoid-object-prototype branch from afa5f0b to 16cbd05 Compare January 3, 2021 05:59
@dougwilson dougwilson force-pushed the avoid-object-prototype branch from 16cbd05 to 90c1829 Compare January 3, 2021 06:13
@dougwilson dougwilson added the bug label Jan 3, 2021
@dougwilson dougwilson self-assigned this Jan 3, 2021
@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.

2 participants

X Tutup