Skip to content

Commit df23e14

Browse files
committed
use hasOwnProperty in for in loops
fixes webpack#450
1 parent 89db931 commit df23e14

1 file changed

Lines changed: 34 additions & 26 deletions

File tree

‎lib/HotModuleReplacementPlugin.js‎

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,11 @@ var hotInitCode = Template.getFunctionContent(function() {
475475
appliedUpdate[moduleId] = hotUpdate[moduleId];
476476
addAllToSet(outdatedModules, result[0]);
477477
for(var moduleId in result[1]) {
478-
if(!outdatedDependencies[moduleId])
479-
outdatedDependencies[moduleId] = [];
480-
addAllToSet(outdatedDependencies[moduleId], result[1][moduleId]);
478+
if(Object.prototype.hasOwnProperty.call(result[1], moduleId)) {
479+
if(!outdatedDependencies[moduleId])
480+
outdatedDependencies[moduleId] = [];
481+
addAllToSet(outdatedDependencies[moduleId], result[1][moduleId]);
482+
}
481483
}
482484
}
483485

@@ -530,12 +532,14 @@ var hotInitCode = Template.getFunctionContent(function() {
530532

531533
// remove outdated dependency from module children
532534
for(var moduleId in outdatedDependencies) {
533-
var module = installedModules[moduleId];
534-
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
535-
for(var j = 0; j < moduleOutdatedDependencies.length; j++) {
536-
var dependency = moduleOutdatedDependencies[j];
537-
var idx = module.children.indexOf(dependency);
538-
if(idx >= 0) module.children.splice(idx, 1);
535+
if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
536+
var module = installedModules[moduleId];
537+
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
538+
for(var j = 0; j < moduleOutdatedDependencies.length; j++) {
539+
var dependency = moduleOutdatedDependencies[j];
540+
var idx = module.children.indexOf(dependency);
541+
if(idx >= 0) module.children.splice(idx, 1);
542+
}
539543
}
540544
}
541545

@@ -546,28 +550,32 @@ var hotInitCode = Template.getFunctionContent(function() {
546550

547551
// insert new code
548552
for(var moduleId in appliedUpdate) {
549-
modules[moduleId] = appliedUpdate[moduleId];
553+
if(Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
554+
modules[moduleId] = appliedUpdate[moduleId];
555+
}
550556
}
551557

552558
// call accept handlers
553559
var error = null;
554560
for(var moduleId in outdatedDependencies) {
555-
var module = installedModules[moduleId];
556-
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
557-
var callbacks = [];
558-
for(var i = 0; i < moduleOutdatedDependencies.length; i++) {
559-
var dependency = moduleOutdatedDependencies[i];
560-
var cb = module.hot._acceptedDependencies[dependency];
561-
if(callbacks.indexOf(cb) >= 0) continue;
562-
callbacks.push(cb);
563-
}
564-
for(var i = 0; i < callbacks.length; i++) {
565-
var cb = callbacks[i];
566-
try {
567-
cb(outdatedDependencies);
568-
} catch(err) {
569-
if(!error)
570-
error = err;
561+
if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
562+
var module = installedModules[moduleId];
563+
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
564+
var callbacks = [];
565+
for(var i = 0; i < moduleOutdatedDependencies.length; i++) {
566+
var dependency = moduleOutdatedDependencies[i];
567+
var cb = module.hot._acceptedDependencies[dependency];
568+
if(callbacks.indexOf(cb) >= 0) continue;
569+
callbacks.push(cb);
570+
}
571+
for(var i = 0; i < callbacks.length; i++) {
572+
var cb = callbacks[i];
573+
try {
574+
cb(outdatedDependencies);
575+
} catch(err) {
576+
if(!error)
577+
error = err;
578+
}
571579
}
572580
}
573581
}

0 commit comments

Comments
 (0)