mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Ensure _.clone handles generators correctly.
This commit is contained in:
@@ -2262,7 +2262,7 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var tag = getTag(value),
|
var tag = getTag(value),
|
||||||
isFunc = tag == funcTag;
|
isFunc = tag == funcTag || tag == genTag;
|
||||||
|
|
||||||
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
||||||
if (isHostObject(value)) {
|
if (isHostObject(value)) {
|
||||||
|
|||||||
34
test/test.js
34
test/test.js
@@ -226,6 +226,11 @@
|
|||||||
/** Used to restore the `_` reference. */
|
/** Used to restore the `_` reference. */
|
||||||
var oldDash = root._;
|
var oldDash = root._;
|
||||||
|
|
||||||
|
/** Used to test generator functions. */
|
||||||
|
var generator = lodashStable.attempt(function() {
|
||||||
|
return Function('return function*(){}');
|
||||||
|
});
|
||||||
|
|
||||||
/** List of latin-1 supplementary letters to basic latin letters. */
|
/** List of latin-1 supplementary letters to basic latin letters. */
|
||||||
var burredLetters = [
|
var burredLetters = [
|
||||||
'\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce',
|
'\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce',
|
||||||
@@ -2219,7 +2224,8 @@
|
|||||||
|
|
||||||
var uncloneable = {
|
var uncloneable = {
|
||||||
'DOM elements': body,
|
'DOM elements': body,
|
||||||
'functions': Foo
|
'functions': Foo,
|
||||||
|
'generators': generator
|
||||||
};
|
};
|
||||||
|
|
||||||
lodashStable.each(errors, function(error) {
|
lodashStable.each(errors, function(error) {
|
||||||
@@ -2452,14 +2458,18 @@
|
|||||||
QUnit.test('`_.' + methodName + '` should not clone ' + key, function(assert) {
|
QUnit.test('`_.' + methodName + '` should not clone ' + key, function(assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
var object = { 'a': value, 'b': { 'c': value } },
|
if (value) {
|
||||||
actual = func(object);
|
var object = { 'a': value, 'b': { 'c': value } },
|
||||||
|
actual = func(object),
|
||||||
|
expected = (typeof value == 'function' && !!value.c) ? { 'c': Foo.c } : {};
|
||||||
|
|
||||||
assert.deepEqual(actual, object);
|
assert.deepEqual(actual, object);
|
||||||
assert.notStrictEqual(actual, object);
|
assert.notStrictEqual(actual, object);
|
||||||
|
assert.deepEqual(func(value), expected);
|
||||||
var expected = typeof value == 'function' ? { 'c': Foo.c } : (value && {});
|
}
|
||||||
assert.deepEqual(func(value), expected);
|
else {
|
||||||
|
skipTest(assert, 3);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -7300,10 +7310,6 @@
|
|||||||
QUnit.test('should return `false` for non-arrays', function(assert) {
|
QUnit.test('should return `false` for non-arrays', function(assert) {
|
||||||
assert.expect(10);
|
assert.expect(10);
|
||||||
|
|
||||||
var generator = lodashStable.attempt(function() {
|
|
||||||
return Function('return function*(){}');
|
|
||||||
});
|
|
||||||
|
|
||||||
var expected = lodashStable.map(falsey, function(value) {
|
var expected = lodashStable.map(falsey, function(value) {
|
||||||
return value === '';
|
return value === '';
|
||||||
});
|
});
|
||||||
@@ -8526,10 +8532,6 @@
|
|||||||
QUnit.test('should return `true` for generator functions', function(assert) {
|
QUnit.test('should return `true` for generator functions', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var generator = lodashStable.attempt(function() {
|
|
||||||
return Function('return function*(){}');
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.strictEqual(_.isFunction(generator), typeof generator == 'function');
|
assert.strictEqual(_.isFunction(generator), typeof generator == 'function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user