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
10 changes: 9 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,17 @@ function stylizeNoColor(str, styleType) {


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

var 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


Copy link
Contributor

Choose a reason for hiding this comment

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

Why creating a new hash in each iteration?

Copy link
Member Author

Choose a reason for hiding this comment

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

@pmq20 Sorry, it was a mistake

if(val==='__proto__'){
hash = Object.create(null);
}else{
hash = {};
}

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