[es6] Remove Scanner and Parser flags for harmony_modules
These flags weren't doing any real work, since the decision of whether some source code is a script or module is made outside the parser (currently, by the V8 API). The only behavior change in this patch is to always parse 'import' and 'export' as their Token values, which changes the error message from "Unexpected reserved word" to "Unexpected token import" (which doesn't seem particularly harmful). Review URL: https://codereview.chromium.org/1262913003 Cr-Commit-Position: refs/heads/master@{#30034}
This commit is contained in:
parent
2cd2b8cadb
commit
5c34bacb72
@ -910,7 +910,6 @@ Parser::Parser(ParseInfo* info)
|
||||
DCHECK(!info->script().is_null() || info->source_stream() != NULL);
|
||||
set_allow_lazy(info->allow_lazy_parsing());
|
||||
set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
|
||||
set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules);
|
||||
set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions);
|
||||
set_allow_harmony_sloppy(FLAG_harmony_sloppy);
|
||||
set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let);
|
||||
@ -1054,7 +1053,6 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
|
||||
bool ok = true;
|
||||
int beg_pos = scanner()->location().beg_pos;
|
||||
if (info->is_module()) {
|
||||
DCHECK(allow_harmony_modules());
|
||||
ParseModuleItemList(body, &ok);
|
||||
} else {
|
||||
ParseStatementList(body, Token::EOS, &ok);
|
||||
@ -4492,7 +4490,6 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
|
||||
reusable_preparser_->set_allow_lazy(true);
|
||||
#define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
|
||||
SET_ALLOW(natives);
|
||||
SET_ALLOW(harmony_modules);
|
||||
SET_ALLOW(harmony_arrow_functions);
|
||||
SET_ALLOW(harmony_sloppy);
|
||||
SET_ALLOW(harmony_sloppy_let);
|
||||
|
@ -139,10 +139,8 @@ class ParserBase : public Traits {
|
||||
ALLOW_ACCESSORS(legacy_const);
|
||||
#undef ALLOW_ACCESSORS
|
||||
|
||||
bool allow_harmony_modules() const { return scanner()->HarmonyModules(); }
|
||||
bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); }
|
||||
|
||||
void set_allow_harmony_modules(bool a) { scanner()->SetHarmonyModules(a); }
|
||||
void set_allow_harmony_unicode(bool a) { scanner()->SetHarmonyUnicode(a); }
|
||||
|
||||
protected:
|
||||
@ -322,7 +320,7 @@ class ParserBase : public Traits {
|
||||
|
||||
Scope* NewScope(Scope* parent, ScopeType scope_type, FunctionKind kind) {
|
||||
DCHECK(ast_value_factory());
|
||||
DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules());
|
||||
DCHECK(scope_type != MODULE_SCOPE || FLAG_harmony_modules);
|
||||
DCHECK(!IsArrowFunction(kind) || scope_type == ARROW_SCOPE);
|
||||
Scope* result = new (zone())
|
||||
Scope(zone(), parent, scope_type, ast_value_factory(), kind);
|
||||
|
135
src/scanner.cc
135
src/scanner.cc
@ -41,7 +41,6 @@ Scanner::Scanner(UnicodeCache* unicode_cache)
|
||||
: unicode_cache_(unicode_cache),
|
||||
bookmark_c0_(kNoBookmark),
|
||||
octal_pos_(Location::invalid()),
|
||||
harmony_modules_(false),
|
||||
harmony_unicode_(false) {
|
||||
bookmark_current_.literal_chars = &bookmark_current_literal_;
|
||||
bookmark_current_.raw_literal_chars = &bookmark_current_raw_literal_;
|
||||
@ -1098,74 +1097,71 @@ uc32 Scanner::ScanUnicodeEscape() {
|
||||
// ----------------------------------------------------------------------------
|
||||
// Keyword Matcher
|
||||
|
||||
#define KEYWORDS(KEYWORD_GROUP, KEYWORD) \
|
||||
KEYWORD_GROUP('b') \
|
||||
KEYWORD("break", Token::BREAK) \
|
||||
KEYWORD_GROUP('c') \
|
||||
KEYWORD("case", Token::CASE) \
|
||||
KEYWORD("catch", Token::CATCH) \
|
||||
KEYWORD("class", Token::CLASS) \
|
||||
KEYWORD("const", Token::CONST) \
|
||||
KEYWORD("continue", Token::CONTINUE) \
|
||||
KEYWORD_GROUP('d') \
|
||||
KEYWORD("debugger", Token::DEBUGGER) \
|
||||
KEYWORD("default", Token::DEFAULT) \
|
||||
KEYWORD("delete", Token::DELETE) \
|
||||
KEYWORD("do", Token::DO) \
|
||||
KEYWORD_GROUP('e') \
|
||||
KEYWORD("else", Token::ELSE) \
|
||||
KEYWORD("enum", Token::FUTURE_RESERVED_WORD) \
|
||||
KEYWORD("export", \
|
||||
harmony_modules ? Token::EXPORT : Token::FUTURE_RESERVED_WORD) \
|
||||
KEYWORD("extends", Token::EXTENDS) \
|
||||
KEYWORD_GROUP('f') \
|
||||
KEYWORD("false", Token::FALSE_LITERAL) \
|
||||
KEYWORD("finally", Token::FINALLY) \
|
||||
KEYWORD("for", Token::FOR) \
|
||||
KEYWORD("function", Token::FUNCTION) \
|
||||
KEYWORD_GROUP('i') \
|
||||
KEYWORD("if", Token::IF) \
|
||||
KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD("import", \
|
||||
harmony_modules ? Token::IMPORT : Token::FUTURE_RESERVED_WORD) \
|
||||
KEYWORD("in", Token::IN) \
|
||||
KEYWORD("instanceof", Token::INSTANCEOF) \
|
||||
KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD_GROUP('l') \
|
||||
KEYWORD("let", Token::LET) \
|
||||
KEYWORD_GROUP('n') \
|
||||
KEYWORD("new", Token::NEW) \
|
||||
KEYWORD("null", Token::NULL_LITERAL) \
|
||||
KEYWORD_GROUP('p') \
|
||||
KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD("protected", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD("public", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD_GROUP('r') \
|
||||
KEYWORD("return", Token::RETURN) \
|
||||
KEYWORD_GROUP('s') \
|
||||
KEYWORD("static", Token::STATIC) \
|
||||
KEYWORD("super", Token::SUPER) \
|
||||
KEYWORD("switch", Token::SWITCH) \
|
||||
KEYWORD_GROUP('t') \
|
||||
KEYWORD("this", Token::THIS) \
|
||||
KEYWORD("throw", Token::THROW) \
|
||||
KEYWORD("true", Token::TRUE_LITERAL) \
|
||||
KEYWORD("try", Token::TRY) \
|
||||
KEYWORD("typeof", Token::TYPEOF) \
|
||||
KEYWORD_GROUP('v') \
|
||||
KEYWORD("var", Token::VAR) \
|
||||
KEYWORD("void", Token::VOID) \
|
||||
KEYWORD_GROUP('w') \
|
||||
KEYWORD("while", Token::WHILE) \
|
||||
KEYWORD("with", Token::WITH) \
|
||||
KEYWORD_GROUP('y') \
|
||||
#define KEYWORDS(KEYWORD_GROUP, KEYWORD) \
|
||||
KEYWORD_GROUP('b') \
|
||||
KEYWORD("break", Token::BREAK) \
|
||||
KEYWORD_GROUP('c') \
|
||||
KEYWORD("case", Token::CASE) \
|
||||
KEYWORD("catch", Token::CATCH) \
|
||||
KEYWORD("class", Token::CLASS) \
|
||||
KEYWORD("const", Token::CONST) \
|
||||
KEYWORD("continue", Token::CONTINUE) \
|
||||
KEYWORD_GROUP('d') \
|
||||
KEYWORD("debugger", Token::DEBUGGER) \
|
||||
KEYWORD("default", Token::DEFAULT) \
|
||||
KEYWORD("delete", Token::DELETE) \
|
||||
KEYWORD("do", Token::DO) \
|
||||
KEYWORD_GROUP('e') \
|
||||
KEYWORD("else", Token::ELSE) \
|
||||
KEYWORD("enum", Token::FUTURE_RESERVED_WORD) \
|
||||
KEYWORD("export", Token::EXPORT) \
|
||||
KEYWORD("extends", Token::EXTENDS) \
|
||||
KEYWORD_GROUP('f') \
|
||||
KEYWORD("false", Token::FALSE_LITERAL) \
|
||||
KEYWORD("finally", Token::FINALLY) \
|
||||
KEYWORD("for", Token::FOR) \
|
||||
KEYWORD("function", Token::FUNCTION) \
|
||||
KEYWORD_GROUP('i') \
|
||||
KEYWORD("if", Token::IF) \
|
||||
KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD("import", Token::IMPORT) \
|
||||
KEYWORD("in", Token::IN) \
|
||||
KEYWORD("instanceof", Token::INSTANCEOF) \
|
||||
KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD_GROUP('l') \
|
||||
KEYWORD("let", Token::LET) \
|
||||
KEYWORD_GROUP('n') \
|
||||
KEYWORD("new", Token::NEW) \
|
||||
KEYWORD("null", Token::NULL_LITERAL) \
|
||||
KEYWORD_GROUP('p') \
|
||||
KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD("protected", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD("public", Token::FUTURE_STRICT_RESERVED_WORD) \
|
||||
KEYWORD_GROUP('r') \
|
||||
KEYWORD("return", Token::RETURN) \
|
||||
KEYWORD_GROUP('s') \
|
||||
KEYWORD("static", Token::STATIC) \
|
||||
KEYWORD("super", Token::SUPER) \
|
||||
KEYWORD("switch", Token::SWITCH) \
|
||||
KEYWORD_GROUP('t') \
|
||||
KEYWORD("this", Token::THIS) \
|
||||
KEYWORD("throw", Token::THROW) \
|
||||
KEYWORD("true", Token::TRUE_LITERAL) \
|
||||
KEYWORD("try", Token::TRY) \
|
||||
KEYWORD("typeof", Token::TYPEOF) \
|
||||
KEYWORD_GROUP('v') \
|
||||
KEYWORD("var", Token::VAR) \
|
||||
KEYWORD("void", Token::VOID) \
|
||||
KEYWORD_GROUP('w') \
|
||||
KEYWORD("while", Token::WHILE) \
|
||||
KEYWORD("with", Token::WITH) \
|
||||
KEYWORD_GROUP('y') \
|
||||
KEYWORD("yield", Token::YIELD)
|
||||
|
||||
|
||||
static Token::Value KeywordOrIdentifierToken(const uint8_t* input,
|
||||
int input_length,
|
||||
bool harmony_modules) {
|
||||
int input_length) {
|
||||
DCHECK(input_length >= 1);
|
||||
const int kMinLength = 2;
|
||||
const int kMaxLength = 10;
|
||||
@ -1212,8 +1208,7 @@ bool Scanner::IdentifierIsFutureStrictReserved(
|
||||
return true;
|
||||
}
|
||||
return Token::FUTURE_STRICT_RESERVED_WORD ==
|
||||
KeywordOrIdentifierToken(string->raw_data(), string->length(),
|
||||
harmony_modules_);
|
||||
KeywordOrIdentifierToken(string->raw_data(), string->length());
|
||||
}
|
||||
|
||||
|
||||
@ -1246,8 +1241,7 @@ Token::Value Scanner::ScanIdentifierOrKeyword() {
|
||||
// Only a-z+: could be a keyword or identifier.
|
||||
literal.Complete();
|
||||
Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
|
||||
return KeywordOrIdentifierToken(chars.start(), chars.length(),
|
||||
harmony_modules_);
|
||||
return KeywordOrIdentifierToken(chars.start(), chars.length());
|
||||
}
|
||||
|
||||
HandleLeadSurrogate();
|
||||
@ -1297,8 +1291,7 @@ Token::Value Scanner::ScanIdentifierOrKeyword() {
|
||||
|
||||
if (next_.literal_chars->is_one_byte()) {
|
||||
Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
|
||||
return KeywordOrIdentifierToken(chars.start(), chars.length(),
|
||||
harmony_modules_);
|
||||
return KeywordOrIdentifierToken(chars.start(), chars.length());
|
||||
}
|
||||
return Token::IDENTIFIER;
|
||||
}
|
||||
|
@ -478,13 +478,6 @@ class Scanner {
|
||||
// tokens, which is what it is used for.
|
||||
void SeekForward(int pos);
|
||||
|
||||
bool HarmonyModules() const {
|
||||
return harmony_modules_;
|
||||
}
|
||||
void SetHarmonyModules(bool modules) {
|
||||
harmony_modules_ = modules;
|
||||
}
|
||||
|
||||
bool HarmonyUnicode() const { return harmony_unicode_; }
|
||||
void SetHarmonyUnicode(bool unicode) { harmony_unicode_ = unicode; }
|
||||
|
||||
@ -797,8 +790,6 @@ class Scanner {
|
||||
// Whether there is a multi-line comment that contains a
|
||||
// line-terminator after the current token, and before the next.
|
||||
bool has_multiline_comment_before_next_;
|
||||
// Whether we scan 'module', 'import', 'export' as keywords.
|
||||
bool harmony_modules_;
|
||||
// Whether we allow \u{xxxxx}.
|
||||
bool harmony_unicode_;
|
||||
};
|
||||
|
@ -71,8 +71,6 @@ TEST(ScanKeywords) {
|
||||
{
|
||||
i::Utf8ToUtf16CharacterStream stream(keyword, length);
|
||||
i::Scanner scanner(&unicode_cache);
|
||||
// The scanner should parse Harmony keywords for this test.
|
||||
scanner.SetHarmonyModules(true);
|
||||
scanner.Initialize(&stream);
|
||||
CHECK_EQ(key_token.token, scanner.Next());
|
||||
CHECK_EQ(i::Token::EOS, scanner.Next());
|
||||
@ -1427,7 +1425,6 @@ i::Handle<i::String> FormatMessage(i::Vector<unsigned> data) {
|
||||
enum ParserFlag {
|
||||
kAllowLazy,
|
||||
kAllowNatives,
|
||||
kAllowHarmonyModules,
|
||||
kAllowHarmonyArrowFunctions,
|
||||
kAllowHarmonyRestParameters,
|
||||
kAllowHarmonySloppy,
|
||||
@ -1454,7 +1451,6 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
|
||||
i::EnumSet<ParserFlag> flags) {
|
||||
parser->set_allow_lazy(flags.Contains(kAllowLazy));
|
||||
parser->set_allow_natives(flags.Contains(kAllowNatives));
|
||||
parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules));
|
||||
parser->set_allow_harmony_arrow_functions(
|
||||
flags.Contains(kAllowHarmonyArrowFunctions));
|
||||
parser->set_allow_harmony_rest_parameters(
|
||||
@ -5312,6 +5308,8 @@ TEST(ComputedPropertyNameShorthandError) {
|
||||
|
||||
|
||||
TEST(BasicImportExportParsing) {
|
||||
i::FLAG_harmony_modules = true;
|
||||
|
||||
const char* kSources[] = {
|
||||
"export let x = 0;",
|
||||
"export var y = 0;",
|
||||
@ -5371,7 +5369,6 @@ TEST(BasicImportExportParsing) {
|
||||
i::Zone zone;
|
||||
i::ParseInfo info(&zone, script);
|
||||
i::Parser parser(&info);
|
||||
parser.set_allow_harmony_modules(true);
|
||||
info.set_module();
|
||||
if (!parser.Parse(&info)) {
|
||||
i::Handle<i::JSObject> exception_handle(
|
||||
@ -5397,7 +5394,6 @@ TEST(BasicImportExportParsing) {
|
||||
i::Zone zone;
|
||||
i::ParseInfo info(&zone, script);
|
||||
i::Parser parser(&info);
|
||||
parser.set_allow_harmony_modules(true);
|
||||
info.set_global();
|
||||
CHECK(!parser.Parse(&info));
|
||||
}
|
||||
@ -5406,6 +5402,8 @@ TEST(BasicImportExportParsing) {
|
||||
|
||||
|
||||
TEST(ImportExportParsingErrors) {
|
||||
i::FLAG_harmony_modules = true;
|
||||
|
||||
const char* kErrorSources[] = {
|
||||
"export {",
|
||||
"var a; export { a",
|
||||
@ -5486,7 +5484,6 @@ TEST(ImportExportParsingErrors) {
|
||||
i::Zone zone;
|
||||
i::ParseInfo info(&zone, script);
|
||||
i::Parser parser(&info);
|
||||
parser.set_allow_harmony_modules(true);
|
||||
info.set_module();
|
||||
CHECK(!parser.Parse(&info));
|
||||
}
|
||||
@ -5517,7 +5514,6 @@ TEST(ModuleParsingInternals) {
|
||||
i::Zone zone;
|
||||
i::ParseInfo info(&zone, script);
|
||||
i::Parser parser(&info);
|
||||
parser.set_allow_harmony_modules(true);
|
||||
info.set_module();
|
||||
CHECK(parser.Parse(&info));
|
||||
CHECK(i::Compiler::Analyze(&info));
|
||||
|
Loading…
Reference in New Issue
Block a user