Avoid circular dep with isHostObject.

This commit is contained in:
John-David Dalton
2014-08-23 12:12:24 -07:00
parent 691d566482
commit fca5fda9da

View File

@@ -544,6 +544,26 @@
return '\\' + stringEscapes[chr]; return '\\' + stringEscapes[chr];
} }
/**
* Checks if `value` is a host object in IE < 9.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
*/
var isHostObject = (function() {
try {
({ 'toString': 0 } + '');
} catch(e) {
return function() { return false; };
}
return function(value) {
// IE < 9 presents many host objects as `Object` objects that can coerce to
// strings despite having improperly defined `toString` methods
return typeof value.toString != 'function' && typeof (value + '') == 'string';
};
}());
/** /**
* Used by `_.trimmedLeftIndex` and `_.trimmedRightIndex` to determine if a * Used by `_.trimmedLeftIndex` and `_.trimmedRightIndex` to determine if a
* character code is whitespace. * character code is whitespace.
@@ -921,6 +941,14 @@
*/ */
support.funcNames = typeof Function.name == 'string'; support.funcNames = typeof Function.name == 'string';
/**
* Detect if the `[[Class]]` of DOM nodes is resolvable (all but IE < 9).
*
* @memberOf _.support
* @type boolean
*/
support.nodeClass = toString.call(document) != objectClass;
/** /**
* Detect if string indexes are non-enumerable * Detect if string indexes are non-enumerable
* (IE < 9, RingoJS, Rhino, Narwhal). * (IE < 9, RingoJS, Rhino, Narwhal).
@@ -990,26 +1018,6 @@
support.dom = false; support.dom = false;
} }
/**
* Detect if the host objects are detectable (IE < 9).
*
* @memberOf _.support
* @type boolean
*/
try {
support.hostObject = !({ 'toString': 0 } + '');
} catch(e) {
support.hostObject = false;
}
/**
* Detect if the `[[Class]]` of DOM nodes is resolvable (all but IE < 9).
*
* @memberOf _.support
* @type boolean
*/
support.nodeClass = !(toString.call(document) == objectClass && support.hostObject);
/** /**
* Detect if `arguments` object indexes are non-enumerable. * Detect if `arguments` object indexes are non-enumerable.
* *
@@ -2884,7 +2892,7 @@
*/ */
function initObjectClone(object, isDeep) { function initObjectClone(object, isDeep) {
var className = toString.call(object); var className = toString.call(object);
if (!cloneableClasses[className] || (!support.nodeClass && isHostObject(object))) { if (!cloneableClasses[className] || isHostObject(object)) {
return object; return object;
} }
var Ctor = object.constructor, var Ctor = object.constructor,
@@ -2942,19 +2950,6 @@
arrayLikeClasses[toString.call(value)]) || false; arrayLikeClasses[toString.call(value)]) || false;
} }
/**
* Checks if `value` is a host object in IE < 9.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
*/
var isHostObject = !support.hostObject ? constant(false) : function(value) {
// IE < 9 presents many host objects as `Object` objects that can coerce to
// strings despite having improperly defined `toString` methods
return typeof value.toString != 'function' && typeof (value + '') == 'string';
};
/** /**
* Checks if `value` is suitable for strict equality comparisons, i.e. `===`. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
* *
@@ -3079,12 +3074,12 @@
var Ctor, var Ctor,
result; result;
// avoid non `Object` objects, `arguments` objects, and DOM elements // exit early for non `Object` objects
if (!(value && toString.call(value) == objectClass) || if (!(value && typeof value == 'object' &&
toString.call(value) == objectClass && !isHostObject(value)) ||
(!hasOwnProperty.call(value, 'constructor') && (!hasOwnProperty.call(value, 'constructor') &&
(Ctor = value.constructor, isFunction(Ctor) && !(Ctor instanceof Ctor))) || (Ctor = value.constructor, isFunction(Ctor) && !(Ctor instanceof Ctor))) ||
(!support.argsClass && isArguments(value)) || (!support.argsClass && isArguments(value))) {
(!support.nodeClass && isHostObject(value))) {
return false; return false;
} }
// IE < 9 iterates inherited properties before own properties. If the first // IE < 9 iterates inherited properties before own properties. If the first
@@ -7376,12 +7371,8 @@
if (isFunction(value)) { if (isFunction(value)) {
return reNative.test(fnToString.call(value)); return reNative.test(fnToString.call(value));
} }
if (value && typeof value == 'object') { return (value && typeof value == 'object' &&
return !('constructor' in value) && isHostObject(value) (isHostObject(value) ? reNative : reHostCtor).test(value)) || false;
? reNative.test(value)
: reHostCtor.test(toString.call(value));
}
return false;
} }
/** /**