Skip to content
Permalink
Browse files
JEXL-358: correct closure evaluator;
- add test;
  • Loading branch information
henrib committed Jan 26, 2022
1 parent 93591bd commit 0e186325b2ee03dcc3e5d96aafff1f70b276ccd6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
@@ -1005,9 +1005,16 @@ protected Object visitLexicalNode(final JexlNode node, final Object data) {
*/
protected Object runClosure(final Closure closure, final Object data) {
final ASTJexlScript script = closure.getScript();
// if empty script, nothing to evaluate
final int numChildren = script.jjtGetNumChildren();
if (numChildren == 0) {
return null;
}
block = new LexicalFrame(frame, block).defineArgs();
try {
final JexlNode body = script.jjtGetChild(script.jjtGetNumChildren() - 1);
final JexlNode body = script instanceof ASTJexlLambda
? script.jjtGetChild(numChildren - 1)
: script;
return interpret(body);
} finally {
block = block.pop();
@@ -297,6 +297,30 @@ public void testCurry3() throws Exception {
Assert.assertEquals(42, result);
}

@Test
public void testCurry4() throws Exception {
final JexlEngine jexl = createEngine();
JexlScript script;
Object result;

final JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
script = base.curry(5);
result = script.execute(null, 15, 22);
Assert.assertEquals(42, result);
}

@Test
public void testCurry5() throws Exception {
final JexlEngine jexl = createEngine();
JexlScript script;
Object result;

final JexlScript base = jexl.createScript("var t = x + y + z; return t", "x", "y", "z");
script = base.curry(5);
result = script.execute(null, 15, 22);
Assert.assertEquals(42, result);
}

@Test
public void test270() throws Exception {
final JexlEngine jexl = createEngine();

0 comments on commit 0e18632

Please sign in to comment.