Bug 1258097 - Check for redeclaration of imports by functions r=shu
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 01 Apr 2016 10:29:03 +0100
changeset 291212 19bd9167df871bdcd04000e6983da746fa667365
parent 291211 6001a9e0ec92fa83ab76f2628d1d0638b6db523d
child 291213 2eac8f080d52827aa8a37d712e673db288d44fe6
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1258097
milestone48.0a1
Bug 1258097 - Check for redeclaration of imports by functions r=shu
js/src/frontend/Parser.cpp
js/src/jit-test/tests/modules/bug-1258097.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -2323,28 +2323,29 @@ Parser<FullParseHandler>::bindBodyLevelF
     /*
      * Handle redeclaration and optimize cases where we can statically bind the
      * function (thereby avoiding JSOP_DEFFUN and dynamic name lookup).
      */
     if (Definition* dn = pc->decls().lookupFirst(funName)) {
         MOZ_ASSERT(!dn->isUsed());
         MOZ_ASSERT(dn->isDefn());
 
-        if (dn->kind() == Definition::CONSTANT || dn->kind() == Definition::LET)
-            return reportRedeclaration(nullptr, Definition::VAR, funName);
+        Definition::Kind kind = dn->kind();
+        if (kind == Definition::CONSTANT || kind == Definition::LET || kind == Definition::IMPORT)
+            return reportRedeclaration(nullptr, kind, funName);
 
         /*
          * Body-level function statements are effectively variable
          * declarations where the initialization is hoisted to the
          * beginning of the block. This means that any other variable
          * declaration with the same name is really just an assignment to
          * the function's binding (which is mutable), so turn any existing
          * declaration into a use.
          */
-        if (dn->kind() == Definition::ARG) {
+        if (kind == Definition::ARG) {
             // The exception to the above comment is when the function
             // has the same name as an argument. Then the argument node
             // remains a definition. But change the function node pn so
             // that it knows where the argument is located.
             pn->setOp(JSOP_GETARG);
             pn->setDefn(true);
             pn->pn_scopecoord = dn->pn_scopecoord;
             pn->pn_blockid = dn->pn_blockid;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/modules/bug-1258097.js
@@ -0,0 +1,3 @@
+// |jit-test| module; error:SyntaxError
+import x from 'y';
+function x() {}