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

Side by Side Diff: src/parsing/parser.cc

Issue 1827763002: Correctly parse the directive prologue in modules (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 // (Ecma 262 6th Edition, 15.2): 1297 // (Ecma 262 6th Edition, 15.2):
1298 // Module : 1298 // Module :
1299 // ModuleBody? 1299 // ModuleBody?
1300 // 1300 //
1301 // ModuleBody : 1301 // ModuleBody :
1302 // ModuleItem* 1302 // ModuleItem*
1303 1303
1304 DCHECK(scope_->is_module_scope()); 1304 DCHECK(scope_->is_module_scope());
1305 RaiseLanguageMode(STRICT); 1305 RaiseLanguageMode(STRICT);
1306 1306
1307 bool directive_prologue = true; // Parsing directive prologue.
1308
1307 while (peek() != Token::EOS) { 1309 while (peek() != Token::EOS) {
1310 if (directive_prologue && peek() != Token::STRING) {
1311 directive_prologue = false;
1312 }
1313
1314 Scanner::Location token_loc = scanner()->peek_location();
1308 Statement* stat = ParseModuleItem(CHECK_OK); 1315 Statement* stat = ParseModuleItem(CHECK_OK);
1309 if (stat && !stat->IsEmpty()) { 1316 if (stat == NULL || stat->IsEmpty()) {
1310 body->Add(stat, zone()); 1317 directive_prologue = false; // End of directive prologue.
1318 continue;
1311 } 1319 }
1320
1321 if (directive_prologue) {
1322 // A shot at a directive.
1323 ExpressionStatement* e_stat;
1324 Literal* literal;
1325 // Still processing directive prologue?
1326 if ((e_stat = stat->AsExpressionStatement()) != NULL &&
1327 (literal = e_stat->expression()->AsLiteral()) != NULL &&
1328 literal->raw_value()->IsString()) {
1329 // Ignore "use strict" directive in a module, check "use asm".
1330 if (literal->raw_value()->AsString() ==
1331 ast_value_factory()->use_asm_string() &&
1332 token_loc.end_pos - token_loc.beg_pos ==
1333 ast_value_factory()->use_asm_string()->length() + 2) {
1334 // Store the usage count; The actual use counter on the isolate is
1335 // incremented after parsing is done.
1336 ++use_counts_[v8::Isolate::kUseAsm];
1337 scope_->SetAsmModule();
1338 }
1339 } else {
1340 // End of the directive prologue.
1341 directive_prologue = false;
1342 }
1343 }
1344
1345 body->Add(stat, zone());
1312 } 1346 }
1313 1347
1314 // Check that all exports are bound. 1348 // Check that all exports are bound.
1315 ModuleDescriptor* descriptor = scope_->module(); 1349 ModuleDescriptor* descriptor = scope_->module();
1316 for (ModuleDescriptor::Iterator it = descriptor->iterator(); !it.done(); 1350 for (ModuleDescriptor::Iterator it = descriptor->iterator(); !it.done();
1317 it.Advance()) { 1351 it.Advance()) {
1318 if (scope_->LookupLocal(it.local_name()) == NULL) { 1352 if (scope_->LookupLocal(it.local_name()) == NULL) {
1319 // TODO(adamk): Pass both local_name and export_name once ParserTraits 1353 // TODO(adamk): Pass both local_name and export_name once ParserTraits
1320 // supports multiple arg error messages. 1354 // supports multiple arg error messages.
1321 // Also try to report this at a better location. 1355 // Also try to report this at a better location.
(...skipping 5533 matching lines...) Expand 10 before | Expand all | Expand 10 after
6855 try_block, target); 6889 try_block, target);
6856 final_loop = target; 6890 final_loop = target;
6857 } 6891 }
6858 6892
6859 return final_loop; 6893 return final_loop;
6860 } 6894 }
6861 6895
6862 6896
6863 } // namespace internal 6897 } // namespace internal
6864 } // namespace v8 6898 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698