15.2.3.14 Object.keys(O)

2010-07-04

array Object.isExtensible(O:object) throws TypeError

Get all enumerable properties of object O. See Object.getOwnPropertyNames (15.2.3.4) to get all the (non-internal) properties of O.

Code: (Meta Ecma)
Object.keys = function(O){
if (Type(O) != 'Object') throw TypeError;
var array = [];
var n = 0;
for (P in O) { // note that this should IGNORE [[Enumerable]]! (at this level we assume all properties are enumerable)
var desc = O.[[GetOwnProperty]](P);
if (desc.[[Enumerable]]) {
var name = P;
array.[[DefineOwnProperty]](ToString(n), PD{[[Value]]:name, [[Writable]]:true, [[Enumerable]]:true, [[Configurable]]:true}, false);
++n;
}
}
return array;
}