Commit 5c34bacb authored by adamk's avatar adamk Committed by Commit bot

[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}
parent 2cd2b8ca
......@@ -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);
......
This diff is collapsed.
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment