TomFrost / Bristol

Insanely configurable logging for Node.js
MIT License
113 stars 19 forks source link

Internal forEachObj() function Exception on null-proto Objects #23

Closed MarkHerhold closed 7 years ago

MarkHerhold commented 8 years ago

I have a very strange issue where a module is producing a prototype-less (null) object, which causes Bristol to blow up when the object gets run through the internal forEachObj() function.

I'm honestly not sure if this should be addressed by Bristol, but it would be nice to never have Bristol throw an error (which has been the case up to now).

Here's the code to reproduce the issue:

function forEachObj(obj, cb) {
    var brakesOn = false,
        brake = function() { brakesOn = true; };
    for (var key in obj) {
        if (obj.hasOwnProperty(key))
            cb(key, obj[key], brake);
        if (brakesOn) break;
    }
}

let badObj = {value: 5};
badObj.__proto__ = null; // set null proto

forEachObj(badObj, function() {})
// TypeError: obj.hasOwnProperty is not a function

Any thoughts are appreciated.