Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Reject local module declarations. (issue 11033025)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
rossb...@chromium.org  
View profile  
 More options Oct 4 2012, 9:42 am
From: rossb...@chromium.org
Date: Thu, 04 Oct 2012 13:42:34 +0000
Local: Thurs, Oct 4 2012 9:42 am
Subject: Reject local module declarations. (issue 11033025)
Reviewers: Michael Starzinger,

Description:
Reject local module declarations.

R=mstarzin...@chromium.org
BUG=

Please review this at https://codereview.chromium.org/11033025/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
   M src/parser.h
   M src/parser.cc
   M test/mjsunit/harmony/module-parsing.js

Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index  
a626d99fa0a078cbaffb97deb3fb448e4d6c8dd2..9c78b8c83e58fb62bf9c1139c00e53b40 4034c7d  
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -642,7 +642,7 @@ FunctionLiteral*  
Parser::DoParseProgram(CompilationInfo* info,
      ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16,  
zone());
      bool ok = true;
      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()) {
        CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
      }
@@ -1007,6 +1007,7 @@ class ThisNamedPropertyAssignmentFinder {
  void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
                                    int end_token,
                                    bool is_eval,
+                                  bool is_global,
                                    bool* ok) {
    // SourceElements ::
    //   (ModuleElement)* <end_token>
@@ -1028,7 +1029,12 @@ void*  
Parser::ParseSourceElements(ZoneList<Statement*>* processor,
      }

      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()) {
        directive_prologue = false;   // End of directive prologue.
        continue;
@@ -4531,7 +4537,7 @@ FunctionLiteral*  
Parser::ParseFunctionLiteral(Handle<String> function_name,
                                       RelocInfo::kNoPosition)),
                                       zone());
        }
-      ParseSourceElements(body, Token::RBRACE, false, CHECK_OK);
+      ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK);

        materialized_literal_count =  
function_state.materialized_literal_count();
        expected_property_count = function_state.expected_property_count();
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index  
93dd03a63b201d986e8d9c09cdc6342653619daf..46d4ec86ef8ba7650e153aa719315a966 d634faa  
100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -590,8 +590,8 @@ class Parser {
    // which is set to false if parsing failed; it is unchanged otherwise.
    // By making the 'exception handling' explicit, we are forced to check
    // for failure at the call sites.
-  void* ParseSourceElements(ZoneList<Statement*>* processor,
-                            int end_token, bool is_eval, bool* ok);
+  void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token,
+                            bool is_eval, bool is_global, bool* ok);
    Statement* ParseModuleElement(ZoneStringList* labels, bool* ok);
    Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok);
    Module* ParseModule(bool* ok);
Index: test/mjsunit/harmony/module-parsing.js
diff --git a/test/mjsunit/harmony/module-parsing.js  
b/test/mjsunit/harmony/module-parsing.js
index  
03948e31b9609f519378126582d9825d322206de..8a9103d13284ad4134192972276f7cd2c 025538b  
100644
--- a/test/mjsunit/harmony/module-parsing.js
+++ b/test/mjsunit/harmony/module-parsing.js
@@ -162,3 +162,29 @@ try {} catch (module) {}

  module
  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);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.