Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Unified Diff: src/preparser.h

Issue 6927075: Strict mode detection in preparser. (Closed)
Patch Set: Added TODO with bugnumber for R Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/preparse-data-format.h ('k') | src/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « src/preparse-data-format.h ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698