Permalink
Browse files

Handling prototype enum bug.

  • Loading branch information...
1 parent e11054d commit 0ed16606b5d630848e4d292afa2cea4a8a02d8df @ljharb ljharb committed Jan 5, 2014
Showing with 7 additions and 6 deletions.
  1. +7 −6 es5-shim.js
View
@@ -655,6 +655,7 @@ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
if (!Object.keys) {
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
var hasDontEnumBug = true,
+ hasProtoEnumBug = (function () {}).propertyIsEnumerable('prototype'),
dontEnums = [
"toString",
"toLocaleString",
@@ -671,17 +672,17 @@ if (!Object.keys) {
}
Object.keys = function keys(object) {
+ var isFunction = toString.call(object) === '[object Function]',
+ isObject = object !== null && typeof object === 'object';
- if (
- (typeof object != "object" && typeof object != "function") ||
- object === null
- ) {
+ if (!isObject && !isFunction) {
throw new TypeError("Object.keys called on a non-object");
}
- var keys = [];
+ var keys = [],
+ skipProto = hasProtoEnumBug && isFunction;
for (var name in object) {
- if (owns(object, name)) {
+ if (!(skipProto && name === 'prototype') && owns(object, name)) {
keys.push(name);
}
}

0 comments on commit 0ed1660

Please sign in to comment.