Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index 0dbfe5d18522d4799207318a42f22f879fd08f35..ecc14782792147f1545eb61774680165d6394f46 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -289,7 +289,7 @@ FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, |
Scope* function_scope = |
NewScope(scope, FUNCTION_SCOPE, FunctionKind::kDefaultConstructor); |
function_scope->SetLanguageMode( |
- static_cast<LanguageMode>(scope->language_mode() | STRICT)); |
+ static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); |
// Set start and end position to the same value |
function_scope->set_start_position(pos); |
function_scope->set_end_position(pos); |
@@ -1145,13 +1145,23 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, |
if ((e_stat = stat->AsExpressionStatement()) != NULL && |
(literal = e_stat->expression()->AsLiteral()) != NULL && |
literal->raw_value()->IsString()) { |
- // Check "use strict" directive (ES5 14.1) and "use asm" directive. Only |
- // one can be present. |
- if (is_sloppy(language_mode()) && |
+ // Check "use strict" directive (ES5 14.1), "use asm" directive, and |
+ // "use sanity" directive (experimental). Only one can be present. |
+ bool use_strict_found = |
+ is_sloppy(language_mode()) && |
literal->raw_value()->AsString() == |
ast_value_factory()->use_strict_string() && |
token_loc.end_pos - token_loc.beg_pos == |
- ast_value_factory()->use_strict_string()->length() + 2) { |
+ ast_value_factory()->use_strict_string()->length() + 2; |
+ bool use_sanity_found = |
arv (Not doing code reviews)
2015/02/04 16:17:11
Don't we want a flag for this work?
rossberg
2015/02/04 16:19:57
Ah, excellent point! Yes, we need a flag. I sugges
marja
2015/02/05 12:11:37
Done.
|
+ !use_strict_found && !is_sane(language_mode()) && |
rossberg
2015/02/04 16:18:09
If I read this correctly then
"use sanity"; "us
marja
2015/02/05 12:11:37
Done. (Oops, preparser was already following that
|
+ literal->raw_value()->AsString() == |
+ ast_value_factory()->use_sanity_string() && |
+ token_loc.end_pos - token_loc.beg_pos == |
+ ast_value_factory()->use_sanity_string()->length() + 2; |
+ if (use_strict_found || use_sanity_found) { |
+ // Sane mode implies strict mode. |
+ |
// TODO(mstarzinger): Global strict eval calls, need their own scope |
// as specified in ES5 10.4.2(3). The correct fix would be to always |
// add this scope in DoParseProgram(), but that requires adaptations |
@@ -1170,8 +1180,14 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, |
mode_ = PARSE_EAGERLY; |
} |
scope_->SetLanguageMode( |
- static_cast<LanguageMode>(scope_->language_mode() | STRICT)); |
- // "use strict" is the only directive for now. |
+ static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
+ |
+ if (use_sanity_found) { |
+ scope_->SetLanguageMode( |
+ static_cast<LanguageMode>(scope_->language_mode() | SANE_BIT)); |
+ } |
+ |
+ // Don't allow additional directives. |
directive_prologue = false; |
} else if (literal->raw_value()->AsString() == |
ast_value_factory()->use_asm_string() && |
@@ -1181,6 +1197,8 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, |
// incremented after parsing is done. |
++use_counts_[v8::Isolate::kUseAsm]; |
scope_->SetAsmModule(); |
+ // Don't allow additional directives. |
+ directive_prologue = false; |
} |
} else { |
// End of the directive prologue. |
@@ -1257,7 +1275,7 @@ Module* Parser::ParseModule(bool* ok) { |
scope->set_start_position(scanner()->location().beg_pos); |
scope->SetLanguageMode( |
- static_cast<LanguageMode>(scope->language_mode() | STRICT)); |
+ static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); |
{ |
BlockState block_state(&scope_, scope); |
@@ -4036,7 +4054,7 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, |
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
BlockState block_state(&scope_, block_scope); |
scope_->SetLanguageMode( |
- static_cast<LanguageMode>(scope_->language_mode() | STRICT)); |
+ static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
scope_->SetScopeName(name); |
VariableProxy* proxy = NULL; |