3

I have this JS function:

function newJSArray() {return []}

That I am trying to return in Java using the following method:

public static NativeArray newArray() throws Exception {
    return (NativeArray)invocable.invokeFunction("newJSArray");
}

But it's throwing an exception when I try to invoke this function:

Exception in thread "main" java.lang.NoSuchMethodError: ....JavaScript.newArray()Ljdk/nashorn/api/scripting/JSObject;
    at ....

I want to be given a JS array specifically so I can call jsArr1.concat(jsArr2).

2 Answers 2

2

Yes, all API methods return JavaScript objects as instances of jdk.nashorn.api.scripting.JSObject. You can access members of that JS array by JSObject.getSlot method.

Sign up to request clarification or add additional context in comments.

Comments

0

Found out that the object returned was a JSObject.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.