Reviewers: Michael Starzinger,

Description:
Correctly report octal literals in strict mode when preparsing.

SingletonLogger::LogMessage did not work as advertised and
overwrote existing message.


[email protected]
BUG=v8:2220
TEST=PreparserStrictOctal


Please review this at https://chromiumcodereview.appspot.com/10689134/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/parser.cc
  M test/cctest/test-parsing.cc


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index e4efdf7fa5108b9539364a25b2c80e65dc80f7ed..2dbfeccdd628ab47be91cd6553cfc5d16968b03e 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -4362,6 +4362,7 @@ class SingletonLogger : public ParserRecorder {
                           int end,
                           const char* message,
                           const char* argument_opt) {
+    if (has_error_) return;
     has_error_ = true;
     start_ = start;
     end_ = end;
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 1a4a7f73e0493746d59b4352b17c7d2b1003a84a..288e8d1f3f98c422da5bb50bedff5c896a3aa4fd 100755
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1236,3 +1236,26 @@ TEST(ParserSync) {
     }
   }
 }
+
+
+TEST(PreparserStrictOctal) {
+ // Test that syntax error caused by octal literal is reported correctly as
+  // such (issue 2220).
+  v8::internal::FLAG_min_preparse_length = 1;  // Force preparsing.
+  v8::V8::Initialize();
+  v8::HandleScope scope;
+  v8::Context::Scope context_scope(v8::Context::New());
+  v8::TryCatch try_catch;
+  const char* script =
+      "\"use strict\";       \n"
+      "a = function() {      \n"
+      "  b = function() {    \n"
+      "    01;               \n"
+      "  };                  \n"
+      "};                    \n";
+  v8::Script::Compile(v8::String::New(script));
+  CHECK(try_catch.HasCaught());
+  v8::String::Utf8Value exception(try_catch.Exception());
+  CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
+           *exception);
+}


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to