Use for..of Object.keys instead of for..in (#9518)
In https://github.com/babel/babel/issues/9511 (and #9495 is another symptom), @PavelKastornyy reported a node crash becaue the JavaScript heap run out of memory. The problem was that their code was adding enumerable properties to `Object.prototype`: it is something that shouldn't be done, but Babel shouldn't make node crash if someone adds them. I reduced down the problem to `for...in` loops in `@babel/traverse` that grew the memory consumption exponentially because of that unexpected properties.
This commit is contained in:
@@ -195,12 +195,12 @@ function misMatch(exp, act) {
|
||||
return ppJSON(exp) + " !== " + ppJSON(act);
|
||||
}
|
||||
} else {
|
||||
for (const prop in exp) {
|
||||
for (const prop of Object.keys(exp)) {
|
||||
const mis = misMatch(exp[prop], act[prop]);
|
||||
if (mis) return addPath(mis, prop);
|
||||
}
|
||||
|
||||
for (const prop in act) {
|
||||
for (const prop of Object.keys(act)) {
|
||||
if (typeof act[prop] === "function") {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user