Fix error in rest parameter length optimization (#3573)

If there aren’t enough arguments to get to the offset index, we would
return an negative length.
This commit is contained in:
Justin Ridgewell
2016-07-12 21:12:45 -04:00
committed by Henry Zhu
parent 57ef3ea8eb
commit 823ffbd87c
4 changed files with 25 additions and 20 deletions

View File

@@ -0,0 +1,8 @@
var length = function (a, b, ...items) {
return items.length;
};
assert.equal(length(), 0);
assert.equal(length(1), 0);
assert.equal(length(1, 2), 0);
assert.equal(length(1, 2, 3), 1);

View File

@@ -1,6 +1,6 @@
var t = function (f) {
arguments.length <= 1 ? undefined : arguments[1];
arguments.length <= arguments.length - 1 - 1 + 1 ? undefined : arguments[arguments.length - 1 - 1 + 1];
arguments.length <= (arguments.length <= 1 ? 0 : arguments.length - 1) - 1 + 1 ? undefined : arguments[(arguments.length <= 1 ? 0 : arguments.length - 1) - 1 + 1];
};
function t(f) {
@@ -11,4 +11,4 @@ function t(f) {
items;
items[0];
items[items.length - 1];
}
}

View File

@@ -63,11 +63,11 @@ var b = function () {
};
var b = function (foo) {
return (arguments.length - 1) * 2;
return (arguments.length <= 1 ? 0 : arguments.length - 1) * 2;
};
var b = function (foo, baz) {
return arguments.length - 2;
return arguments.length <= 2 ? 0 : arguments.length - 2;
};
function x() {
@@ -193,4 +193,4 @@ function postfixDecrement() {
}
rest[0]--;
}
}