Skip to content

Commit

Permalink
Potential fix for #240
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanth committed Jun 1, 2014
1 parent ebad461 commit 357be95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,15 @@
},

getPropertyNames: function(subject) {
var result = Object.getOwnPropertyNames(subject);
var getOwnPropertyNames = function(object){
var props = [];
for (var key in object) {
if (object.hasOwnProperty(key))
props.push(key);
}
return props;
};
var result = getOwnPropertyNames(subject);
var proto = Object.getPrototypeOf(subject);

var addProperty = function(property) {
Expand All @@ -772,7 +780,7 @@
};

while (proto !== null) {
Object.getOwnPropertyNames(proto).forEach(addProperty);
getOwnPropertyNames(proto).forEach(addProperty);
proto = Object.getPrototypeOf(proto);
}
return result;
Expand Down
12 changes: 10 additions & 2 deletions test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ describe('Object', function() {
});

describe('Object.getPropertyNames()', function() {
var getOwnPropertyNames = function(object){
var props = [];
for (var key in object) {
if (object.hasOwnProperty(key))
props.push(key);
}
return props;
};
it('should produce an array of property names including inherited ones',
function() {
expect(Object.getPropertyNames(Object.create(null))).to.eql([]);
var obj = {};
expect(Object.getPropertyNames(Object.create(obj))).to.eql(
Object.getOwnPropertyNames(obj).concat(
Object.getOwnPropertyNames(Object.getPrototypeOf(obj))
getOwnPropertyNames(obj).concat(
getOwnPropertyNames(Object.getPrototypeOf(obj))
)
);
});
Expand Down

0 comments on commit 357be95

Please sign in to comment.