Index: src/preparser.h |
diff --git a/src/preparser.h b/src/preparser.h |
index b7fa6c73bd4db1eb6c9be286df86576a58758758..93a8a42feaca7b9c49d5e812017581177b07af85 100644 |
--- a/src/preparser.h |
+++ b/src/preparser.h |
@@ -33,7 +33,7 @@ namespace preparser { |
// Preparsing checks a JavaScript program and emits preparse-data that helps |
// a later parsing to be faster. |
-// See preparse-data.h for the data. |
+// See preparse-data-format.h for the data format. |
// The PreParser checks that the syntax follows the grammar for JavaScript, |
// and collects some information about the program along the way. |
@@ -80,14 +80,18 @@ class PreParser { |
// simple this-property assignments. |
enum StatementType { |
- kUnknownStatement |
+ kUnknownStatement, |
+ kStringLiteralExpressionStatement, |
+ kUseStrictExpressionStatement |
}; |
enum ExpressionType { |
kUnknownExpression, |
kIdentifierExpression, // Used to detect labels. |
kThisExpression, |
- kThisPropertyExpression |
+ kThisPropertyExpression, |
+ kStringLiteralExpression, |
+ kUseStrictString |
}; |
enum IdentifierType { |
@@ -95,7 +99,9 @@ class PreParser { |
}; |
enum SourceElementTypes { |
- kUnknownSourceElements |
+ kUnknownSourceElements, |
+ kDirectivePrologue, |
+ kUseStrictDirective |
}; |
typedef int SourceElements; |
@@ -112,7 +118,8 @@ class PreParser { |
type_(type), |
materialized_literal_count_(0), |
expected_properties_(0), |
- with_nesting_count_(0) { |
+ with_nesting_count_(0), |
+ strict_((prev_ != NULL) && prev_->is_strict()) { |
*variable = this; |
} |
~Scope() { *variable_ = prev_; } |
@@ -122,6 +129,8 @@ class PreParser { |
int expected_properties() { return expected_properties_; } |
int materialized_literal_count() { return materialized_literal_count_; } |
bool IsInsideWith() { return with_nesting_count_ != 0; } |
+ bool is_strict() { return strict_; } |
+ void set_strict() { strict_ = true; } |
void EnterWith() { with_nesting_count_++; } |
void LeaveWith() { with_nesting_count_--; } |
@@ -132,6 +141,7 @@ class PreParser { |
int materialized_literal_count_; |
int expected_properties_; |
int with_nesting_count_; |
+ bool strict_; |
}; |
// Private constructor only used in PreParseProgram. |
@@ -152,10 +162,13 @@ class PreParser { |
PreParseResult PreParse() { |
Scope top_scope(&scope_, kTopLevelScope); |
bool ok = true; |
+ int start_position = scanner_->peek_location().beg_pos; |
ParseSourceElements(i::Token::EOS, &ok); |
if (stack_overflow_) return kPreParseStackOverflow; |
if (!ok) { |
ReportUnexpectedToken(scanner_->current_token()); |
+ } else if (scope_->is_strict()) { |
+ CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok); |
} |
return kPreParseSuccess; |
} |
@@ -169,6 +182,8 @@ class PreParser { |
log_->LogMessage(start_pos, end_pos, type, name_opt); |
} |
+ void CheckOctalLiteral(int beg_pos, int end_pos, bool* ok); |
+ |
// All ParseXXX functions take as the last argument an *ok parameter |
// which is set to false if parsing failed; it is unchanged otherwise. |
// By making the 'exception handling' explicit, we are forced to check |
@@ -245,6 +260,12 @@ class PreParser { |
bool peek_any_identifier(); |
+ void set_strict_mode() { |
+ scope_->set_strict(); |
+ } |
+ |
+ bool is_strict_mode() { return scope_->is_strict(); } |
+ |
void Consume(i::Token::Value token) { Next(); } |
void Expect(i::Token::Value token, bool* ok) { |