Ensure that _.transform checks that object is an object before using it as the accumulator [[Prototype]].

This commit is contained in:
John-David Dalton
2014-04-28 08:39:35 -07:00
parent 68702ca43f
commit 2c4657355f
2 changed files with 8 additions and 3 deletions

View File

@@ -6945,9 +6945,10 @@
if (isArr) {
accumulator = [];
} else {
var ctor = object && object.constructor,
proto = ctor && ctor.prototype;
if (isObject(object)) {
var ctor = object.constructor,
proto = ctor && ctor.prototype;
}
accumulator = baseCreate(proto);
}
}

View File

@@ -9404,6 +9404,10 @@
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({
'array': [1, 2, 3],
'object': { 'a': 1, 'b': 2, 'c': 3 }