From 15aa3ecb5d842635abaa7cfa85787c47bb3406d4 Mon Sep 17 00:00:00 2001 From: slackersoft Date: Fri, 17 Jan 2014 19:56:43 -1000 Subject: [PATCH] Better support in pretty printer when an object has null prototype - Fixes #500 --- lib/jasmine-core/jasmine.js | 2 +- spec/core/PrettyPrintSpec.js | 7 +++++++ src/core/PrettyPrinter.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) 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);