Open
Conversation
[`__proto__`] is a special property to access an object's prototype. It has many pitfalls: - Setting it to an object value changes an object's prototype, which is generally discouraged and may be unexpected by the `iterator` callback. - Setting it to a non-object value does nothing (meaning `seen[k] = true` has no effect). - When Node.js is run with the [`--disable-proto=throw`] option, getting or setting `__proto__` causes an exception with code `ERR_PROTO_ACCESS` to be thrown. Additionally, since this property (and all properties of `Object.prototype`) are currently unused in this project by consumers of `walk()`, it is both safe and preferable to exclude. [`__proto__`]: https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.prototype.__proto__ [`--disable-proto=throw`]: https://nodejs.org/api/cli.html#disable-protomode Fixes: sinonjs#2695 Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose (TL;DR) - mandatory
Fix issue #2695 by excluding
__proto__fromwalk().Background (Problem in detail) - optional
__proto__is a special property to access an object's prototype. It has many pitfalls:iteratorcallback.seen[k] = truehas no effect).--disable-proto=throwoption, getting or setting__proto__causes an exception with codeERR_PROTO_ACCESSto be thrown, which causes issues like Change in 21.1: sinon.stub() throws with--disable-proto=throw#2695.Solution - optional
Since
__proto__(and all properties ofObject.prototype) are currently unused by consumers ofwalk()in this project, it is both safe and preferable to exclude it from enumeration bywalk().How to verify - mandatory
npm installNODE_OPTIONS=--disable-proto=throw npm testChecklist for author
npm run lintpassesAdditional Work
It would be great if
--disable-proto=throwcould be added to the test suite, either by adding--node-option disable-proto=throwto the mocha invocation intest-node, or adding a separate run to test under these conditions. However, this may introduce an additional maintenance burden, so requires additional discussion and is not currently part of this PR.Thanks for considering,
Kevin