From 661b1c534cc88bc5bb16d5942d6d02e3c298a746 Mon Sep 17 00:00:00 2001 From: Martok Date: Sun, 2 Apr 2023 19:40:49 +0200 Subject: [PATCH] Issue #2173 - Allow constant folding to see inside functions when using the module pattern (function() { ... })() IIFE pattern should get its body const-folded. This won't make much runtime difference on JIT, but can be significant in interpreted code (and saves time for JIT codegen). Based-on: m-c 632020 --- js/src/frontend/FoldConstants.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/src/frontend/FoldConstants.cpp b/js/src/frontend/FoldConstants.cpp index ed176a27d4..0e27a09404 100644 --- a/js/src/frontend/FoldConstants.cpp +++ b/js/src/frontend/FoldConstants.cpp @@ -1544,9 +1544,13 @@ FoldCall(ExclusiveContext* cx, BinaryNode* node, Parser& parse // 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(PNK_NEW) || !callee->isInParens()) { + if (node->isKind(PNK_NEW) || !callee->isInParens() || callee->is()) { if (!Fold(cx, node->unsafeLeftReference(), parser, inGenexpLambda)) return false; }