Revision: 4893 http://sourceforge.net/p/vexi/code/4893 Author: mkpg2 Date: 2016-10-28 18:11:40 +0000 (Fri, 28 Oct 2016) Log Message: ----------- Support setting 'this' when making direct js call from java.
Modified Paths: -------------- branches/vexi3/org.vexi-core.devtools/src/test/java/test/debug/DebuggerTestCase.java branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Interpreter.java branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Scheduler.java branches/vexi3/org.vexi-library.js/src/test/java/test/js/threading/Scripting.java Modified: branches/vexi3/org.vexi-core.devtools/src/test/java/test/debug/DebuggerTestCase.java =================================================================== --- branches/vexi3/org.vexi-core.devtools/src/test/java/test/debug/DebuggerTestCase.java 2016-10-28 01:45:47 UTC (rev 4892) +++ branches/vexi3/org.vexi-core.devtools/src/test/java/test/debug/DebuggerTestCase.java 2016-10-28 18:11:40 UTC (rev 4893) @@ -26,7 +26,7 @@ org.vexi.core.Main.SCHEDULER.add(new Callable(){ public Object run(Object o) throws Exception { JS function = Util.getStatic(v, main, "runtest"); - org.vexi.core.Main.SCHEDULER.runInNew(function, new JS[]{}); + org.vexi.core.Main.SCHEDULER.runInNew(function); return null; } }); Modified: branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Interpreter.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Interpreter.java 2016-10-28 01:45:47 UTC (rev 4892) +++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Interpreter.java 2016-10-28 18:11:40 UTC (rev 4893) @@ -96,14 +96,14 @@ this.old = thread.currentInterpreter; thread.currentInterpreter = this; } - Interpreter(Thread thread, JSFunction f, boolean pauseable, JS[] args) { + Interpreter(Thread thread, JSFunction f, boolean pauseable, JS this_, JS[] args) { this(thread); this.f = f.f; this.pausecount = pauseable ? 0 : -1; this.scope = f.parentScope; try { stack.push(new CallMarker(null)); // the "root function returned" marker -- f==null - stack.push(new JSArgs(args, f, null)); // FIXME: temprorary bug fix + stack.push(new JSArgs(args, f, this_)); // FIXME: temprorary bug fix } catch(JSExn e) { throw new Error("should never happen"); } Modified: branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Scheduler.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Scheduler.java 2016-10-28 01:45:47 UTC (rev 4892) +++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Scheduler.java 2016-10-28 18:11:40 UTC (rev 4893) @@ -179,10 +179,10 @@ } - public void runInNew(JS function) throws JSExn { runInNew(function, null, null); } - public void runInNew(JS function, JS[] args, Callable<Object, JS> callback) throws JSExn { + public void runInNew(JS function) throws JSExn { runInNew(function, null, null, null); } + public void runInNew(JS function, JS this_, JS[] args, Callable<Object, JS> callback) throws JSExn { Thread thread = newThread(this, "background", function, true, callback); - thread.currentInterpreter = new Interpreter(thread, (JSFunction)function, true, args); + thread.currentInterpreter = new Interpreter(thread, (JSFunction)function, true, this_, args); add(thread); } public void runInNew(Trap trap, JS trapname, JS put, Callable<Object, JS> callback) throws JSExn { @@ -338,7 +338,7 @@ } Interpreter old = jsthread.currentInterpreter; // Always false. Restarting paused nested Interpreters not supported. - Interpreter I = new Interpreter(jsthread, (JSFunction)function, /*jsthread.pauseable*/false, args); + Interpreter I = new Interpreter(jsthread, (JSFunction)function, /*jsthread.pauseable*/false, this_, args); try { return (JS)I.run(null); } finally { @@ -446,10 +446,10 @@ return null; // doesn't matter since we are paused } - public JS syncCall(JS function, JS[] args) throws JSExn, InterruptedException{ + public JS syncCall(JS function, JS this_, JS[] args) throws JSExn, InterruptedException{ final CountDownLatch latch0 = new CountDownLatch(1); final Object[] retArr = new Object[1]; - runInNew(function, args, new Callable<Object, JS>() { + runInNew(function, this_, args, new Callable<Object, JS>() { public JS run(Object ret) throws Exception { retArr[0] = ret; latch0.countDown(); Modified: branches/vexi3/org.vexi-library.js/src/test/java/test/js/threading/Scripting.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/test/java/test/js/threading/Scripting.java 2016-10-28 01:45:47 UTC (rev 4892) +++ branches/vexi3/org.vexi-library.js/src/test/java/test/js/threading/Scripting.java 2016-10-28 18:11:40 UTC (rev 4893) @@ -112,14 +112,14 @@ public void run(final String name, final Reader reader) throws Exception{ final Function f = ExecParser.parse(name, 0, reader); final JSFunction run = JSU.cloneWithNewGlobalScope(f, GLOBAL); - SCHEDULER.syncCall(run, null); + SCHEDULER.syncCall(run, null, null); } public JS callMethod(boolean throwexn) throws Exception { if(method==null){ throw new Exception("method not initialised"); } - return SCHEDULER.syncCall(method, new JS[]{JSU.B(throwexn)}); + return SCHEDULER.syncCall(method, null, new JS[]{JSU.B(throwexn)}); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy! http://sdm.link/telerik _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn