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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 91f17dd143b81eb966ddc85c568124afdd81f740..300d9349bee554c1c515feb705c1b9a6308ec5cc 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -1304,11 +1304,45 @@ void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) {
DCHECK(scope_->is_module_scope());
RaiseLanguageMode(STRICT);
+ bool directive_prologue = true; // Parsing directive prologue.
+
while (peek() != Token::EOS) {
+ if (directive_prologue && peek() != Token::STRING) {
+ directive_prologue = false;
+ }
+
+ Scanner::Location token_loc = scanner()->peek_location();
Statement* stat = ParseModuleItem(CHECK_OK);
- if (stat && !stat->IsEmpty()) {
- body->Add(stat, zone());
+ if (stat == NULL || stat->IsEmpty()) {
+ directive_prologue = false; // End of directive prologue.
+ continue;
+ }
+
+ if (directive_prologue) {
+ // A shot at a directive.
+ ExpressionStatement* e_stat;
+ Literal* literal;
+ // Still processing directive prologue?
+ if ((e_stat = stat->AsExpressionStatement()) != NULL &&
+ (literal = e_stat->expression()->AsLiteral()) != NULL &&
+ literal->raw_value()->IsString()) {
+ // Ignore "use strict" directive in a module, check "use asm".
+ if (literal->raw_value()->AsString() ==
+ ast_value_factory()->use_asm_string() &&
+ token_loc.end_pos - token_loc.beg_pos ==
+ ast_value_factory()->use_asm_string()->length() + 2) {
+ // Store the usage count; The actual use counter on the isolate is
+ // incremented after parsing is done.
+ ++use_counts_[v8::Isolate::kUseAsm];
+ scope_->SetAsmModule();
+ }
+ } else {
+ // End of the directive prologue.
+ directive_prologue = false;
+ }
}
+
+ body->Add(stat, zone());
}
// Check that all exports are bound.
« 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