An exception occurred several times inside the following function, running in the (Chrome) browsers of our users. NB the code is minified, I've just added newlines for readabilily.
function a(c, b, e, f) {
for (var d in b) {
if (c && _.isObject(b[d]) === true && _.isArray(b[d]) === false) {
a(c[d], b[d], e, d + ".")
} else {
if (!c || _.isEqual(c[d], b[d]) === false) {
e.push({
name: f + d,
value: b[d]
})
}
}
}
return e
}
The exception was: TypeError: Cannot read property 'beginning' of null
So far my analysis is this:
- Known fact:
beginning
is one of the values of thed
variable (a property ofb
). - So, the exception occurred when evaluating
b[d]
orc[d]
- Inside the
for
loop,c
can be null, but notb
(b null => no loop) - So, the only way to trigger that exception is to have a
null
c
- If
c
isnull
, we have to take theelse
path - If
c
isnull
,!c
is truthy, so_.isEqual(...)
should not be evaluated (see Is that js expression safe: if( !x || doSomething( x[prop], y[prop] ) === false )).
At that point, I've reached a dead end in my reasoning. The exception should not happen. I probably made a mistake somewhere along the line, but where ?
NB: the problem seems to be fixed (I can't reproduce it, so I can't be sure), just by changing the code a bit, adding a separate 'is c null ?' test before the if...else, but that's not very satisfying.