Browse Source

fix: #2402 make sure a given element isn’t undefined before accessing properties (#2403)

codeClimate
David Anderson 8 years ago
committed by Alexander Wunschik
parent
commit
a77e462105
1 changed files with 11 additions and 9 deletions
  1. +11
    -9
      lib/util.js

+ 11
- 9
lib/util.js View File

@ -1488,17 +1488,19 @@ exports.topMost = function (pile, accessors) {
accessors = [accessors]; accessors = [accessors];
} }
for (const member of pile) { for (const member of pile) {
candidate = member[accessors[0]];
for (let i = 1; i < accessors.length; i++){
if (member) {
candidate = member[accessors[0]];
for (let i = 1; i < accessors.length; i++){
if (candidate) {
candidate = candidate[accessors[i]]
} else {
continue;
}
}
if (candidate) { if (candidate) {
candidate = candidate[accessors[i]]
} else {
continue;
break;
} }
} }
if (candidate) {
break;
}
} }
return candidate; return candidate;
}
};

Loading…
Cancel
Save