Index: src/preparser.h |
diff --git a/src/preparser.h b/src/preparser.h |
index b783d65db32468c6395a76ecd046399cd6d851c6..ae01a613db1a8ccd5cc01eb27fe6677d043e38e4 100644 |
--- a/src/preparser.h |
+++ b/src/preparser.h |
@@ -75,6 +75,11 @@ typedef int Arguments; |
class PreParser { |
public: |
+ enum PreParseResult { |
+ kPreParseStackOverflow, |
+ kPreParseSuccess |
+ }; |
+ |
PreParser() : scope_(NULL), allow_lazy_(true) { } |
fschneider
2010/11/29 12:27:35
stack_limit_ and stack_overflow_ should be initial
Lasse Reichstein
2010/11/29 13:06:40
Not really. In fact, allow_lazy_ shouldn't be init
|
~PreParser() { } |
@@ -82,20 +87,22 @@ class PreParser { |
// success (even if parsing failed, the pre-parse data successfully |
// captured the syntax error), and false if a stack-overflow happened |
// during parsing. |
- bool PreParseProgram(i::JavaScriptScanner* scanner, |
- i::ParserRecorder* log, |
- bool allow_lazy) { |
+ PreParseResult PreParseProgram(i::JavaScriptScanner* scanner, |
+ i::ParserRecorder* log, |
+ bool allow_lazy, |
+ uintptr_t stack_limit) { |
allow_lazy_ = allow_lazy; |
scanner_ = scanner; |
log_ = log; |
+ stack_limit_ = stack_limit; |
+ stack_overflow_ = false; |
Scope top_scope(&scope_, kTopLevelScope); |
bool ok = true; |
ParseSourceElements(i::Token::EOS, &ok); |
- bool stack_overflow = scanner_->stack_overflow(); |
- if (!ok && !stack_overflow) { |
+ if (!ok && !stack_overflow_) { |
ReportUnexpectedToken(scanner_->current_token()); |
} |
- return !stack_overflow; |
+ return stack_overflow_ ? kPreParseStackOverflow : kPreParseSuccess; |
} |
private: |
@@ -202,16 +209,26 @@ class PreParser { |
unsigned int HexDigitValue(char digit); |
Expression GetStringSymbol(); |
+ i::Token::Value peek() { |
+ if (stack_overflow_) return i::Token::ILLEGAL; |
+ return scanner_->peek(); |
+ } |
- i::Token::Value peek() { return scanner_->peek(); } |
i::Token::Value Next() { |
- i::Token::Value next = scanner_->Next(); |
- return next; |
+ if (stack_overflow_) return i::Token::ILLEGAL; |
+ { |
+ int marker; |
+ if (reinterpret_cast<uintptr_t>(&marker) < stack_limit_) { |
+ // Further calls to peek/Next will return illegal token. |
+ // The current one will still be returned. It might already |
+ // have been seen using peek. |
+ stack_overflow_ = true; |
+ } |
+ } |
+ return scanner_->Next(); |
} |
- void Consume(i::Token::Value token) { |
- Next(); |
- } |
+ void Consume(i::Token::Value token) { Next(); } |
void Expect(i::Token::Value token, bool* ok) { |
if (Next() != token) { |
@@ -234,6 +251,8 @@ class PreParser { |
i::JavaScriptScanner* scanner_; |
i::ParserRecorder* log_; |
Scope* scope_; |
+ uintptr_t stack_limit_; |
+ bool stack_overflow_; |
bool allow_lazy_; |
}; |
} } // v8::preparser |