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

Unified Diff: src/preparser.h

Issue 894683003: Introduce LanguageMode, drop StrictMode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: . Created 5 years, 11 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
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 67a559c77f4367b49218607d8c0f66aaa41e5013..b1b5e4389885111bf5a5b174f1f21a3406dd0526 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -470,7 +470,7 @@ class ParserBase : public Traits {
return function_state_->factory();
}
- StrictMode strict_mode() { return scope_->strict_mode(); }
+ LanguageMode language_mode() { return scope_->language_mode(); }
bool is_generator() const { return function_state_->is_generator(); }
// Report syntax errors.
@@ -1010,12 +1010,14 @@ class PreParserScope {
explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type,
void* = NULL)
: scope_type_(scope_type) {
- strict_mode_ = outer_scope ? outer_scope->strict_mode() : SLOPPY;
+ language_mode_ = outer_scope ? outer_scope->language_mode() : SLOPPY;
}
ScopeType type() { return scope_type_; }
- StrictMode strict_mode() const { return strict_mode_; }
- void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; }
+ LanguageMode language_mode() const { return language_mode_; }
+ void SetLanguageMode(LanguageMode language_mode) {
+ language_mode_ = language_mode;
+ }
void SetScopeName(PreParserIdentifier name) {}
// When PreParser is in use, lazy compilation is already being done,
@@ -1037,7 +1039,7 @@ class PreParserScope {
private:
ScopeType scope_type_;
- StrictMode strict_mode_;
+ LanguageMode language_mode_;
};
@@ -1527,7 +1529,7 @@ class PreParser : public ParserBase<PreParserTraits> {
if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) {
ReportUnexpectedToken(scanner()->current_token());
- } else if (scope_->strict_mode() == STRICT) {
+ } else if (is_strict(scope_->language_mode())) {
CheckStrictOctalLiteral(start_position, scanner()->location().end_pos,
&ok);
}
@@ -1545,9 +1547,8 @@ class PreParser : public ParserBase<PreParserTraits> {
// keyword and parameters, and have consumed the initial '{'.
// At return, unless an error occurred, the scanner is positioned before the
// the final '}'.
- PreParseResult PreParseLazyFunction(StrictMode strict_mode,
- bool is_generator,
- ParserRecorder* log);
+ PreParseResult PreParseLazyFunction(LanguageMode language_mode,
+ bool is_generator, ParserRecorder* log);
private:
friend class PreParserTraits;
@@ -1706,8 +1707,10 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
case Token::STATIC:
case Token::YIELD:
case Token::FUTURE_STRICT_RESERVED_WORD:
- return ReportMessageAt(source_location, strict_mode() == SLOPPY
- ? "unexpected_token_identifier" : "unexpected_strict_reserved");
+ return ReportMessageAt(source_location,
+ is_strict(language_mode())
+ ? "unexpected_strict_reserved"
+ : "unexpected_token_identifier");
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL:
return Traits::ReportMessageAt(source_location,
@@ -1728,14 +1731,14 @@ typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier(
if (next == Token::IDENTIFIER) {
IdentifierT name = this->GetSymbol(scanner());
if (allow_eval_or_arguments == kDontAllowEvalOrArguments &&
- strict_mode() == STRICT && this->IsEvalOrArguments(name)) {
+ is_strict(language_mode()) && this->IsEvalOrArguments(name)) {
ReportMessage("strict_eval_arguments");
*ok = false;
}
if (name->IsArguments(this->ast_value_factory()))
scope_->RecordArgumentsUsage();
return name;
- } else if (strict_mode() == SLOPPY &&
+ } else if (!is_strict(language_mode()) &&
(next == Token::FUTURE_STRICT_RESERVED_WORD ||
next == Token::LET || next == Token::STATIC ||
(next == Token::YIELD && !is_generator()))) {
@@ -1932,7 +1935,7 @@ ParserBase<Traits>::ParsePrimaryExpression(bool* ok) {
case Token::CLASS: {
Consume(Token::CLASS);
- if (!allow_harmony_sloppy() && strict_mode() == SLOPPY) {
+ if (!allow_harmony_sloppy() && !is_strict(language_mode())) {
ReportMessage("sloppy_lexical", NULL);
*ok = false;
break;
@@ -2186,7 +2189,7 @@ ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker,
is_static, *is_computed_name);
} else if (!in_class && allow_harmony_object_literals_ &&
- Token::IsIdentifier(name_token, strict_mode(),
+ Token::IsIdentifier(name_token, language_mode(),
this->is_generator())) {
DCHECK(!*is_computed_name);
DCHECK(!is_static);
@@ -2507,7 +2510,7 @@ ParserBase<Traits>::ParseUnaryExpression(bool* ok) {
ExpressionT expression = ParseUnaryExpression(CHECK_OK);
// "delete identifier" is a syntax error in strict mode.
- if (op == Token::DELETE && strict_mode() == STRICT &&
+ if (op == Token::DELETE && is_strict(language_mode()) &&
this->IsIdentifier(expression)) {
ReportMessage("strict_delete");
*ok = false;
@@ -2875,12 +2878,12 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
CHECK_OK);
// Validate strict mode.
- if (strict_mode() == STRICT) {
+ if (is_strict(language_mode())) {
CheckStrictOctalLiteral(start_pos, scanner()->location().end_pos,
CHECK_OK);
}
- if (allow_harmony_scoping() && strict_mode() == STRICT)
+ if (allow_harmony_scoping() && is_strict(language_mode()))
this->CheckConflictingVarDeclarations(scope, CHECK_OK);
}
@@ -2997,7 +3000,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<
Traits>::CheckAndRewriteReferenceExpression(ExpressionT expression,
Scanner::Location location,
const char* message, bool* ok) {
- if (strict_mode() == STRICT && this->IsIdentifier(expression) &&
+ if (is_strict(language_mode()) && this->IsIdentifier(expression) &&
this->IsEvalOrArguments(this->AsIdentifier(expression))) {
this->ReportMessageAt(location, "strict_eval_arguments", false);
*ok = false;

Powered by Google App Engine
This is Rietveld 408576698