G'day
What do you (CFMLers, sorry) make of this?
<cfscript>
function f(){
writeOutput("in f<br>")
abort
}
writeOutput("before f<br>")
f()
writeOutput("after f<br>")
</cfscript>
What would you expect that to output? The foolhardly money would go on:
before f
in f
Because, like, it's obvious: after f is never called because we're aborting in the function. Right?
Well yer partly right. On ColdFusion, that's exacly what happens (I tested on CF2021). On Lucee, however, I get this:
before f
in f
after f
Um… kewl.
The thing is that if one adds a semi-colon after the abort, Lucee starts behaving.
<cfscript>
function f(){
writeOutput("in f<br>")
abort;
}
writeOutput("before f<br>")
f()
writeOutput("after f<br>")
</cfscript>
I had some abort-confusion the other day on the CFML / Lucee Slack channel because this had behaviour I did not expect:
But that's actually correct behaviour. abort takes an optional string parameter showError, and writeOutput returns true (don't ask), which can be coerced into a string. If a statement has only one parameter, its name can be omitted, so Lucee is interpretting that as a multi-line abort statement - with a showError value of true - that doesn't end until the explicit semi-colon.
This is not the same though, as far as I can tell. The } of the function block is an explicit end-of-statement token just like a semi-colon is. Or at least it ought to be.
In other news, this sample code won't run correctly on trycf.com, which you can check out at https://trycf.com/gist/759318ea257c7ca7130c1f12c3ee72f8: Lucee doesn't work as expected whether or not the semi-colon is there; and CF only works as expected when the semi-colon is not there. This is at odds to how it works on (my) actual servers. I'd be interested in what behaviour you get on your servers?
Am still wondering a bit if I'm missing something here; especially given the different varieties of behaviour…
Righto.
--
Adam