Reviewers: Lasse Reichstein,
Description:
Fix V8 bug 1084
Allow "\0" in strict mode as valid escape sequence.
http://code.google.com/p/v8/issues/detail?id=1084
BUG=http://code.google.com/p/v8/issues/detail?id=1084
TEST=test/mjsunit/strict_mode.js
Please review this at http://codereview.chromium.org/6386014/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/scanner-base.cc
M test/mjsunit/strict-mode.js
Index: src/scanner-base.cc
diff --git a/src/scanner-base.cc b/src/scanner-base.cc
index
e141d0eb70726bddab28d09c3540767cf0ef754d..91ea9e5133afa54905f2e7e71d45d792bd95fbe5
100644
--- a/src/scanner-base.cc
+++ b/src/scanner-base.cc
@@ -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,10 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
x = nx;
Advance();
}
+ // Allow \0 only. Rest are octal escapes, illegal in strict mode.
+ if (c != '\0' || i > 0) {
+ octal_pos_ = source_pos() - i - 1; // Already advanced
+ }
return x;
}
Index: test/mjsunit/strict-mode.js
diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js
index
6f3a2441342d24541202e78b6d8729c1cd989c9f..e6922c59b46bbb0ebf86147e573b63804f9a10b9
100644
--- a/test/mjsunit/strict-mode.js
+++ b/test/mjsunit/strict-mode.js
@@ -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() {\
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev