15.2.3.4 Object.getOwnPropertyNames(O)

2010-07-04

array Object.getOwnPropertyNames(O:object) throws TypeError

Return the names of all properties of O, regardless of their [[Enumerable]] value, as an array. See Object.keys (15.2.3.14) to get only the properties that have [[Enumerable]] set to true.

Code: (Meta Ecma)
Object.getOwnPropertyNames = 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 name = P;
array.[[DefineOwnProperty]](ToString(n), PD{[[Value]]:name, [[Writable]]:true, [[Enumerable]]:true, [[Configurable]]:true}, false);
++n;
}
return array;
}


Note that String instances also return the properties defined in 15.5.5.2 (character positions of the string).