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

util: use Object.create(null) for dictionary object #3791

Closed
wants to merge 10 commits into from
9 changes: 8 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ function stylizeNoColor(str, styleType) {


function arrayToHash(array) {
var hash = {};

var hash;

if (array.indexOf('__proto__') > -1) {
hash = Object.create(null);
} else {
hash = {};
}

array.forEach(function(val, idx) {

Choose a reason for hiding this comment

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

if idx is not used, why pass it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@YuriSolovyov Hmm, It was there before I made a PR,
I speculate that it could be used

Choose a reason for hiding this comment

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

it is not used anywhere in the scope of the function, IMO it is safe to drop it

hash[val] = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

You'd check if val was __proto__ here and discard it if it was, I think. cc @bnoordhuis

Expand Down