mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Ensure that _.transform checks that object is an object before using it as the accumulator [[Prototype]].
This commit is contained in:
@@ -6945,9 +6945,10 @@
|
|||||||
if (isArr) {
|
if (isArr) {
|
||||||
accumulator = [];
|
accumulator = [];
|
||||||
} else {
|
} else {
|
||||||
var ctor = object && object.constructor,
|
if (isObject(object)) {
|
||||||
proto = ctor && ctor.prototype;
|
var ctor = object.constructor,
|
||||||
|
proto = ctor && ctor.prototype;
|
||||||
|
}
|
||||||
accumulator = baseCreate(proto);
|
accumulator = baseCreate(proto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9404,6 +9404,10 @@
|
|||||||
ok(_.transform(new Foo) instanceof Foo);
|
ok(_.transform(new Foo) instanceof Foo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should check that `object` is an object before using it as the `accumulator` `[[Prototype]]', 1, function() {
|
||||||
|
ok(!(_.transform(1) instanceof Number));
|
||||||
|
});
|
||||||
|
|
||||||
_.each({
|
_.each({
|
||||||
'array': [1, 2, 3],
|
'array': [1, 2, 3],
|
||||||
'object': { 'a': 1, 'b': 2, 'c': 3 }
|
'object': { 'a': 1, 'b': 2, 'c': 3 }
|
||||||
|
|||||||
Reference in New Issue
Block a user