Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Unified Diff: test/mjsunit/strict-mode.js

Issue 6386014: Fix V8 bug 1084 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR Feedback Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scanner-base.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/strict-mode.js
diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js
index 6f3a2441342d24541202e78b6d8729c1cd989c9f..3cb6d329237b9aa01ff7fda137b4f3725460574c 100644
--- a/test/mjsunit/strict-mode.js
+++ b/test/mjsunit/strict-mode.js
@@ -62,17 +62,17 @@ function CheckFunctionConstructorStrictMode() {
}
// Incorrect 'use strict' directive.
-function UseStrictEscape() {
+(function UseStrictEscape() {
"use\\x20strict";
with ({}) {};
-}
+})();
// 'use strict' in non-directive position.
-function UseStrictNonDirective() {
+(function UseStrictNonDirective() {
void(0);
"use strict";
with ({}) {};
-}
+})();
// Multiple directives, including "use strict".
assertThrows('\
@@ -87,47 +87,47 @@ with({}) {}', SyntaxError);
CheckStrictMode("with({}) {}", SyntaxError);
// Function named 'eval'.
-CheckStrictMode("function eval() {}", SyntaxError)
+CheckStrictMode("function eval() {}", SyntaxError);
// Function named 'arguments'.
-CheckStrictMode("function arguments() {}", SyntaxError)
+CheckStrictMode("function arguments() {}", SyntaxError);
// Function parameter named 'eval'.
-CheckStrictMode("function foo(a, b, eval, c, d) {}", SyntaxError)
+CheckStrictMode("function foo(a, b, eval, c, d) {}", SyntaxError);
// Function parameter named 'arguments'.
-CheckStrictMode("function foo(a, b, arguments, c, d) {}", SyntaxError)
+CheckStrictMode("function foo(a, b, arguments, c, d) {}", SyntaxError);
// Property accessor parameter named 'eval'.
-CheckStrictMode("var o = { set foo(eval) {} }", SyntaxError)
+CheckStrictMode("var o = { set foo(eval) {} }", SyntaxError);
// Property accessor parameter named 'arguments'.
-CheckStrictMode("var o = { set foo(arguments) {} }", SyntaxError)
+CheckStrictMode("var o = { set foo(arguments) {} }", SyntaxError);
// Duplicate function parameter name.
-CheckStrictMode("function foo(a, b, c, d, b) {}", SyntaxError)
+CheckStrictMode("function foo(a, b, c, d, b) {}", SyntaxError);
// Function constructor: eval parameter name.
-CheckFunctionConstructorStrictMode("eval")
+CheckFunctionConstructorStrictMode("eval");
// Function constructor: arguments parameter name.
-CheckFunctionConstructorStrictMode("arguments")
+CheckFunctionConstructorStrictMode("arguments");
// Function constructor: duplicate parameter name.
-CheckFunctionConstructorStrictMode("a", "b", "c", "b")
-CheckFunctionConstructorStrictMode("a,b,c,b")
+CheckFunctionConstructorStrictMode("a", "b", "c", "b");
+CheckFunctionConstructorStrictMode("a,b,c,b");
// catch(eval)
-CheckStrictMode("try{}catch(eval){};", SyntaxError)
+CheckStrictMode("try{}catch(eval){};", SyntaxError);
// catch(arguments)
-CheckStrictMode("try{}catch(arguments){};", SyntaxError)
+CheckStrictMode("try{}catch(arguments){};", SyntaxError);
// var eval
-CheckStrictMode("var eval;", SyntaxError)
+CheckStrictMode("var eval;", SyntaxError);
// var arguments
-CheckStrictMode("var arguments;", SyntaxError)
+CheckStrictMode("var arguments;", SyntaxError);
// Strict mode applies to the function in which the directive is used..
assertThrows('\
@@ -136,12 +136,12 @@ function foo(eval) {\
}', SyntaxError);
// Strict mode doesn't affect the outer stop of strict code.
-function NotStrict(eval) {
+(function NotStrict(eval) {
function Strict() {
"use strict";
}
with ({}) {};
-}
+})();
// Octal literal
CheckStrictMode("var x = 012");
@@ -150,6 +150,12 @@ CheckStrictMode("'Hello octal\\032'");
CheckStrictMode("function octal() { return 012; }");
CheckStrictMode("function octal() { return '\\032'; }");
+(function ValidEscape() {
+ "use strict";
+ var x = '\0';
+ var y = "\0";
+})();
+
// Octal before "use strict"
assertThrows('\
function strict() {\
@@ -158,110 +164,110 @@ assertThrows('\
}', SyntaxError);
// Duplicate data properties.
-CheckStrictMode("var x = { dupe : 1, nondupe: 3, dupe : 2 };", SyntaxError)
-CheckStrictMode("var x = { '1234' : 1, '2345' : 2, '1234' : 3 };", SyntaxError)
-CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };", SyntaxError)
-CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError)
-CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError)
-CheckStrictMode("var x = { 123: 1, 123.00000000000000000000000000000000000000000000000000000000000000000001 : 2 }", SyntaxError)
+CheckStrictMode("var x = { dupe : 1, nondupe: 3, dupe : 2 };", SyntaxError);
+CheckStrictMode("var x = { '1234' : 1, '2345' : 2, '1234' : 3 };", SyntaxError);
+CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };", SyntaxError);
+CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError);
+CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError);
+CheckStrictMode("var x = { 123: 1, 123.00000000000000000000000000000000000000000000000000000000000000000001 : 2 }", SyntaxError);
// Non-conflicting data properties.
-function StrictModeNonDuplicate() {
+(function StrictModeNonDuplicate() {
"use strict";
var x = { 123 : 1, "0123" : 2 };
var x = { 123: 1, '123.00000000000000000000000000000000000000000000000000000000000000000001' : 2 }
-}
+})();
// Two getters (non-strict)
-assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError)
-assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError)
-assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError)
+assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError);
+assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError);
+assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError);
// Two setters (non-strict)
-assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError)
-assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError)
-assertThrows("var x = { set 13(v) { }, set '13'(v) { } };", SyntaxError)
+assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError);
+assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError);
+assertThrows("var x = { set 13(v) { }, set '13'(v) { } };", SyntaxError);
// Setter and data (non-strict)
-assertThrows("var x = { foo: 'data', set foo(v) { } };", SyntaxError)
-assertThrows("var x = { set foo(v) { }, foo: 'data' };", SyntaxError)
-assertThrows("var x = { foo: 'data', set 'foo'(v) { } };", SyntaxError)
-assertThrows("var x = { set foo(v) { }, 'foo': 'data' };", SyntaxError)
-assertThrows("var x = { 'foo': 'data', set foo(v) { } };", SyntaxError)
-assertThrows("var x = { set 'foo'(v) { }, foo: 'data' };", SyntaxError)
-assertThrows("var x = { 'foo': 'data', set 'foo'(v) { } };", SyntaxError)
-assertThrows("var x = { set 'foo'(v) { }, 'foo': 'data' };", SyntaxError)
+assertThrows("var x = { foo: 'data', set foo(v) { } };", SyntaxError);
+assertThrows("var x = { set foo(v) { }, foo: 'data' };", SyntaxError);
+assertThrows("var x = { foo: 'data', set 'foo'(v) { } };", SyntaxError);
+assertThrows("var x = { set foo(v) { }, 'foo': 'data' };", SyntaxError);
+assertThrows("var x = { 'foo': 'data', set foo(v) { } };", SyntaxError);
+assertThrows("var x = { set 'foo'(v) { }, foo: 'data' };", SyntaxError);
+assertThrows("var x = { 'foo': 'data', set 'foo'(v) { } };", SyntaxError);
+assertThrows("var x = { set 'foo'(v) { }, 'foo': 'data' };", SyntaxError);
assertThrows("var x = { 12: 1, set '12'(v){}};", SyntaxError);
assertThrows("var x = { 12: 1, set 12(v){}};", SyntaxError);
assertThrows("var x = { '12': 1, set '12'(v){}};", SyntaxError);
assertThrows("var x = { '12': 1, set 12(v){}};", SyntaxError);
// Getter and data (non-strict)
-assertThrows("var x = { foo: 'data', get foo() { } };", SyntaxError)
-assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError)
-assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError)
-assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError)
+assertThrows("var x = { foo: 'data', get foo() { } };", SyntaxError);
+assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError);
+assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError);
+assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError);
assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError);
assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError);
// Assignment to eval or arguments
-CheckStrictMode("function strict() { eval = undefined; }", SyntaxError)
-CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError)
-CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError)
-CheckStrictMode("function strict() { print(arguments = undefined); }", SyntaxError)
-CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError)
-CheckStrictMode("function strict() { var x = arguments = undefined; }", SyntaxError)
+CheckStrictMode("function strict() { eval = undefined; }", SyntaxError);
+CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError);
+CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError);
+CheckStrictMode("function strict() { print(arguments = undefined); }", SyntaxError);
+CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError);
+CheckStrictMode("function strict() { var x = arguments = undefined; }", SyntaxError);
// Compound assignment to eval or arguments
-CheckStrictMode("function strict() { eval *= undefined; }", SyntaxError)
-CheckStrictMode("function strict() { arguments /= undefined; }", SyntaxError)
-CheckStrictMode("function strict() { print(eval %= undefined); }", SyntaxError)
-CheckStrictMode("function strict() { print(arguments %= undefined); }", SyntaxError)
-CheckStrictMode("function strict() { var x = eval += undefined; }", SyntaxError)
-CheckStrictMode("function strict() { var x = arguments -= undefined; }", SyntaxError)
-CheckStrictMode("function strict() { eval <<= undefined; }", SyntaxError)
-CheckStrictMode("function strict() { arguments >>= undefined; }", SyntaxError)
-CheckStrictMode("function strict() { print(eval >>>= undefined); }", SyntaxError)
-CheckStrictMode("function strict() { print(arguments &= undefined); }", SyntaxError)
-CheckStrictMode("function strict() { var x = eval ^= undefined; }", SyntaxError)
-CheckStrictMode("function strict() { var x = arguments |= undefined; }", SyntaxError)
+CheckStrictMode("function strict() { eval *= undefined; }", SyntaxError);
+CheckStrictMode("function strict() { arguments /= undefined; }", SyntaxError);
+CheckStrictMode("function strict() { print(eval %= undefined); }", SyntaxError);
+CheckStrictMode("function strict() { print(arguments %= undefined); }", SyntaxError);
+CheckStrictMode("function strict() { var x = eval += undefined; }", SyntaxError);
+CheckStrictMode("function strict() { var x = arguments -= undefined; }", SyntaxError);
+CheckStrictMode("function strict() { eval <<= undefined; }", SyntaxError);
+CheckStrictMode("function strict() { arguments >>= undefined; }", SyntaxError);
+CheckStrictMode("function strict() { print(eval >>>= undefined); }", SyntaxError);
+CheckStrictMode("function strict() { print(arguments &= undefined); }", SyntaxError);
+CheckStrictMode("function strict() { var x = eval ^= undefined; }", SyntaxError);
+CheckStrictMode("function strict() { var x = arguments |= undefined; }", SyntaxError);
// Postfix increment with eval or arguments
-CheckStrictMode("function strict() { eval++; }", SyntaxError)
-CheckStrictMode("function strict() { arguments++; }", SyntaxError)
-CheckStrictMode("function strict() { print(eval++); }", SyntaxError)
-CheckStrictMode("function strict() { print(arguments++); }", SyntaxError)
-CheckStrictMode("function strict() { var x = eval++; }", SyntaxError)
-CheckStrictMode("function strict() { var x = arguments++; }", SyntaxError)
+CheckStrictMode("function strict() { eval++; }", SyntaxError);
+CheckStrictMode("function strict() { arguments++; }", SyntaxError);
+CheckStrictMode("function strict() { print(eval++); }", SyntaxError);
+CheckStrictMode("function strict() { print(arguments++); }", SyntaxError);
+CheckStrictMode("function strict() { var x = eval++; }", SyntaxError);
+CheckStrictMode("function strict() { var x = arguments++; }", SyntaxError);
// Postfix decrement with eval or arguments
-CheckStrictMode("function strict() { eval--; }", SyntaxError)
-CheckStrictMode("function strict() { arguments--; }", SyntaxError)
-CheckStrictMode("function strict() { print(eval--); }", SyntaxError)
-CheckStrictMode("function strict() { print(arguments--); }", SyntaxError)
-CheckStrictMode("function strict() { var x = eval--; }", SyntaxError)
-CheckStrictMode("function strict() { var x = arguments--; }", SyntaxError)
+CheckStrictMode("function strict() { eval--; }", SyntaxError);
+CheckStrictMode("function strict() { arguments--; }", SyntaxError);
+CheckStrictMode("function strict() { print(eval--); }", SyntaxError);
+CheckStrictMode("function strict() { print(arguments--); }", SyntaxError);
+CheckStrictMode("function strict() { var x = eval--; }", SyntaxError);
+CheckStrictMode("function strict() { var x = arguments--; }", SyntaxError);
// Prefix increment with eval or arguments
-CheckStrictMode("function strict() { ++eval; }", SyntaxError)
-CheckStrictMode("function strict() { ++arguments; }", SyntaxError)
-CheckStrictMode("function strict() { print(++eval); }", SyntaxError)
-CheckStrictMode("function strict() { print(++arguments); }", SyntaxError)
-CheckStrictMode("function strict() { var x = ++eval; }", SyntaxError)
-CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError)
+CheckStrictMode("function strict() { ++eval; }", SyntaxError);
+CheckStrictMode("function strict() { ++arguments; }", SyntaxError);
+CheckStrictMode("function strict() { print(++eval); }", SyntaxError);
+CheckStrictMode("function strict() { print(++arguments); }", SyntaxError);
+CheckStrictMode("function strict() { var x = ++eval; }", SyntaxError);
+CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError);
// Prefix decrement with eval or arguments
-CheckStrictMode("function strict() { --eval; }", SyntaxError)
-CheckStrictMode("function strict() { --arguments; }", SyntaxError)
-CheckStrictMode("function strict() { print(--eval); }", SyntaxError)
-CheckStrictMode("function strict() { print(--arguments); }", SyntaxError)
-CheckStrictMode("function strict() { var x = --eval; }", SyntaxError)
-CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError)
+CheckStrictMode("function strict() { --eval; }", SyntaxError);
+CheckStrictMode("function strict() { --arguments; }", SyntaxError);
+CheckStrictMode("function strict() { print(--eval); }", SyntaxError);
+CheckStrictMode("function strict() { print(--arguments); }", SyntaxError);
+CheckStrictMode("function strict() { var x = --eval; }", SyntaxError);
+CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError);
// Prefix unary operators other than delete, ++, -- are valid in strict mode
-function StrictModeUnaryOperators() {
+(function StrictModeUnaryOperators() {
"use strict";
var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval];
var y = [void arguments, typeof arguments,
+arguments, -arguments, ~arguments, !arguments];
-}
+})();
« no previous file with comments | « src/scanner-base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698