Skip to content

Commit

Permalink
concat test, make sure to slice arguments in array.concat
Browse files Browse the repository at this point in the history
  • Loading branch information
charliesome committed Jan 10, 2012
1 parent 205d325 commit 3f67eae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/twostroke/runtime/lib/array.js
Expand Up @@ -26,7 +26,7 @@ Array.prototype.concat = function() {
Array.prototype.slice.call(this).forEach(function(el) {
x.push(el);
});
arguments.forEach(function(obj) {
Array.prototype.slice.call(arguments).forEach(function(obj) {
if(obj instanceof Array) {
obj.forEach(function(el) {
x.push(el);
Expand Down
16 changes: 16 additions & 0 deletions test/array.js
Expand Up @@ -52,4 +52,20 @@ test("length=", function() {
var a = [1,2,3,4,5,6,7];
a.length = 4;
assert("1,2,3,4" == a);
});

test("concat", function() {
var a = [];

assert(a.concat(1,2,3) == "1,2,3");
assert(a == "", "concat mutated array");

assert(a.concat([1,2,3],4,[5]) == "1,2,3,4,5");
assert(a == "", "concat mutated array");

var b = [1,2,3];
assert(b.concat() == "1,2,3");
assert(b.concat() !== b);

assert(Array.prototype.concat.call({ length: 2, 0: 1, 1: 2 }, [3, 4]) == "1,2,3,4");
});

0 comments on commit 3f67eae

Please sign in to comment.