9821286d6e527c21107ab52d6656d1b9b436f70f
[platform/framework/web/crosswalk-tizen.git] /
1 var baseForIn = require('./baseForIn'),
2     isObjectLike = require('./isObjectLike');
3
4 /** `Object#toString` result references. */
5 var objectTag = '[object Object]';
6
7 /** Used for native method references. */
8 var objectProto = Object.prototype;
9
10 /** Used to check objects for own properties. */
11 var hasOwnProperty = objectProto.hasOwnProperty;
12
13 /**
14  * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
15  * of values.
16  */
17 var objToString = objectProto.toString;
18
19 /**
20  * A fallback implementation of `_.isPlainObject` which checks if `value`
21  * is an object created by the `Object` constructor or has a `[[Prototype]]`
22  * of `null`.
23  *
24  * @private
25  * @param {*} value The value to check.
26  * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
27  */
28 function shimIsPlainObject(value) {
29   var Ctor;
30
31   // Exit early for non `Object` objects.
32   if (!(isObjectLike(value) && objToString.call(value) == objectTag) ||
33       (!hasOwnProperty.call(value, 'constructor') &&
34         (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
35     return false;
36   }
37   // IE < 9 iterates inherited properties before own properties. If the first
38   // iterated property is an object's own property then there are no inherited
39   // enumerable properties.
40   var result;
41   // In most environments an object's own properties are iterated before
42   // its inherited properties. If the last iterated property is an object's
43   // own property then there are no inherited enumerable properties.
44   baseForIn(value, function(subValue, key) {
45     result = key;
46   });
47   return result === undefined || hasOwnProperty.call(value, result);
48 }
49
50 module.exports = shimIsPlainObject;