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
This commit is contained in:
Martok 2023-04-02 19:40:49 +02:00 • committed by roytam1
commit 661b1c534c

View file

@ -1544,9 +1544,13 @@ FoldCall(ExclusiveContext* cx, BinaryNode* node, Parser<FullParseHandler>& 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<FunctionNode>()) {
if (!Fold(cx, node->unsafeLeftReference(), parser, inGenexpLambda))
return false;
}