Skip to content

Commit

Permalink
Make sure the replaced Object.keys is non-enumerable.
Browse files Browse the repository at this point in the history
Also, move the try/catch to a function.
  • Loading branch information
ljharb committed Feb 16, 2015
1 parent c5528f5 commit fb5b059
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,13 +1098,19 @@
}());
}

try {
Object.keys('foo');
} catch (e) {
var objectKeysAcceptsPrimitives = (function () {
try {
Object.keys('foo');
return true;
} catch (e) {
return false;
}
}());
if (!objectKeysAcceptsPrimitives) {
var originalObjectKeys = Object.keys;
Object.keys = function (obj) {
return originalObjectKeys(ES.ToObject(obj));
};
defineProperty(Object, 'keys', function keys(value) {
return originalObjectKeys(ES.ToObject(value));
}, true);
}

if (!RegExp.prototype.flags && supportsDescriptors) {
Expand Down

0 comments on commit fb5b059

Please sign in to comment.