diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index e970f5d2f3..94a295b026 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -4209,6 +4209,7 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_numeric_separator) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_json_stringify) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_sequence) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_await_optimization) +EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_hashbang) #undef EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE diff --git a/src/flag-definitions.h b/src/flag-definitions.h index f27ed2f5fa..f694ef59a4 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -201,7 +201,8 @@ DEFINE_IMPLICATION(harmony_private_methods, harmony_private_fields) V(harmony_class_fields, "harmony fields in class literals") \ V(harmony_private_methods, "harmony private methods in class literals") \ V(harmony_regexp_sequence, "RegExp Unicode sequence properties") \ - V(harmony_weak_refs, "harmony weak references") + V(harmony_weak_refs, "harmony weak references") \ + V(harmony_hashbang, "harmony hashbang syntax") #ifdef V8_INTL_SUPPORT #define HARMONY_INPROGRESS(V) \ diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index 6fee33da82..49b0dfbe2f 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -495,6 +495,9 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { DeserializeScopeChain(isolate, info, info->maybe_outer_scope_info()); scanner_.Initialize(); + if (FLAG_harmony_hashbang && !info->is_eval()) { + scanner_.SkipHashBang(); + } FunctionLiteral* result = DoParseProgram(isolate, info); MaybeResetCharacterStream(info, result); MaybeProcessSourceRanges(info, result, stack_limit_); diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc index 6c22e59a36..07f727d88a 100644 --- a/src/parsing/preparser.cc +++ b/src/parsing/preparser.cc @@ -78,6 +78,12 @@ PreParser::PreParseResult PreParser::PreParseProgram() { scope->set_is_being_lazily_parsed(true); #endif + if (FLAG_harmony_hashbang) { + // Note: We should only skip the hashbang in non-Eval scripts + // (currently, Eval is not handled by the PreParser). + scanner()->SkipHashBang(); + } + // ModuleDeclarationInstantiation for Source Text Module Records creates a // new Module Environment Record whose outer lexical environment record is // the global scope. diff --git a/src/parsing/scanner.cc b/src/parsing/scanner.cc index 9c152ebeda..43fc589e88 100644 --- a/src/parsing/scanner.cc +++ b/src/parsing/scanner.cc @@ -361,6 +361,13 @@ Token::Value Scanner::SkipMultiLineComment() { return Token::ILLEGAL; } +void Scanner::SkipHashBang() { + if (c0_ == '#' && Peek() == '!' && source_pos() == 0) { + SkipSingleLineComment(); + Scan(); + } +} + Token::Value Scanner::ScanHtmlComment() { // Check for