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

Unified Diff: src/parser.cc

Issue 8344082: Replace boolean indications of strict mode by an enum value. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Some fixes and adapted the preparser. Created 9 years, 2 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
« src/compiler.cc ('K') | « src/objects-inl.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index cd3dd290aa2b4a8a4a7fb22b7f8bcb198fa81fa5..17155d602c517cd585dd6623bafa60757599c51b 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -636,6 +636,7 @@ FunctionLiteral* Parser::DoParseProgram(Handle<String> source,
bool in_global_context,
StrictModeFlag strict_mode,
ZoneScope* zone_scope) {
+ ASSERT(top_scope_ == NULL);
ASSERT(target_stack_ == NULL);
if (pre_data_ != NULL) pre_data_->Initialize();
@@ -652,9 +653,8 @@ FunctionLiteral* Parser::DoParseProgram(Handle<String> source,
FunctionLiteral* result = NULL;
{ Scope* scope = NewScope(top_scope_, type);
LexicalScope lexical_scope(this, scope, isolate());
- if (strict_mode == kStrictMode) {
- top_scope_->EnableStrictMode();
- }
+ ASSERT(top_scope_->strict_mode_flag() == kNonStrictMode);
+ top_scope_->SetStrictModeFlag(strict_mode);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16);
bool ok = true;
int beg_loc = scanner().location().beg_pos;
@@ -727,6 +727,7 @@ FunctionLiteral* Parser::ParseLazy(CompilationInfo* info,
ZoneScope* zone_scope) {
Handle<SharedFunctionInfo> shared_info = info->shared_info();
scanner_.Initialize(source);
+ ASSERT(top_scope_ == NULL);
ASSERT(target_stack_ == NULL);
Handle<String> name(String::cast(shared_info->name()));
@@ -745,11 +746,10 @@ FunctionLiteral* Parser::ParseLazy(CompilationInfo* info,
scope = Scope::DeserializeScopeChain(info, scope);
}
LexicalScope lexical_scope(this, scope, isolate());
-
- if (shared_info->strict_mode()) {
- top_scope_->EnableStrictMode();
- }
-
+ ASSERT(scope->strict_mode_flag() == kNonStrictMode ||
+ scope->strict_mode_flag() == info->strict_mode_flag());
+ ASSERT(info->strict_mode_flag() == shared_info->strict_mode_flag());
+ scope->SetStrictModeFlag(shared_info->strict_mode_flag());
FunctionLiteral::Type type = shared_info->is_expression()
? (shared_info->is_anonymous()
? FunctionLiteral::ANONYMOUS_EXPRESSION
@@ -1196,7 +1196,7 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
directive->Equals(isolate()->heap()->use_strict()) &&
token_loc.end_pos - token_loc.beg_pos ==
isolate()->heap()->use_strict()->length() + 2) {
- top_scope_->EnableStrictMode();
+ top_scope_->SetStrictModeFlag(kStrictMode);
// "use strict" is the only directive for now.
directive_prologue = false;
}
@@ -1596,9 +1596,6 @@ Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) {
// Construct block expecting 16 statements.
Block* body = new(zone()) Block(isolate(), labels, 16, false);
Scope* block_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE);
- if (top_scope_->is_strict_mode()) {
- block_scope->EnableStrictMode();
- }
// Parse the statements and collect escaping labels.
Expect(Token::LBRACE, CHECK_OK);
@@ -1844,9 +1841,7 @@ Block* Parser::ParseVariableDeclarations(
} else {
// Add strict mode.
// We may want to pass singleton to avoid Literal allocations.
- StrictModeFlag flag = initialization_scope->is_strict_mode()
- ? kStrictMode
- : kNonStrictMode;
+ StrictModeFlag flag = initialization_scope->strict_mode_flag();
arguments->Add(NewNumberLiteral(flag));
// Be careful not to assign a value to the global variable if
@@ -2256,9 +2251,6 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
if (peek() == Token::LBRACE) {
Target target(&this->target_stack_, &catch_collector);
catch_scope = NewScope(top_scope_, Scope::CATCH_SCOPE);
- if (top_scope_->is_strict_mode()) {
- catch_scope->EnableStrictMode();
- }
VariableMode mode = harmony_scoping_ ? LET : VAR;
catch_variable = catch_scope->DeclareLocal(name, mode);
@@ -2376,9 +2368,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
// Create an in-between scope for let-bound iteration variables.
Scope* saved_scope = top_scope_;
Scope* for_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE);
- if (top_scope_->is_strict_mode()) {
- for_scope->EnableStrictMode();
- }
top_scope_ = for_scope;
Expect(Token::FOR, CHECK_OK);
@@ -3975,7 +3964,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name,
scanner().SeekForward(end_pos - 1);
materialized_literal_count = entry.literal_count();
expected_property_count = entry.property_count();
- if (entry.strict_mode()) top_scope_->EnableStrictMode();
+ if (entry.strict_mode()) top_scope_->SetStrictModeFlag(kStrictMode);
only_simple_this_property_assignments = false;
this_property_assignments = isolate()->factory()->empty_fixed_array();
Expect(Token::RBRACE, CHECK_OK);
@@ -5385,7 +5374,7 @@ bool ParserApi::Parse(CompilationInfo* info) {
Handle<String> source = Handle<String>(String::cast(script->source()));
result = parser.ParseProgram(source,
info->is_global(),
- info->StrictMode());
+ info->strict_mode_flag());
}
}
info->SetFunction(result);
« src/compiler.cc ('K') | « src/objects-inl.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698