unclefool / jav8

Automatically exported from code.google.com/p/jav8
0 stars 0 forks source link

invokeMethod failed, fixed myself #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
see code below:

engine.eval("var obj = {name : 'tom'}");
engine.eval("obj.test = function() { out.println(this.name)}");
engine.eval("obj.test()");
((Invocable)engine).invokeMethod(engine.eval("obj"), "test");

i have resolve this problem as below:

src/lu/flier/script/V8Function.java : LN 24 append new function 

public Object invoke(long thizObj, Object... args) {
    Object result = internalInvoke(this.obj, thizObj, args);
    return result == null ? null : this.ctxt.bind(result);
}

/src/lu/flier/script/V8ScriptEngine.java : LN 171 replace with :

    V8Function fun = ((V8Function) ((V8Object) thiz).get(name));
    return fun.invoke(((V8Object)thiz).obj, args);

now it's work fine, i am not sure this is the best way, hope your official new 
version.

Original issue reported on code.google.com by ins...@gmail.com on 17 Oct 2013 at 10:20