| Index: src/preparse-data.h
|
| diff --git a/src/preparse-data.h b/src/preparse-data.h
|
| index c1331d044fcfd6148cd9dbb30846c76e3fc1d8bb..04958fb5a60106ccd4c64bf143ebf9a600c89eee 100644
|
| --- a/src/preparse-data.h
|
| +++ b/src/preparse-data.h
|
| @@ -6,6 +6,7 @@
|
| #define V8_PREPARSE_DATA_H_
|
|
|
| #include "src/allocation.h"
|
| +#include "src/ast-value-factory.h"
|
| #include "src/hashmap.h"
|
| #include "src/preparse-data-format.h"
|
| #include "src/utils-inl.h"
|
| @@ -13,15 +14,26 @@
|
| namespace v8 {
|
| namespace internal {
|
|
|
| +class AstRawString;
|
| class ScriptData;
|
|
|
| -
|
| // Abstract interface for preparse data recorder.
|
| class ParserRecorder {
|
| public:
|
| - ParserRecorder() { }
|
| + ParserRecorder() : identifiers_(AstRawString::Compare) {}
|
| virtual ~ParserRecorder() { }
|
|
|
| + // Logs that the next function makes a direct call to eval
|
| + virtual void LogEvalCall() = 0;
|
| +
|
| + // Logs an identifier accessed by the next function
|
| + virtual void LogIdentifier(const AstRawString* identifier) {
|
| + // Lookup will insert the identifier into the HashMap with a NULL value
|
| + // if the key (identifier) is not found
|
| + identifiers_.Lookup(const_cast<AstRawString*>(identifier),
|
| + identifier->hash(), true);
|
| + }
|
| +
|
| // Logs the scope and some details of a function literal in the source.
|
| virtual void LogFunction(int start,
|
| int end,
|
| @@ -37,6 +49,10 @@ class ParserRecorder {
|
| const char* message,
|
| const char* argument_opt,
|
| bool is_reference_error) = 0;
|
| +
|
| + protected:
|
| + HashMap identifiers_;
|
| +
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(ParserRecorder);
|
| };
|
| @@ -45,10 +61,20 @@ class ParserRecorder {
|
| class SingletonLogger : public ParserRecorder {
|
| public:
|
| SingletonLogger()
|
| - : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {}
|
| + : has_error_(false),
|
| + start_(-1),
|
| + end_(-1),
|
| + calls_eval_(false),
|
| + is_reference_error_(false) {}
|
| virtual ~SingletonLogger() {}
|
|
|
| - void Reset() { has_error_ = false; }
|
| + void Reset() {
|
| + has_error_ = false;
|
| + calls_eval_ = false;
|
| + identifiers_.Clear();
|
| + }
|
| +
|
| + virtual void LogEvalCall() { calls_eval_ = true; }
|
|
|
| virtual void LogFunction(int start,
|
| int end,
|
| @@ -80,6 +106,29 @@ class SingletonLogger : public ParserRecorder {
|
| is_reference_error_ = is_reference_error;
|
| }
|
|
|
| + class IdentifierIterator {
|
| + friend class SingletonLogger;
|
| +
|
| + public:
|
| + const AstRawString* Next() {
|
| + if (entry_ == NULL) return NULL;
|
| + const AstRawString* result = static_cast<AstRawString*>(entry_->key);
|
| + entry_ = identifiers_.Next(entry_);
|
| + return result;
|
| + }
|
| +
|
| + private:
|
| + IdentifierIterator(const HashMap& identifiers, HashMap::Entry* entry)
|
| + : identifiers_(identifiers), entry_(entry) {}
|
| +
|
| + const HashMap& identifiers_;
|
| + HashMap::Entry* entry_;
|
| + };
|
| +
|
| + IdentifierIterator IdentifiersStart() {
|
| + return IdentifierIterator(identifiers_, identifiers_.Start());
|
| + }
|
| +
|
| bool has_error() const { return has_error_; }
|
|
|
| int start() const { return start_; }
|
| @@ -96,6 +145,10 @@ class SingletonLogger : public ParserRecorder {
|
| DCHECK(!has_error_);
|
| return strict_mode_;
|
| }
|
| + bool calls_eval() const {
|
| + DCHECK(!has_error_);
|
| + return calls_eval_;
|
| + }
|
| int is_reference_error() const { return is_reference_error_; }
|
| const char* message() {
|
| DCHECK(has_error_);
|
| @@ -114,6 +167,7 @@ class SingletonLogger : public ParserRecorder {
|
| int literals_;
|
| int properties_;
|
| StrictMode strict_mode_;
|
| + bool calls_eval_;
|
| // For error messages.
|
| const char* message_;
|
| const char* argument_opt_;
|
| @@ -131,6 +185,8 @@ class CompleteParserRecorder : public ParserRecorder {
|
| CompleteParserRecorder();
|
| virtual ~CompleteParserRecorder() {}
|
|
|
| + virtual void LogEvalCall() { next_function_calls_eval_ = true; }
|
| +
|
| virtual void LogFunction(int start,
|
| int end,
|
| int literals,
|
| @@ -141,6 +197,14 @@ class CompleteParserRecorder : public ParserRecorder {
|
| function_store_.Add(literals);
|
| function_store_.Add(properties);
|
| function_store_.Add(strict_mode);
|
| + function_store_.Add(next_function_calls_eval_);
|
| + function_store_.Add(identifiers_.occupancy());
|
| + for (HashMap::Entry* p = identifiers_.Start(); p != NULL;
|
| + p = identifiers_.Next(p)) {
|
| + WriteString(static_cast<AstRawString*>(p->key));
|
| + }
|
| + identifiers_.Clear();
|
| + next_function_calls_eval_ = false;
|
| }
|
|
|
| // Logs an error message and marks the log as containing an error.
|
| @@ -163,12 +227,14 @@ class CompleteParserRecorder : public ParserRecorder {
|
|
|
| private:
|
| void WriteString(Vector<const char> str);
|
| + void WriteString(const AstRawString* str);
|
|
|
| // Write a non-negative number to the symbol store.
|
| void WriteNumber(int number);
|
|
|
| Collector<unsigned> function_store_;
|
| unsigned preamble_[PreparseDataConstants::kHeaderSize];
|
| + bool next_function_calls_eval_;
|
|
|
| #ifdef DEBUG
|
| int prev_start_;
|
|
|