Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/main/java/com/dashjoin/jsonata/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1561,9 +1561,10 @@ public static List hofFuncArgs(Object func, Object arg1, Object arg2, Object arg
*/
public static Object funcApply(Object func, List funcArgs) throws Throwable {
Object res;
if (isLambda(func))
res = Jsonata.current.get().apply(func, funcArgs, null, Jsonata.current.get().environment);
else
if (isLambda(func)) {
Jsonata.EvalContext ctx = Jsonata.evalContext.get();
res = ctx.instance.apply(func, funcArgs, null, ctx.environment);
} else
res = ((JFunction)func).call(null, funcArgs);
return res;
}
Expand Down Expand Up @@ -2375,7 +2376,8 @@ public static Object functionEval(String expr, Object focus) {
if(expr == null) {
return null;
}
Object input = Jsonata.current.get().input; // = this.input;
Jsonata.EvalContext ctx = Jsonata.evalContext.get();
Object input = ctx.input;
if(focus != null) {
input = focus;
// if the input is a JSON array, then wrap it in a singleton sequence so it gets treated as a single input
Expand All @@ -2386,7 +2388,7 @@ public static Object functionEval(String expr, Object focus) {
}

Jsonata ast;
Jsonata.Frame env = Jsonata.current.get().environment;
Jsonata.Frame env = ctx.environment;
try {
ast = jsonata(expr);
} catch(Throwable err) {
Expand All @@ -2397,7 +2399,7 @@ public static Object functionEval(String expr, Object focus) {
}
Object result = null;
try {
result = Jsonata.current.get().evaluate(ast.ast, input, env);
result = ctx.instance.evaluate(ast.ast, input, env);
} catch(Throwable err) {
// error evaluating the expression passed to $eval
//populateMessage(err);
Expand All @@ -2412,15 +2414,15 @@ public static Object functionEval(String expr, Object focus) {
// return datetime.fromMillis(timestamp.getTime(), picture, timezone);
// }, "<s?s?:s>"));
public static String now(String picture, String timezone) {
long t = Jsonata.current.get().timestamp;
long t = Jsonata.evalContext.get().timestamp;
return dateTimeFromMillis(t, picture, timezone);
}

// environment.bind("millis", defineFunction(function() {
// return timestamp.getTime();
// }, "<:n>"));
public static long millis() {
long t = Jsonata.current.get().timestamp;
long t = Jsonata.evalContext.get().timestamp;
return t;
}
}
Loading