Better support in pretty printer when an object has null prototype

- Fixes #500
This commit is contained in:
slackersoft
2014-01-17 19:56:43 -10:00
parent 2670bb40a7
commit 15aa3ecb5d
3 changed files with 9 additions and 2 deletions

View File

@@ -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);

View File

@@ -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' }");
});
});

View File

@@ -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);