diff --git a/lodash.src.js b/lodash.src.js index 86a2a6036..b44470634 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -772,6 +772,7 @@ ceil = Math.ceil, clearTimeout = context.clearTimeout, floor = Math.floor, + getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols, getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf, push = arrayProto.push, propertyIsEnumerable = objectProto.propertyIsEnumerable, @@ -793,6 +794,18 @@ return result; }()); + /** Used as `baseAssign`. */ + var nativeAssign = (function() { + var object = Object('x'), + func = isNative(func = Object.assign) && func; + + // Avoid `Object.assign` in Firefox 34-37 which have an early implementation + // with a slower try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344 + // for more details. + try { func(object, 'xo'); } catch(e) {} + return !object[1] && func; + }()); + /* Native method references for those with the same name as other `lodash` methods. */ var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray, nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate, @@ -1747,21 +1760,19 @@ } /** - * The base implementation of `_.assign` without support for argument juggling, - * multiple sources, and `this` binding `customizer` functions. + * A specialized version of `_.assign` for customizing assigned values without + * support for argument juggling, multiple sources, and `this` binding `customizer` + * functions. * * @private * @param {Object} object The destination object. * @param {Object} source The source object. - * @param {Function} [customizer] The function to customize assigning values. - * @returns {Object} Returns the destination object. + * @param {Function} customizer The function to customize assigned values. + * @returns {Object} Returns `object`. */ - function baseAssign(object, source, customizer) { - var props = keys(source); - if (!customizer) { - return baseCopy(source, object, props); - } + function assignWith(object, source, customizer) { var index = -1, + props = keys(source), length = props.length; while (++index < length) { @@ -1777,6 +1788,21 @@ return object; } + /** + * The base implementation of `_.assign` without support for argument juggling, + * multiple sources, and `customizer` functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @returns {Object} Returns `object`. + */ + var baseAssign = nativeAssign || function(object, source) { + return source == null + ? object + : baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object)); + }; + /** * The base implementation of `_.at` without support for string collections * and individual key arguments. @@ -1809,15 +1835,13 @@ * * @private * @param {Object} source The object to copy properties from. - * @param {Object} [object={}] The object to copy properties to. * @param {Array} props The property names to copy. + * @param {Object} [object={}] The object to copy properties to. * @returns {Object} Returns `object`. */ - function baseCopy(source, object, props) { - if (!props) { - props = object; - object = {}; - } + function baseCopy(source, props, object) { + object || (object = {}); + var index = -1, length = props.length; @@ -1897,7 +1921,7 @@ } result = initCloneObject(isFunc ? {} : value); if (!isDeep) { - return baseCopy(value, result, keys(value)); + return baseAssign(result, value); } } else { return cloneableTags[tag] @@ -2536,7 +2560,7 @@ * @param {Function} [customizer] The function to customize merging properties. * @param {Array} [stackA=[]] Tracks traversed source objects. * @param {Array} [stackB=[]] Associates values with source counterparts. - * @returns {Object} Returns the destination object. + * @returns {Object} Returns `object`. */ function baseMerge(object, source, customizer, stackA, stackB) { if (!isObject(object)) { @@ -4114,6 +4138,15 @@ */ var getLength = baseProperty('length'); + /** + * Creates an array of the own symbols of `object`. + * + * @private + * @param {Object} object The object to inspect. + * @returns {Array} Returns the array of symbols. + */ + var getSymbols = getOwnPropertySymbols || constant([]); + /** * Gets the view, applying any `transforms` to the `start` and `end` positions. * @@ -8650,7 +8683,7 @@ * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @param {Function} [customizer] The function to customize comparing values. + * @param {Function} [customizer] The function to customize value comparisons. * @param {*} [thisArg] The `this` binding of `customizer`. * @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @example @@ -8803,7 +8836,7 @@ * @category Lang * @param {Object} object The object to inspect. * @param {Object} source The object of property values to match. - * @param {Function} [customizer] The function to customize comparing values. + * @param {Function} [customizer] The function to customize value comparisons. * @param {*} [thisArg] The `this` binding of `customizer`. * @returns {boolean} Returns `true` if `object` is a match, else `false`. * @example @@ -9152,7 +9185,7 @@ * @category Object * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. - * @param {Function} [customizer] The function to customize assigning values. + * @param {Function} [customizer] The function to customize assigned values. * @param {*} [thisArg] The `this` binding of `customizer`. * @returns {Object} Returns `object`. * @example @@ -9168,7 +9201,11 @@ * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); * // => { 'user': 'barney', 'age': 36 } */ - var assign = createAssigner(baseAssign); + var assign = createAssigner(function(object, source, customizer) { + return customizer + ? assignWith(object, source, customizer) + : baseAssign(object, source); + }); /** * Creates an object that inherits from the given `prototype` object. If a @@ -9209,7 +9246,7 @@ if (guard && isIterateeCall(prototype, properties, guard)) { properties = null; } - return properties ? baseCopy(properties, result, keys(properties)) : result; + return properties ? baseAssign(result, properties) : result; } /** @@ -9773,7 +9810,7 @@ * @category Object * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. - * @param {Function} [customizer] The function to customize merging properties. + * @param {Function} [customizer] The function to customize assigned values. * @param {*} [thisArg] The `this` binding of `customizer`. * @returns {Object} Returns `object`. * @example @@ -10745,9 +10782,9 @@ options = otherOptions = null; } string = baseToString(string); - options = baseAssign(baseAssign({}, otherOptions || options), settings, assignOwnDefaults); + options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults); - var imports = baseAssign(baseAssign({}, options.imports), settings.imports, assignOwnDefaults), + var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys);