Commit b07f38a4 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Reject local module declarations.

R=mstarzinger@chromium.org
BUG=150628

Review URL: https://codereview.chromium.org/11033025

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12665 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3f7b5c33
...@@ -642,7 +642,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, ...@@ -642,7 +642,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
bool ok = true; bool ok = true;
int beg_loc = scanner().location().beg_pos; int beg_loc = scanner().location().beg_pos;
ParseSourceElements(body, Token::EOS, info->is_eval(), &ok); ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
if (ok && !top_scope_->is_classic_mode()) { if (ok && !top_scope_->is_classic_mode()) {
CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
} }
...@@ -1007,6 +1007,7 @@ class ThisNamedPropertyAssignmentFinder { ...@@ -1007,6 +1007,7 @@ class ThisNamedPropertyAssignmentFinder {
void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
int end_token, int end_token,
bool is_eval, bool is_eval,
bool is_global,
bool* ok) { bool* ok) {
// SourceElements :: // SourceElements ::
// (ModuleElement)* <end_token> // (ModuleElement)* <end_token>
...@@ -1028,7 +1029,12 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, ...@@ -1028,7 +1029,12 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
} }
Scanner::Location token_loc = scanner().peek_location(); Scanner::Location token_loc = scanner().peek_location();
Statement* stat = ParseModuleElement(NULL, CHECK_OK); Statement* stat;
if (is_global && !is_eval) {
stat = ParseModuleElement(NULL, CHECK_OK);
} else {
stat = ParseBlockElement(NULL, CHECK_OK);
}
if (stat == NULL || stat->IsEmpty()) { if (stat == NULL || stat->IsEmpty()) {
directive_prologue = false; // End of directive prologue. directive_prologue = false; // End of directive prologue.
continue; continue;
...@@ -4533,7 +4539,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name, ...@@ -4533,7 +4539,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name,
RelocInfo::kNoPosition)), RelocInfo::kNoPosition)),
zone()); zone());
} }
ParseSourceElements(body, Token::RBRACE, false, CHECK_OK); ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK);
materialized_literal_count = function_state.materialized_literal_count(); materialized_literal_count = function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count(); expected_property_count = function_state.expected_property_count();
......
...@@ -590,8 +590,8 @@ class Parser { ...@@ -590,8 +590,8 @@ class Parser {
// which is set to false if parsing failed; it is unchanged otherwise. // which is set to false if parsing failed; it is unchanged otherwise.
// By making the 'exception handling' explicit, we are forced to check // By making the 'exception handling' explicit, we are forced to check
// for failure at the call sites. // for failure at the call sites.
void* ParseSourceElements(ZoneList<Statement*>* processor, void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token,
int end_token, bool is_eval, bool* ok); bool is_eval, bool is_global, bool* ok);
Statement* ParseModuleElement(ZoneStringList* labels, bool* ok); Statement* ParseModuleElement(ZoneStringList* labels, bool* ok);
Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok); Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok);
Module* ParseModule(bool* ok); Module* ParseModule(bool* ok);
......
...@@ -162,3 +162,29 @@ try {} catch (module) {} ...@@ -162,3 +162,29 @@ try {} catch (module) {}
module module
v = 20 v = 20
// Check that module declarations are rejected in eval or local scope.
module M { export let x; }
assertThrows("export x;", SyntaxError); // It's using eval, so should throw.
assertThrows("export let x;", SyntaxError);
assertThrows("import x from M;", SyntaxError);
assertThrows("module M {};", SyntaxError);
assertThrows("{ export x; }", SyntaxError);
assertThrows("{ export let x; }", SyntaxError);
assertThrows("{ import x from M; }", SyntaxError);
assertThrows("{ module M {}; }", SyntaxError);
assertThrows("function f() { export x; }", SyntaxError);
assertThrows("function f() { export let x; }", SyntaxError);
assertThrows("function f() { import x from M; }", SyntaxError);
assertThrows("function f() { module M {}; }", SyntaxError);
assertThrows("function f() { { export x; } }", SyntaxError);
assertThrows("function f() { { export let x; } }", SyntaxError);
assertThrows("function f() { { import x from M; } }", SyntaxError);
assertThrows("function f() { { module M {}; } }", SyntaxError);
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