Revision: 8199
Author: [email protected]
Date: Tue Jun 7 05:08:20 2011
Log: Merge revision r8194 to 3.1 branch.
Limit the number of arguments in a function call to 32766. This is identical
to the limit on the number of parameters to a function.
BUG=v8:1413
TEST=regress/regress-1122.js
Review URL: http://codereview.chromium.org/7132001
http://code.google.com/p/v8/source/detail?r=8199
Modified:
/branches/3.1/src/messages.js
/branches/3.1/src/parser.cc
/branches/3.1/src/version.cc
/branches/3.1/test/mjsunit/regress/regress-1122.js
=======================================
--- /branches/3.1/src/messages.js Wed Mar 2 05:43:26 2011
+++ /branches/3.1/src/messages.js Tue Jun 7 05:08:20 2011
@@ -211,6 +211,7 @@
invalid_preparser_data: ["Invalid preparser data for
function ", "%0"],
strict_mode_with: ["Strict mode code may not include a
with statement"],
strict_catch_variable: ["Catch variable may not be eval or
arguments in strict mode"],
+ too_many_arguments: ["Too many arguments in function call
(only 32766 allowed)"],
too_many_parameters: ["Too many parameters in function
definition"],
strict_param_name: ["Parameter name eval or arguments is
not allowed in strict mode"],
strict_param_dupe: ["Strict mode function may not have
duplicate parameter names"],
=======================================
--- /branches/3.1/src/parser.cc Mon Mar 14 10:03:58 2011
+++ /branches/3.1/src/parser.cc Tue Jun 7 05:08:20 2011
@@ -3490,6 +3490,12 @@
while (!done) {
Expression* argument = ParseAssignmentExpression(true, CHECK_OK);
result->Add(argument);
+ if (result->length() > kMaxNumFunctionParameters) {
+ ReportMessageAt(scanner().location(), "too_many_arguments",
+ Vector<const char*>::empty());
+ *ok = false;
+ return NULL;
+ }
done = (peek() == Token::RPAREN);
if (!done) Expect(Token::COMMA, CHECK_OK);
}
=======================================
--- /branches/3.1/src/version.cc Tue May 24 08:09:38 2011
+++ /branches/3.1/src/version.cc Tue Jun 7 05:08:20 2011
@@ -35,7 +35,7 @@
#define MAJOR_VERSION 3
#define MINOR_VERSION 1
#define BUILD_NUMBER 8
-#define PATCH_LEVEL 22
+#define PATCH_LEVEL 23
#define CANDIDATE_VERSION false
// Define SONAME to have the SCons build the put a specific SONAME into the
=======================================
--- /branches/3.1/test/mjsunit/regress/regress-1122.js Wed Feb 9 23:45:38
2011
+++ /branches/3.1/test/mjsunit/regress/regress-1122.js Tue Jun 7 05:08:20
2011
@@ -25,12 +25,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test that we can handle functions with up to 32766 arguments, and that
-// functions with more arguments throw an exception.
-
-// See http://code.google.com/p/v8/issues/detail?id=1122.
-
-function function_with_n_args(n) {
+// Test that we can handle function calls with up to 32766 arguments, and
+// that function calls with more arguments throw an exception. Apply a
+// similar limit to the number of function parameters.
+
+// See http://code.google.com/p/v8/issues/detail?id=1122 and
+// http://code.google.com/p/v8/issues/detail?id=1413.
+
+function function_with_n_params_and_m_args(n, m) {
test_prefix = 'prefix ';
test_suffix = ' suffix';
var source = 'test_prefix + (function f(';
@@ -39,7 +41,7 @@
source += 'arg' + arg;
}
source += ') { return arg' + (n - n % 2) / 2 + '; })(';
- for (var arg = 0; arg < n ; arg++) {
+ for (var arg = 0; arg < m ; arg++) {
if (arg != 0) source += ',';
source += arg;
}
@@ -47,9 +49,20 @@
return eval(source);
}
-assertEquals('prefix 4000 suffix', function_with_n_args(8000));
-assertEquals('prefix 9000 suffix', function_with_n_args(18000));
-assertEquals('prefix 16000 suffix', function_with_n_args(32000));
-
-assertThrows("function_with_n_args(35000)");
-assertThrows("function_with_n_args(100000)");
+assertEquals('prefix 4000 suffix',
+ function_with_n_params_and_m_args(8000, 8000));
+assertEquals('prefix 3000 suffix',
+ function_with_n_params_and_m_args(6000, 8000));
+assertEquals('prefix 5000 suffix',
+ function_with_n_params_and_m_args(10000, 8000));
+assertEquals('prefix 9000 suffix',
+ function_with_n_params_and_m_args(18000, 18000));
+assertEquals('prefix 16000 suffix',
+ function_with_n_params_and_m_args(32000, 32000));
+assertEquals('prefix undefined suffix',
+ function_with_n_params_and_m_args(32000, 10000));
+
+assertThrows("function_with_n_params_and_m_args(35000, 35000)");
+assertThrows("function_with_n_params_and_m_args(100000, 100000)");
+assertThrows("function_with_n_params_and_m_args(35000, 30000)");
+assertThrows("function_with_n_params_and_m_args(30000, 35000)");
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev