invoking method of nested js objects

Viktor Gamov viktor.gamov at gmail.com
Tue Sep 3 16:20:31 PDT 2013


Hello nashorn team,

I have a question regarding how to invoke function that deeply nested inside object.
Here is example:

@Test
public void useCase_7() throws ScriptException, LoadError, NoSuchMethodException {
    engine.eval("x = {a: {b: {c: function(a, b) { return a + b } } } }");
    Invocable inv = (Invocable) engine;
    Assert.assertEquals("function reference chain", inv.invokeFunction("x.a.b.c", 2, 3), 5.0);
}

And I'm getting java.lang.NoSuchMethodException: No such function x.a.b.c

Invoke method doesn't seem to work as well.

@Test
public void useCase_8() throws ScriptException, LoadError, NoSuchMethodException {
    engine.eval("x = {a: {b: {c: function(a, b) { return a + b } } } }");
    Invocable inv = (Invocable) engine;
    Object x = engine.get("x");
    Assert.assertEquals("function reference chain", inv.invokeMethod(x, "a.b.c", 2, 3), 5.0);
}

What is correct way to do that?
Please, advice
Thanks		

-- 
With Best Regards, 
Vik Gamov


More information about the nashorn-dev mailing list