mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Ensure _.keys works with arguments objets cross-browser.
Former-commit-id: 1238c9efcfc13a420804c26c5edee1e4aa5a4238
This commit is contained in:
21
build.js
21
build.js
@@ -254,6 +254,7 @@
|
|||||||
'isKeysFast',
|
'isKeysFast',
|
||||||
'object',
|
'object',
|
||||||
'objectBranch',
|
'objectBranch',
|
||||||
|
'noArgsEnum',
|
||||||
'noCharByIndex',
|
'noCharByIndex',
|
||||||
'shadowed',
|
'shadowed',
|
||||||
'top',
|
'top',
|
||||||
@@ -321,7 +322,7 @@
|
|||||||
' lodash include=... Comma separated names of methods to include in the build',
|
' lodash include=... Comma separated names of methods to include in the build',
|
||||||
'',
|
'',
|
||||||
' All arguments, except `backbone` with `underscore`, `exclude` with `include`,',
|
' All arguments, except `backbone` with `underscore`, `exclude` with `include`,',
|
||||||
' and `legacy` with `mobile`, may be combined.',
|
' and `legacy` with `csp`/`mobile`, may be combined.',
|
||||||
'',
|
'',
|
||||||
' Options:',
|
' Options:',
|
||||||
'',
|
'',
|
||||||
@@ -947,8 +948,8 @@
|
|||||||
return match.replace(/\bcallee\b/g, 'merge');
|
return match.replace(/\bcallee\b/g, 'merge');
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove `hasDontEnumBug` and `iteratesOwnLast` assignment
|
// remove `hasDontEnumBug`, `iteratesOwnLast`, `noArgsEnum` assignment
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(\)\);\n/, '');
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(1\)\);\n/, '');
|
||||||
|
|
||||||
// remove `iteratesOwnLast` from `isPlainObject`
|
// remove `iteratesOwnLast` from `isPlainObject`
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(iteratesOwnLast[\s\S]+?\n\1}/, '');
|
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(iteratesOwnLast[\s\S]+?\n\1}/, '');
|
||||||
@@ -1049,23 +1050,23 @@
|
|||||||
}
|
}
|
||||||
if ((source.match(/\bcreateIterator\b/g) || []).length < 2) {
|
if ((source.match(/\bcreateIterator\b/g) || []).length < 2) {
|
||||||
source = removeFunction(source, 'createIterator');
|
source = removeFunction(source, 'createIterator');
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var noArgsEnum;|.+?noArgsEnum *=.+/g, '');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) {
|
if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) {
|
||||||
source = removeVar(source, 'reNative');
|
source = removeVar(source, 'reNative');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'createIterator', 'clone', 'merge')) {
|
if (isRemoved(source, 'createIterator', 'clone', 'merge')) {
|
||||||
source = removeVar(source, 'iteratesOwnLast');
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var iteratesOwnLast;|.+?iteratesOwnLast *=.+/g, '');
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var iteratesOwnLast;| +iteratesOwnLast *=.+/, '');
|
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'createIterator', 'extend', 'isEqual', 'merge')) {
|
if (isRemoved(source, 'createIterator', 'isEqual')) {
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug;| +hasDontEnumBug *=.+/, '');
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug;|.+?hasDontEnumBug *=.+/g, '');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'createIterator', 'keys')) {
|
if (isRemoved(source, 'createIterator', 'keys')) {
|
||||||
source = removeVar(source, 'nativeKeys');
|
source = removeVar(source, 'nativeKeys');
|
||||||
}
|
}
|
||||||
if (!source.match(/var (?:hasDontEnumBug|iteratesOwnLast)\b/g)) {
|
if (!source.match(/var (?:hasDontEnumBug|iteratesOwnLast|noArgsEnum)\b/g)) {
|
||||||
// remove `hasDontEnumBug` and `iteratesOwnLast` assignment
|
// remove `hasDontEnumBug`, `iteratesOwnLast`, `noArgsEnum` assignment
|
||||||
source = source.replace(/ *\(function\(\) *{\s*var props\b[\s\S]+?}\(\)\);/, '');
|
source = source.replace(/ *\(function\(\) *{\s*var props\b[\s\S]+?}\(1\)\);/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove pseudo private properties
|
// remove pseudo private properties
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
'identity',
|
'identity',
|
||||||
'index',
|
'index',
|
||||||
'iteratee',
|
'iteratee',
|
||||||
'iterateeIndex',
|
|
||||||
'iteratorBind',
|
'iteratorBind',
|
||||||
'length',
|
'length',
|
||||||
'nativeKeys',
|
'nativeKeys',
|
||||||
@@ -38,6 +37,8 @@
|
|||||||
// lesser used variables
|
// lesser used variables
|
||||||
'accumulator',
|
'accumulator',
|
||||||
'args',
|
'args',
|
||||||
|
'argsIndex',
|
||||||
|
'argsLength',
|
||||||
'arrayLikeClasses',
|
'arrayLikeClasses',
|
||||||
'ArrayProto',
|
'ArrayProto',
|
||||||
'bind',
|
'bind',
|
||||||
@@ -84,6 +85,7 @@
|
|||||||
'isKeysFast',
|
'isKeysFast',
|
||||||
'object',
|
'object',
|
||||||
'objectBranch',
|
'objectBranch',
|
||||||
|
'noArgsEnum',
|
||||||
'noCharByIndex',
|
'noCharByIndex',
|
||||||
'shadowed',
|
'shadowed',
|
||||||
'top',
|
'top',
|
||||||
|
|||||||
74
lodash.js
74
lodash.js
@@ -134,14 +134,18 @@
|
|||||||
/** Detect if own properties are iterated after inherited properties (IE < 9) */
|
/** Detect if own properties are iterated after inherited properties (IE < 9) */
|
||||||
var iteratesOwnLast;
|
var iteratesOwnLast;
|
||||||
|
|
||||||
|
/** Detect if an `arguments` object's indexes are non-enumerable (IE < 9) */
|
||||||
|
var noArgsEnum = true;
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var props = [];
|
var props = [];
|
||||||
function ctor() { this.x = 1; }
|
function ctor() { this.x = 1; }
|
||||||
ctor.prototype = { 'valueOf': 1, 'y': 1 };
|
ctor.prototype = { 'valueOf': 1, 'y': 1 };
|
||||||
for (var prop in new ctor) { props.push(prop); }
|
for (var prop in new ctor) { props.push(prop); }
|
||||||
|
for (prop in arguments) { noArgsEnum = !prop; }
|
||||||
hasDontEnumBug = (props + '').length < 4;
|
hasDontEnumBug = (props + '').length < 4;
|
||||||
iteratesOwnLast = props[0] != 'x';
|
iteratesOwnLast = props[0] != 'x';
|
||||||
}());
|
}(1));
|
||||||
|
|
||||||
/** Detect if an `arguments` object's [[Class]] is unresolvable (Firefox < 4, IE < 9) */
|
/** Detect if an `arguments` object's [[Class]] is unresolvable (Firefox < 4, IE < 9) */
|
||||||
var noArgsClass = !isArguments(arguments);
|
var noArgsClass = !isArguments(arguments);
|
||||||
@@ -353,7 +357,20 @@
|
|||||||
|
|
||||||
// the following branch is for iterating an object's own/inherited properties
|
// the following branch is for iterating an object's own/inherited properties
|
||||||
'<% if (objectBranch) { %>' +
|
'<% if (objectBranch) { %>' +
|
||||||
' <% if (arrayBranch) { %>\nelse {<% } %>' +
|
' <% if (arrayBranch) { %>\nelse {' +
|
||||||
|
|
||||||
|
// add support for iterating over `arguments` objects if needed
|
||||||
|
' <% } else if (noArgsEnum) { %>\n' +
|
||||||
|
' var length = iteratee.length; index = -1;\n' +
|
||||||
|
' if (length && isArguments(iteratee)) {\n' +
|
||||||
|
' while (++index < length) {\n' +
|
||||||
|
' value = iteratee[index];\n' +
|
||||||
|
' index += \'\';\n' +
|
||||||
|
' <%= objectBranch.inLoop %>\n' +
|
||||||
|
' }\n' +
|
||||||
|
' } else {' +
|
||||||
|
' <% } %>' +
|
||||||
|
|
||||||
' <% if (!hasDontEnumBug) { %>\n' +
|
' <% if (!hasDontEnumBug) { %>\n' +
|
||||||
' var skipProto = typeof iteratee == \'function\' && \n' +
|
' var skipProto = typeof iteratee == \'function\' && \n' +
|
||||||
' propertyIsEnumerable.call(iteratee, \'prototype\');\n' +
|
' propertyIsEnumerable.call(iteratee, \'prototype\');\n' +
|
||||||
@@ -416,7 +433,7 @@
|
|||||||
' }' +
|
' }' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
' <% if (arrayBranch) { %>\n}<% } %>' +
|
' <% if (arrayBranch || noArgsEnum) { %>\n}<% } %>' +
|
||||||
'<% } %>\n' +
|
'<% } %>\n' +
|
||||||
|
|
||||||
// add code to the bottom of the iteration function
|
// add code to the bottom of the iteration function
|
||||||
@@ -473,8 +490,8 @@
|
|||||||
'args': 'object',
|
'args': 'object',
|
||||||
'init': 'object',
|
'init': 'object',
|
||||||
'top':
|
'top':
|
||||||
'for (var iterateeIndex = 1, length = arguments.length; iterateeIndex < length; iterateeIndex++) {\n' +
|
'for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) {\n' +
|
||||||
' iteratee = arguments[iterateeIndex];\n' +
|
' iteratee = arguments[argsIndex];\n' +
|
||||||
(hasDontEnumBug ? ' if (iteratee) {' : ''),
|
(hasDontEnumBug ? ' if (iteratee) {' : ''),
|
||||||
'inLoop': 'result[index] = value',
|
'inLoop': 'result[index] = value',
|
||||||
'bottom': (hasDontEnumBug ? ' }\n' : '') + '}'
|
'bottom': (hasDontEnumBug ? ' }\n' : '') + '}'
|
||||||
@@ -629,6 +646,7 @@
|
|||||||
data.firstArg = firstArg;
|
data.firstArg = firstArg;
|
||||||
data.hasDontEnumBug = hasDontEnumBug;
|
data.hasDontEnumBug = hasDontEnumBug;
|
||||||
data.isKeysFast = isKeysFast;
|
data.isKeysFast = isKeysFast;
|
||||||
|
data.noArgsEnum = noArgsEnum;
|
||||||
data.shadowed = shadowed;
|
data.shadowed = shadowed;
|
||||||
data.useHas = data.useHas !== false;
|
data.useHas = data.useHas !== false;
|
||||||
data.useStrict = data.useStrict !== false;
|
data.useStrict = data.useStrict !== false;
|
||||||
@@ -780,21 +798,6 @@
|
|||||||
// no operation performed
|
// no operation performed
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A shim implementation of `Object.keys` that produces an array of the given
|
|
||||||
* object's own enumerable property names.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} object The object to inspect.
|
|
||||||
* @returns {Array} Returns a new array of property names.
|
|
||||||
*/
|
|
||||||
var shimKeys = createIterator({
|
|
||||||
'args': 'object',
|
|
||||||
'exit': 'if (!(object && objectTypes[typeof object])) throw TypeError()',
|
|
||||||
'init': '[]',
|
|
||||||
'inLoop': 'result.push(index)'
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `template` to replace "escape" template delimiters with tokens.
|
* Used by `template` to replace "escape" template delimiters with tokens.
|
||||||
*
|
*
|
||||||
@@ -858,8 +861,8 @@
|
|||||||
* Creates a clone of `value`. If `deep` is `true`, all nested objects will
|
* Creates a clone of `value`. If `deep` is `true`, all nested objects will
|
||||||
* also be cloned otherwise they will be assigned by reference. If a value has
|
* also be cloned otherwise they will be assigned by reference. If a value has
|
||||||
* a `clone` method it will be used to perform the clone. Functions, DOM nodes,
|
* a `clone` method it will be used to perform the clone. Functions, DOM nodes,
|
||||||
* `arguments` objects, and object instances created by a constructor other
|
* `arguments` objects, and objects created by constructors other than `Object`
|
||||||
* than `Object` are **not** cloned unless they have a custom `clone` method.
|
* are **not** cloned unless they have a custom `clone` method.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -1042,8 +1045,8 @@
|
|||||||
/**
|
/**
|
||||||
* Iterates over `object`'s own and inherited enumerable properties, executing
|
* Iterates over `object`'s own and inherited enumerable properties, executing
|
||||||
* the `callback` for each property. The `callback` is bound to `thisArg` and
|
* the `callback` for each property. The `callback` is bound to `thisArg` and
|
||||||
* invoked with 3 arguments; (value, key, object). Callbacks may terminate
|
* invoked with 3 arguments; (value, key, object). Callbacks may exit iteration
|
||||||
* iteration early by explicitly returning `false`.
|
* early by explicitly returning `false`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -1074,7 +1077,7 @@
|
|||||||
/**
|
/**
|
||||||
* Iterates over `object`'s own enumerable properties, executing the `callback`
|
* Iterates over `object`'s own enumerable properties, executing the `callback`
|
||||||
* for each property. The `callback` is bound to `thisArg` and invoked with 3
|
* for each property. The `callback` is bound to `thisArg` and invoked with 3
|
||||||
* arguments; (value, key, object). Callbacks may terminate iteration early by
|
* arguments; (value, key, object). Callbacks may exit iteration early by
|
||||||
* explicitly returning `false`.
|
* explicitly returning `false`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -1628,6 +1631,21 @@
|
|||||||
return value === undefined;
|
return value === undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A shim implementation of `Object.keys` that produces an array of the given
|
||||||
|
* object's own enumerable property names.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} object The object to inspect.
|
||||||
|
* @returns {Array} Returns a new array of property names.
|
||||||
|
*/
|
||||||
|
var shimKeys = createIterator({
|
||||||
|
'args': 'object',
|
||||||
|
'exit': 'if (!(object && objectTypes[typeof object])) throw TypeError()',
|
||||||
|
'init': '[]',
|
||||||
|
'inLoop': 'result.push(index)'
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array composed of the own enumerable property names of `object`.
|
* Creates an array composed of the own enumerable property names of `object`.
|
||||||
*
|
*
|
||||||
@@ -1860,7 +1878,7 @@
|
|||||||
/**
|
/**
|
||||||
* Iterates over a `collection`, executing the `callback` for each element in
|
* Iterates over a `collection`, executing the `callback` for each element in
|
||||||
* the `collection`. The `callback` is bound to `thisArg` and invoked with 3
|
* the `collection`. The `callback` is bound to `thisArg` and invoked with 3
|
||||||
* arguments; (value, index|key, collection). Callbacks may terminate iteration
|
* arguments; (value, index|key, collection). Callbacks may exit iteration
|
||||||
* early by explicitly returning `false`.
|
* early by explicitly returning `false`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -2008,8 +2026,8 @@
|
|||||||
'top':
|
'top':
|
||||||
'var destValue, found, isArr, stackLength, recursive = indicator == isPlainObject;\n' +
|
'var destValue, found, isArr, stackLength, recursive = indicator == isPlainObject;\n' +
|
||||||
'if (!recursive) stack = [];\n' +
|
'if (!recursive) stack = [];\n' +
|
||||||
'for (var iterateeIndex = 1, length = recursive ? 2 : arguments.length; iterateeIndex < length; iterateeIndex++) {\n' +
|
'for (var argsIndex = 1, argsLength = recursive ? 2 : arguments.length; argsIndex < argsLength; argsIndex++) {\n' +
|
||||||
' iteratee = arguments[iterateeIndex];\n' +
|
' iteratee = arguments[argsIndex];\n' +
|
||||||
(hasDontEnumBug ? ' if (iteratee) {' : ''),
|
(hasDontEnumBug ? ' if (iteratee) {' : ''),
|
||||||
'inLoop':
|
'inLoop':
|
||||||
'if (value && ((isArr = isArray(value)) || isPlainObject(value))) {\n' +
|
'if (value && ((isArr = isArray(value)) || isPlainObject(value))) {\n' +
|
||||||
|
|||||||
Reference in New Issue
Block a user