pi

Nested Array Iteration Breaks Closure Variables


While working on my Big Sexy Poems app (GitHub), I ran into another wild bug in Adobe ColdFusion (see previous post). I don’t exactly know how to articulate this one; but, it seems that if I perform nested array iteration within the context of an asynchronous array iteration, closed-over variables are no longer available within a closure scope.

This breaks in both Adobe ColdFusion 2021 and 2025 with the same error. Here’s my reproduction code:

<cfscript>

        // ASYNCHRONOUS array iteration.
        arrayEach(
                [ "" ],
                () => foo( 999 ),
                true
        );

        public array function foo( required numeric flag ) {

                return arrayFilter(
                        bar(),
                        ( result ) => flag // BUG: This closed-over variable is UNDEFINED!
                );

        }

        public array function bar() {

                return arrayFilter( [ "" ], ( element ) => true );

        }

</cfscript>

There are three layers of iteration happening here:

  1. The asynchronous iteration that kicks of the demo.
  2. The arrayFilter() in foo().
  3. The arrayFilter() in bar().

When I run this in Adobe ColdFusin 2021/2025, it breaks with the following error:

coldfusion.runtime.UndefinedVariableException:

Variable FLAG is undefined.

I can remove the error by either:

  • Changing from asynchronous to synchronous iteration in the first arrayEach() call. But, this only fixes the issue in ACF 2025 – the error persists in ACF 2021.

  • Removing the arrayFilter() in bar(). For example, if I just return the array literal, [""], which is what the deeply nested array iteration was creating, it fixes the issue in both ACF 2021 and ACF 2025.

This one is just strange! I wish I could explain it better. It took me several hours to narrow down on the reproduction case because this only popped up in my ColdFusion application when I had several nested calls to a series of ColdFusion components.

Want to use code from this post?
Check out the license.


https://ift.tt/srxgtdQ

Source link



from Breaking News – Techyrack Hub https://ift.tt/KAdUoP7
via IFTTT
Next Post Previous Post
No Comment
Add Comment
comment url

In-Article Ad 2