Bug 632020 - Allow constant folding to see inside functions when using the module pattern. r=jwalden
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 01 Oct 2018 22:47:25 +0000
changeset 494851 abd419a57735832ac235c23716225c2b38abd759
parent 494850 a080d82d994e423e3bcdd8cf9a2b49b3aba59327
child 494852 260007b95d6791a665a7ce2ba45664182b119609
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs632020
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 632020 - Allow constant folding to see inside functions when using the module pattern. r=jwalden Differential Revision: https://phabricator.services.mozilla.com/D6900
js/src/frontend/FoldConstants.cpp
--- a/js/src/frontend/FoldConstants.cpp
+++ b/js/src/frontend/FoldConstants.cpp
@@ -1484,19 +1484,26 @@ FoldCall(JSContext* cx, BinaryNode* node
     //
     //   var prop = "global";
     //   var obj = { prop: "obj", f: function() { return this.prop; } };
     //   assertEq((true ? obj.f : null)(), "global");
     //   assertEq(obj.f(), "obj");
     //   assertEq((true ? obj.f : null)``, "global");
     //   assertEq(obj.f``, "obj");
     //
+    // As an exception to this, we do allow folding the function in
+    // `(function() { ... })()` (the module pattern), because that lets us
+    // constant fold code inside that function.
+    //
     // See bug 537673 and bug 1182373.
     ParseNode* callee = node->left();
-    if (node->isKind(ParseNodeKind::New) || !callee->isInParens()) {
+    if (node->isKind(ParseNodeKind::New) ||
+        !callee->isInParens() ||
+        callee->isKind(ParseNodeKind::Function))
+    {
         if (!Fold(cx, node->unsafeLeftReference(), parser)) {
             return false;
         }
     }
 
     if (!Fold(cx, node->unsafeRightReference(), parser)) {
         return false;
     }