Commit aa779b38 authored by mmaly@chromium.org's avatar mmaly@chromium.org

Fix V8 bug 1084: allow "\0" in strict mode as valid escape sequence.

http://code.google.com/p/v8/issues/detail?id=1084

Code Review URL: http://codereview.chromium.org/6386014/

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6550 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a38a8ffa
......@@ -99,9 +99,9 @@ uc32 Scanner::ScanHexEscape(uc32 c, int length) {
// Octal escapes of the forms '\0xx' and '\xxx' are not a part of
// ECMA-262. Other JS VMs support them.
uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
octal_pos_ = source_pos() - 1; // Already advanced
uc32 x = c - '0';
for (int i = 0; i < length; i++) {
int i = 0;
for (; i < length; i++) {
int d = c0_ - '0';
if (d < 0 || d > 7) break;
int nx = x * 8 + d;
......@@ -109,6 +109,12 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
x = nx;
Advance();
}
// Anything excelt '\0' is an octal escape sequence, illegal in strict mode.
// Remember the position of octal escape sequences so that better error
// can be reported later (in strict mode).
if (c != '0' || i > 0) {
octal_pos_ = source_pos() - i - 1; // Already advanced
}
return x;
}
......
......@@ -409,6 +409,8 @@ class Scanner {
}
uc32 ScanHexEscape(uc32 c, int length);
// Scans octal escape sequence. Also accepts "\0" decimal escape sequence.
uc32 ScanOctalEscape(uc32 c, int length);
// Return the current source position.
......
......@@ -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 newline at end of file
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment