From bb9ca47a99ae197e29e4eef9a1a36e789aca6959 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Sun, 16 Jun 2024 23:09:14 +0200 Subject: [PATCH] LDEV-4899 - limit use of pure data member handler --- .../bytecode/expression/AsExpression.java | 7 +++ .../expression/ComponentAsExpression.java | 8 ++- .../expression/FunctionAsExpression.java | 7 ++- .../transformer/bytecode/op/OpElvis.java | 5 +- loader/build.xml | 2 +- loader/pom.xml | 2 +- test/tickets/LDEV4899.cfc | 52 +++++++++++++++++++ 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/lucee/transformer/bytecode/expression/AsExpression.java create mode 100644 test/tickets/LDEV4899.cfc diff --git a/core/src/main/java/lucee/transformer/bytecode/expression/AsExpression.java b/core/src/main/java/lucee/transformer/bytecode/expression/AsExpression.java new file mode 100644 index 0000000000..3962613df3 --- /dev/null +++ b/core/src/main/java/lucee/transformer/bytecode/expression/AsExpression.java @@ -0,0 +1,7 @@ +package lucee.transformer.bytecode.expression; + +import lucee.transformer.bytecode.Statement; + +public interface AsExpression { + public Statement getStatement(); +} diff --git a/core/src/main/java/lucee/transformer/bytecode/expression/ComponentAsExpression.java b/core/src/main/java/lucee/transformer/bytecode/expression/ComponentAsExpression.java index c21f9b3bf3..76b1193cbc 100644 --- a/core/src/main/java/lucee/transformer/bytecode/expression/ComponentAsExpression.java +++ b/core/src/main/java/lucee/transformer/bytecode/expression/ComponentAsExpression.java @@ -10,13 +10,14 @@ import lucee.runtime.functions.other.CreateUniqueId; import lucee.transformer.TransformerException; import lucee.transformer.bytecode.BytecodeContext; +import lucee.transformer.bytecode.Statement; import lucee.transformer.bytecode.statement.tag.Attribute; import lucee.transformer.bytecode.statement.tag.TagComponent; import lucee.transformer.bytecode.util.Types; import lucee.transformer.cfml.Data; import lucee.transformer.cfml.evaluator.EvaluatorException; -public class ComponentAsExpression extends ExpressionBase { +public class ComponentAsExpression extends ExpressionBase implements AsExpression { private static final Type COMPONENT_LOADER = Type.getType(ComponentLoader.class); // ComponentImpl loadInline(PageContext pc, CIPage page) private static final Method LOAD_INLINE1 = new Method("loadInline", Types.COMPONENT_IMPL, new Type[] { Types.CI_PAGE }); @@ -74,4 +75,9 @@ public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException public TagComponent getTagComponent() { return tc; } + + @Override + public Statement getStatement() { + return tc; + } } \ No newline at end of file diff --git a/core/src/main/java/lucee/transformer/bytecode/expression/FunctionAsExpression.java b/core/src/main/java/lucee/transformer/bytecode/expression/FunctionAsExpression.java index 9e2d8e57b2..671e008284 100644 --- a/core/src/main/java/lucee/transformer/bytecode/expression/FunctionAsExpression.java +++ b/core/src/main/java/lucee/transformer/bytecode/expression/FunctionAsExpression.java @@ -21,10 +21,11 @@ import lucee.transformer.TransformerException; import lucee.transformer.bytecode.BytecodeContext; +import lucee.transformer.bytecode.Statement; import lucee.transformer.bytecode.statement.udf.Function; import lucee.transformer.bytecode.util.Types; -public class FunctionAsExpression extends ExpressionBase { +public class FunctionAsExpression extends ExpressionBase implements AsExpression { private Function function; @@ -45,4 +46,8 @@ public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException public Function getFunction() { return function; } + + public Statement getStatement() { + return function; + } } \ No newline at end of file diff --git a/core/src/main/java/lucee/transformer/bytecode/op/OpElvis.java b/core/src/main/java/lucee/transformer/bytecode/op/OpElvis.java index 883ffa1d23..ea9f474922 100644 --- a/core/src/main/java/lucee/transformer/bytecode/op/OpElvis.java +++ b/core/src/main/java/lucee/transformer/bytecode/op/OpElvis.java @@ -32,6 +32,7 @@ import lucee.runtime.op.Elvis; import lucee.transformer.TransformerException; import lucee.transformer.bytecode.BytecodeContext; +import lucee.transformer.bytecode.expression.AsExpression; import lucee.transformer.bytecode.expression.ExpressionBase; import lucee.transformer.bytecode.util.ASMUtil; import lucee.transformer.bytecode.util.Types; @@ -54,7 +55,9 @@ public final class OpElvis extends ExpressionBase { @Override public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException { - if (ASMUtil.hasOnlyDataMembers(left)) return _writeOutPureDataMember(bc, mode); + // FUTURE this is just a patch, for unknown reason the assignment of inline component or closures + // causes a issue, most likely in the way the object uses the stack + if (ASMUtil.hasOnlyDataMembers(left) && !(right instanceof AsExpression)) return _writeOutPureDataMember(bc, mode); String name = createRandom(bc); GeneratorAdapter ga = bc.getAdapter(); diff --git a/loader/build.xml b/loader/build.xml index 3ffbbca8b7..195edafc19 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 1db839b385..8e2a2a4460 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.1.0.197-SNAPSHOT + 6.1.0.198-SNAPSHOT jar Lucee Loader Build diff --git a/test/tickets/LDEV4899.cfc b/test/tickets/LDEV4899.cfc new file mode 100644 index 0000000000..a9de86ca61 --- /dev/null +++ b/test/tickets/LDEV4899.cfc @@ -0,0 +1,52 @@ +component extends = "org.lucee.cfml.test.LuceeTestCase" labels="struct" { + + function run( testResults, testBox ) { + describe( "Testcase for LDEV-4899", function() { + it( title="testing elvis with default closure", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: function(){ return "" }; + }); + it( title="testing elvis with default lambda", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: () => "susi"; + }); + + it( title="testing elvis with default array", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: [1,2,3]; + }); + + it( title="testing elvis with default struct", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: {a:1}; + }); + + it( title="testing elvis with default component", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: new Query(); + }); + + it( title="testing elvis with default inline component", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: new component {}; + }); + + + it( title="testing elvis with default array of closure", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: [function(){ return "" }]; + }); + it( title="testing elvis with default array of lambda", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: [() => "susi"]; + }); + + it( title="testing elvis with default array of struct", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: [{a:1}]; + }); + + it( title="testing elvis with default array of component", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: [new Query()]; + }); + + it( title="testing elvis with default array of inline component", skip="true", body=function( currentSpec ) { + var prop = a.b.c ?: [new component {}]; + }); + + + + }); + } +}