8000 Ensure getIn does not throw when iterating over null. Fixes #129 · powercoder23/immutable-js@9261f52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9261f52

Browse files
committed
Ensure getIn does not throw when iterating over null. Fixes immutable-js#129
1 parent 80cf20b commit 9261f52

File tree

3 files changed

+38
-47
lines changed

3 files changed

+38
-47
lines changed

dist/Immutable.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,16 @@ var $Sequence = Sequence;
444444
}), null, notSetValue);
445445
},
446446
getIn: function(searchKeyPath, notSetValue) {
447-
if (!searchKeyPath || searchKeyPath.length === 0) {
448-
return this;
447+
var nested = this;
448+
if (searchKeyPath) {
449+
for (var ii = 0; ii < searchKeyPath.length; ii++) {
450+
nested = nested && nested.get ? nested.get(searchKeyPath[ii], NOT_SET) : NOT_SET;
451+
if (nested === NOT_SET) {
452+
return notSetValue;
453+
}
454+
}
449455
}
450-
return getInDeepSequence(this, searchKeyPath, notSetValue, 0);
456+
return nested;
451457
},
452458
contains: function(searchValue) {
453459
return this.find((function(value) {
@@ -921,16 +927,6 @@ function makeSequence() {
921927
function makeIndexedSequence(parent) {
922928
return Object.create(IndexedSequencePrototype);
923929
}
924-
function getInDeepSequence(seq, keyPath, notSetValue, pathOffset) {
925-
var nested = seq.get ? seq.get(keyPath[pathOffset], NOT_SET) : NOT_SET;
926-
if (nested === NOT_SET) {
927-
return notSetValue;
928-
}
929-
if (++pathOffset === keyPath.length) {
930-
return nested;
931-
}
932-
return getInDeepSequence(nested, keyPath, notSetValue, pathOffset);
933-
}
934930
function wholeSlice(begin, end, length) {
935931
return (begin === 0 || (length != null && begin <= -length)) && (end == null || (length != null && end >= length));
936932
}

0 commit comments

Comments
 (0)
0