Reviewers: Lasse Reichstein,
Message:
Set out to implement strict mode checks for function constructor:
new Function("a", "b", "return a+b;")
and it turns out that this already works. Adding tests.
Thanks!
Martin
Description:
Strict mode: function constructor tests.
BUG=
TEST=
Please review this at http://codereview.chromium.org/6364008/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M test/mjsunit/strict-mode.js
Index: test/mjsunit/strict-mode.js
diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js
index
14c00e9d434b77af7e21cc7318401c950db3a8c3..4fde0b2ea2ff7ff855b7997f3de84e2c3c6e047f
100644
--- a/test/mjsunit/strict-mode.js
+++ b/test/mjsunit/strict-mode.js
@@ -44,6 +44,23 @@ function CheckStrictMode(code, exception) {
}", exception);
}
+function CheckFunctionConstructorStrictMode() {
+ var args = [];
+ for (var i = 0; i < arguments.length; i ++) {
+ args[i] = arguments[i];
+ }
+ // Create non-strict function. No exception.
+ args[arguments.length] = "";
+ assertDoesNotThrow(function() {
+ Function.apply(this, args);
+ });
+ // Create strict mode function. Exception expected.
+ args[arguments.length] = "'use strict';";
+ assertThrows(function() {
+ Function.apply(this, args);
+ }, SyntaxError);
+}
+
// Incorrect 'use strict' directive.
function UseStrictEscape() {
"use\\x20strict";
@@ -90,6 +107,16 @@ CheckStrictMode("var o = { set foo(arguments) {} }",
SyntaxError)
// Duplicate function parameter name.
CheckStrictMode("function foo(a, b, c, d, b) {}", SyntaxError)
+// Function constructor: eval parameter name.
+CheckFunctionConstructorStrictMode("eval")
+
+// Function constructor: arguments parameter name.
+CheckFunctionConstructorStrictMode("arguments")
+
+// Function constructor: duplicate parameter name.
+CheckFunctionConstructorStrictMode("a", "b", "c", "b")
+CheckFunctionConstructorStrictMode("a,b,c,b")
+
// catch(eval)
CheckStrictMode("try{}catch(eval){};", SyntaxError)
@@ -145,8 +172,6 @@ function StrictModeNonDuplicate() {
var x = { 123:
1, '123.00000000000000000000000000000000000000000000000000000000000000000001' :
2 }
}
-//CheckStrictMode("", SyntaxError)
-
// Two getters (non-strict)
assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError)
assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError)
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev