Reviewers: rossberg,

Message:
rossberg, ptal

Description:
PreParser fix: propagate reference erros properly.

For example, invalid left hand sides are reference errors. PreParser didn't use
to produce this error ever, so the code for propagating reference errors
properly was missing, and reference errors turned into syntax errors.

[email protected]
BUG=

Please review this at https://codereview.chromium.org/220233006/

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

Affected files (+51, -33 lines):
  M src/parser.h
  M src/parser.cc
  M src/preparse-data.h
  M src/preparse-data.cc
  M src/preparse-data-format.h
  M src/preparser.cc


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index a00adb8c1e0bcacda9b1cd25d7b7eda1a987a7e5..16a1028bf24fa3b75a51f294bec8bdb8d744eb4b 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -304,20 +304,25 @@ const char* ScriptDataImpl::ReadString(unsigned* start, int* chars) {
 }


-Scanner::Location ScriptDataImpl::MessageLocation() {
+Scanner::Location ScriptDataImpl::MessageLocation() const {
   int beg_pos = Read(PreparseDataConstants::kMessageStartPos);
   int end_pos = Read(PreparseDataConstants::kMessageEndPos);
   return Scanner::Location(beg_pos, end_pos);
 }


-const char* ScriptDataImpl::BuildMessage() {
+bool ScriptDataImpl::IsReferenceError() const {
+  return Read(PreparseDataConstants::kIsReferenceErrorPos);
+}
+
+
+const char* ScriptDataImpl::BuildMessage() const {
   unsigned* start = ReadAddress(PreparseDataConstants::kMessageTextPos);
   return ReadString(start, NULL);
 }


-Vector<const char*> ScriptDataImpl::BuildArgs() {
+Vector<const char*> ScriptDataImpl::BuildArgs() const {
   int arg_count = Read(PreparseDataConstants::kMessageArgCountPos);
   const char** array = NewArray<const char*>(arg_count);
   // Position after text found by skipping past length field and
@@ -333,12 +338,12 @@ Vector<const char*> ScriptDataImpl::BuildArgs() {
 }


-unsigned ScriptDataImpl::Read(int position) {
+unsigned ScriptDataImpl::Read(int position) const {
   return store_[PreparseDataConstants::kHeaderSize + position];
 }


-unsigned* ScriptDataImpl::ReadAddress(int position) {
+unsigned* ScriptDataImpl::ReadAddress(int position) const {
   return &store_[PreparseDataConstants::kHeaderSize + position];
 }

@@ -3385,8 +3390,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
           }
           ParserTraits::ReportMessageAt(
               Scanner::Location(logger.start(), logger.end()),
-              logger.message(),
-              args);
+              logger.message(), args, logger.is_reference_error());
           *ok = false;
           return NULL;
         }
@@ -4688,7 +4692,8 @@ bool Parser::Parse() {
       Scanner::Location loc = cached_data->MessageLocation();
       const char* message = cached_data->BuildMessage();
       Vector<const char*> args = cached_data->BuildArgs();
-      ParserTraits::ReportMessageAt(loc, message, args);
+      ParserTraits::ReportMessageAt(loc, message, args,
+                                    cached_data->IsReferenceError());
       DeleteArray(message);
       for (int i = 0; i < args.length(); i++) {
         DeleteArray(args[i]);
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index 4bb9aad5a69459b009138555cc511d0533255a6a..287dfa4a46445a56711af9cb79290a32df6edaef 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -104,9 +104,10 @@ class ScriptDataImpl : public ScriptData {
   int GetSymbolIdentifier();
   bool SanityCheck();

-  Scanner::Location MessageLocation();
-  const char* BuildMessage();
-  Vector<const char*> BuildArgs();
+  Scanner::Location MessageLocation() const;
+  bool IsReferenceError() const;
+  const char* BuildMessage() const;
+  Vector<const char*> BuildArgs() const;

   int symbol_count() {
     return (store_.length() > PreparseDataConstants::kHeaderSize)
@@ -127,8 +128,8 @@ class ScriptDataImpl : public ScriptData {
   int function_index_;
   bool owns_store_;

-  unsigned Read(int position);
-  unsigned* ReadAddress(int position);
+  unsigned Read(int position) const;
+  unsigned* ReadAddress(int position) const;
   // Reads a number from the current symbols
   int ReadNumber(byte** source);

Index: src/preparse-data-format.h
diff --git a/src/preparse-data-format.h b/src/preparse-data-format.h
index e2cf0a1a3e882f3c0158ed64400d8241765d0c78..f5c3a5fbede4b5080a9af7b6880a52b22be088eb 100644
--- a/src/preparse-data-format.h
+++ b/src/preparse-data-format.h
@@ -51,7 +51,8 @@ struct PreparseDataConstants {
   static const int kMessageStartPos = 0;
   static const int kMessageEndPos = 1;
   static const int kMessageArgCountPos = 2;
-  static const int kMessageTextPos = 3;
+  static const int kIsReferenceErrorPos = 3;
+  static const int kMessageTextPos = 4;

   static const unsigned char kNumberTerminator = 0x80u;
 };
Index: src/preparse-data.cc
diff --git a/src/preparse-data.cc b/src/preparse-data.cc
index 9f585a991feadd5c99344cbae31d4c06df2fbfe3..5bc6173e90f07847e2a99c834ae24195a4fa6d3c 100644
--- a/src/preparse-data.cc
+++ b/src/preparse-data.cc
@@ -88,9 +88,10 @@ CompleteParserRecorder::CompleteParserRecorder()


 void CompleteParserRecorder::LogMessage(int start_pos,
-                                               int end_pos,
-                                               const char* message,
-                                               const char* arg_opt) {
+                                        int end_pos,
+                                        const char* message,
+                                        const char* arg_opt,
+                                        bool is_reference_error) {
   if (has_error()) return;
   preamble_[PreparseDataConstants::kHasErrorOffset] = true;
   function_store_.Reset();
@@ -100,7 +101,9 @@ void CompleteParserRecorder::LogMessage(int start_pos,
   function_store_.Add(end_pos);
   STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2);
   function_store_.Add((arg_opt == NULL) ? 0 : 1);
-  STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 3);
+  STATIC_ASSERT(PreparseDataConstants::kIsReferenceErrorPos == 3);
+  function_store_.Add(is_reference_error ? 1 : 0);
+  STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 4);
   WriteString(CStrVector(message));
   if (arg_opt != NULL) WriteString(CStrVector(arg_opt));
   should_log_symbols_ = false;
Index: src/preparse-data.h
diff --git a/src/preparse-data.h b/src/preparse-data.h
index 6a968e3b2241ea7331ff0f3ee6584f10f042d6ff..cfc33fe1319f0434133442ee7ad999d60570f398 100644
--- a/src/preparse-data.h
+++ b/src/preparse-data.h
@@ -55,7 +55,8 @@ class ParserRecorder {
   virtual void LogMessage(int start,
                           int end,
                           const char* message,
-                          const char* argument_opt) = 0;
+                          const char* argument_opt,
+                          bool is_reference_error) = 0;

   // Logs a symbol creation of a literal or identifier.
   bool ShouldLogSymbols() { return should_log_symbols_; }
@@ -80,8 +81,9 @@ class ParserRecorder {

 class SingletonLogger : public ParserRecorder {
  public:
-  SingletonLogger() : has_error_(false), start_(-1), end_(-1) { }
-  virtual ~SingletonLogger() { }
+  SingletonLogger()
+ : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {}
+  virtual ~SingletonLogger() {}

   void Reset() { has_error_ = false; }

@@ -104,36 +106,39 @@ class SingletonLogger : public ParserRecorder {
   virtual void LogMessage(int start,
                           int end,
                           const char* message,
-                          const char* argument_opt) {
+                          const char* argument_opt,
+                          bool is_reference_error) {
     if (has_error_) return;
     has_error_ = true;
     start_ = start;
     end_ = end;
     message_ = message;
     argument_opt_ = argument_opt;
+    is_reference_error_ = is_reference_error;
   }

-  bool has_error() { return has_error_; }
+  bool has_error() const { return has_error_; }

-  int start() { return start_; }
-  int end() { return end_; }
-  int literals() {
+  int start() const { return start_; }
+  int end() const { return end_; }
+  int literals() const {
     ASSERT(!has_error_);
     return literals_;
   }
-  int properties() {
+  int properties() const {
     ASSERT(!has_error_);
     return properties_;
   }
-  StrictMode strict_mode() {
+  StrictMode strict_mode() const {
     ASSERT(!has_error_);
     return strict_mode_;
   }
+  int is_reference_error() const { return is_reference_error_; }
   const char* message() {
     ASSERT(has_error_);
     return message_;
   }
-  const char* argument_opt() {
+  const char* argument_opt() const {
     ASSERT(has_error_);
     return argument_opt_;
   }
@@ -149,6 +154,7 @@ class SingletonLogger : public ParserRecorder {
   // For error messages.
   const char* message_;
   const char* argument_opt_;
+  bool is_reference_error_;
 };


@@ -180,7 +186,8 @@ class CompleteParserRecorder : public ParserRecorder {
   virtual void LogMessage(int start,
                           int end,
                           const char* message,
-                          const char* argument_opt);
+                          const char* argument_opt,
+                          bool is_reference_error_);

   virtual void PauseRecording() {
     ASSERT(should_log_symbols_);
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index 9bcc88002d03cd1a02c9c6f6942c9e21d8d7b749..4995ed92952940cdcfcdf2d2304cda112332d942 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -83,8 +83,8 @@ void PreParserTraits::ReportMessageAt(Scanner::Location location,
                                       const char* type,
                                       const char* name_opt,
                                       bool is_reference_error) {
-  pre_parser_->log_
-      ->LogMessage(location.beg_pos, location.end_pos, type, name_opt);
+  pre_parser_->log_->LogMessage(location.beg_pos, location.end_pos, type,
+                                name_opt, is_reference_error);
 }


@@ -93,7 +93,8 @@ void PreParserTraits::ReportMessageAt(int start_pos,
                                       const char* type,
                                       const char* name_opt,
                                       bool is_reference_error) {
-  pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt);
+  pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt,
+                                is_reference_error);
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to