diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index e88c3655..a5614f9d 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1390,7 +1390,7 @@ getJasmineRequireObj().pp = function(j$) { PrettyPrinter.prototype.iterateObject = function(obj, fn) { for (var property in obj) { - if (!obj.hasOwnProperty(property)) { continue; } + if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; } if (property == '__Jasmine_been_here_before__') { continue; } fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) && obj.__lookupGetter__(property) !== null) : false); diff --git a/spec/core/PrettyPrintSpec.js b/spec/core/PrettyPrintSpec.js index 2314f926..0d447f32 100644 --- a/spec/core/PrettyPrintSpec.js +++ b/spec/core/PrettyPrintSpec.js @@ -121,5 +121,12 @@ describe("j$.pp", function () { expect(j$.pp(obj)).toEqual("strung"); }); + + it("should handle objects with null prototype", function() { + var obj = Object.create(null); + obj.foo = 'bar'; + + expect(j$.pp(obj)).toEqual("{ foo : 'bar' }"); + }); }); diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js index 4029a225..b3b6e80d 100644 --- a/src/core/PrettyPrinter.js +++ b/src/core/PrettyPrinter.js @@ -47,7 +47,7 @@ getJasmineRequireObj().pp = function(j$) { PrettyPrinter.prototype.iterateObject = function(obj, fn) { for (var property in obj) { - if (!obj.hasOwnProperty(property)) { continue; } + if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; } if (property == '__Jasmine_been_here_before__') { continue; } fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) && obj.__lookupGetter__(property) !== null) : false);