Saturday 19 July 2014

Different bugs in each() function in each of Railo and ColdFusion

G'day:
A quick one. I was investigating a bug in Railo, detailed in "Arguments - Struct or Array", and as well as verifying the bug in Railo, I found a different one in ColdFusion.

Here's the repro case:

// eachBug.cfm

safe = function(work){
    try {
        work();
    }
    catch (any e){
        writeOutput("ERRORED. [#e.type#] [#e.message#] [#e.detail#]<br>");
    }
};

iterateArgs = function(){
    arguments.each(function(){
        writeDump(var=arguments);
    });
};

writeOutput("<h3>No args</h3>");
safe(function(){
    iterateArgs();
});

writeOutput("<hr><h3>ordered args</h3>");
safe(function(){
    iterateArgs("tahi", "rua", "toru", "wha");
});


writeOutput("<hr><h3>named args</h3>");
safe(function(){
    iterateArgs(one="tahi", two="rua", three="toru", four="wha");
});


writeOutput("<hr><h3>struct</h3>");
numbers = {one="tahi", two="rua", three="toru", four="wha"};
numbers.each(function(){
    writeDump(var=arguments);
});

writeOutput("<hr><h3>array</h3>");
numbers = ["tahi", "rua", "toru", "wha"];
numbers.each(function(){
    writeDump(var=arguments);
});

Most of this works fine on Railo, except the named args example, which yields:

ERRORED. [expression] [can't cast [one] string to a number value] []

So looks like Railo can't decide whether the arguments are to be treated as an array or a struct, and gets it wrong. So much for the arguments scope being a struct, eh, Micha? Even your own code doesn't agree with you ;-)

The ColdFusion error is with the ordered arguments example. Here's the output:

ordered args

struct
13
2toru
struct
14
2wha
struct
12
2rua
struct
11
2tahi


Note the order here does not reflect the order I passed them into the parent function, which was "tahi", "rua", "toru", "wha". The ordered is not preserved, and it is different from one run to another. If ColdFusion is to allow ordered args, it needs to respect that order in any case where ordering could be relevant.

I'm gonna raise a bug for ColdFusion (3791747), but encourage the bod on the Railo Google Group for them to raise the bug in Railo (RAILO-3129).

--
Adam