Repository navigation
Conversation
Partially applying a native function now wraps the function itself as the lambda body (bodyAST.body = native) instead of generating a trampoline expression that calls the builtin by name. As in JS, the signature of the native function is not validated when the partial is invoked. - implement applyNativeFunction / getNativeFunctionArguments - only '?' leaves a parameter unbound, missing args are bound to null (#86) - fix '?' comparison (token value is a Character) - no lookup by name, so unnamed / custom JFunctions work (#83) - arity of a JFunctionCallable is taken from its signature - arrays now reach $each / $merge, which iterate them like JS for..in since #131 (#79) - fix inverted T1007 check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aeberhart
commented
Nov 5, 2026
| for(var ii = 0; ii < expr.arguments.size(); ii++) { | ||
| var arg = expr.arguments.get(ii); | ||
| if (arg.type.equals("operator") && (arg.value.equals("?"))) { | ||
| if (arg.type.equals("operator") && (""+arg.value).equals("?")) { |
Contributor
Author
There was a problem hiding this comment.
fixes char - string equals which use to be false always
| // lookup the procedure | ||
| var proc = /* await */ evaluate(expr.procedure, input, environment); | ||
| if (proc != null && expr.procedure.type.equals("path") && environment.lookup((String)expr.procedure.steps.get(0).value)!=null) { | ||
| if (proc == null && expr.procedure.type.equals("path") && environment.lookup((String)expr.procedure.steps.get(0).value)!=null) { |
Contributor
Author
There was a problem hiding this comment.
original:
// lookup the procedure
var proc = await evaluate(expr.procedure, input, environment);
if (typeof proc === 'undefined' && expr.procedure.type === 'path' && environment.lookup(expr.procedure.steps[0].value)) {
| } | ||
| if (proc.body instanceof Symbol) { | ||
| result = evaluate(proc.body, proc.input, env); | ||
| if (proc.body instanceof JFunction) { |
Contributor
Author
There was a problem hiding this comment.
moves commented out code from line 1979 on the left
| // proc.arguments.forEach(Object (param, index) { | ||
| Object arg = index<args.size() ? args.get(index) : null; | ||
| if ((arg==null) || (arg instanceof Symbol && ("operator".equals(((Symbol)arg).type) && "?".equals(((Symbol)arg).value)))) { | ||
| if (arg instanceof Symbol && ("operator".equals(((Symbol)arg).type) && "?".equals(""+((Symbol)arg).value))) { |
Contributor
Author
There was a problem hiding this comment.
original:
if (arg && arg.type === 'operator' && arg.value === '?') {
| // return "$" + sigArg; | ||
| // }).toList(); | ||
| // var body = "function(" + String.join(", ", sigArgs) + "){ _ }"; | ||
| var sigArgs = getNativeFunctionArguments(_native); |
Contributor
Author
There was a problem hiding this comment.
move commented out code from line 2042 on the left
|
|
||
| var bodyAST = parser.parse(body); | ||
| //bodyAST.body = _native; | ||
| bodyAST.body = _native; |
Contributor
Author
There was a problem hiding this comment.
point to parent of this partial fn
| if (method != null) | ||
| return method.getParameterTypes().length; | ||
| // Java: a JFunctionCallable has no declared parameters, use the signature (if any) | ||
| return signature != null ? signature.getNumberOfArgs() : 0; |
Contributor
Author
There was a problem hiding this comment.
the third part will address this
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second of three PRs split out of #130. Builds on #131 (already merged).
Fixes #79, #86
Root cause
jsonata-js partially applies a native function by building
function($a, $b){ _ }and setting the body to the native function itself (bodyAST.body = native). When the partial is invoked,applyProcedurecallsapplyNativeFunction, which does not validate the signature. The Java port instead generated a trampoline expression that called the builtin by name ($each($a, $b)). So the signature was checked again, and the function had to be looked up by name.Changes (following the JS code)
partialApplyNativeFunctionsetsbodyAST.body = _native(Symbol.bodyis nowObject). Implemented the commented-outapplyNativeFunction/getNativeFunctionArgumentsand the native branch inapplyProcedure.partialApplyProcedure: only?leaves a parameter unbound. Missing args are bound to null, the way JS bindsundefined(incorrect result when $map($, $append(?)) #86).?comparison: the token value is aCharacter, soarg.value.equals("?")was always false.JFunctions with a signature can be partially applied.proc != nullvs JStypeof proc === 'undefined').$each/$mergethrough partials such as[5,6] ~> $each(?, …). Those functions iterate arrays like JSfor..insince $each / $merge iterate arrays like JS for..in #131 (Incorrect each function signature validation #79).Notes for reviewers
JFunctionis taken from its implementing method or its signature. Partially applying custom functions without a signature,Fn*lambdas, and lambdas bound viaFrame.bindis left for the third PR (Custom function pipe error #83, together with theJLambdaAPI change). The two Issues-83: Custom function pipe error #85 tests that need it are not included here.$each([5,6], …)directly is still rejected with T0410, because the signature is still checked on direct calls."variable".equals(...)and added the(Symbol)cast forbody.Testing
PartialTest(8 cases): Incorrect each function signature validation #79, incorrect result when $map($, $append(?)) #86, a custom function with a signature, binding of missing args,$merge(?)with arrays, T1007.OldPrsTest(6 cases): taken from Issues-79: fix each partial invoke #80, Issues-83: Custom function pipe error #85, ISSUES-86: fix arguments checked #87, including themap_in_pipeexample.-Dmaven.compiler.release=11.🤖 Generated with Claude Code