d165c40cb5b9ea8487ee467c207c8ffa6f3f12a5
[platform/framework/web/crosswalk-tizen.git] /
1 var isArguments = require('../lang/isArguments'),
2     isArray = require('../lang/isArray'),
3     isIndex = require('./isIndex'),
4     isLength = require('./isLength'),
5     keysIn = require('../object/keysIn'),
6     support = require('../support');
7
8 /** Used for native method references. */
9 var objectProto = Object.prototype;
10
11 /** Used to check objects for own properties. */
12 var hasOwnProperty = objectProto.hasOwnProperty;
13
14 /**
15  * A fallback implementation of `Object.keys` which creates an array of the
16  * own enumerable property names of `object`.
17  *
18  * @private
19  * @param {Object} object The object to query.
20  * @returns {Array} Returns the array of property names.
21  */
22 function shimKeys(object) {
23   var props = keysIn(object),
24       propsLength = props.length,
25       length = propsLength && object.length;
26
27   var allowIndexes = length && isLength(length) &&
28     (isArray(object) || (support.nonEnumArgs && isArguments(object)));
29
30   var index = -1,
31       result = [];
32
33   while (++index < propsLength) {
34     var key = props[index];
35     if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
36       result.push(key);
37     }
38   }
39   return result;
40 }
41
42 module.exports = shimKeys;