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:
beginningis one of the values of thedvariable (a property ofb). - So, the exception occurred when evaluating
b[d]orc[d] - Inside the
forloop,ccan be null, but notb(b null => no loop) - So, the only way to trigger that exception is to have a
nullc - If
cisnull, we have to take theelsepath - If
cisnull,!cis 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.