f27bb5a701367c3d7ec0203feebe72c6ed54108d
[platform/framework/web/crosswalk-tizen.git] /
1 var escapeRegExp = require('../string/escapeRegExp'),
2     isObjectLike = require('../internal/isObjectLike');
3
4 /** `Object#toString` result references. */
5 var funcTag = '[object Function]';
6
7 /** Used to detect host constructors (Safari > 5). */
8 var reIsHostCtor = /^\[object .+?Constructor\]$/;
9
10 /** Used for native method references. */
11 var objectProto = Object.prototype;
12
13 /** Used to resolve the decompiled source of functions. */
14 var fnToString = Function.prototype.toString;
15
16 /**
17  * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
18  * of values.
19  */
20 var objToString = objectProto.toString;
21
22 /** Used to detect if a method is native. */
23 var reIsNative = RegExp('^' +
24   escapeRegExp(objToString)
25   .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
26 );
27
28 /**
29  * Checks if `value` is a native function.
30  *
31  * @static
32  * @memberOf _
33  * @category Lang
34  * @param {*} value The value to check.
35  * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
36  * @example
37  *
38  * _.isNative(Array.prototype.push);
39  * // => true
40  *
41  * _.isNative(_);
42  * // => false
43  */
44 function isNative(value) {
45   if (value == null) {
46     return false;
47   }
48   if (objToString.call(value) == funcTag) {
49     return reIsNative.test(fnToString.call(value));
50   }
51   return isObjectLike(value) && reIsHostCtor.test(value);
52 }
53
54 module.exports = isNative;