use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class ScalaTest method interactingWithJavaScript.
@Test
public void interactingWithJavaScript() throws Exception {
ScriptEngine js = JavaScriptTest.getJavaScriptEngine();
Function f = (Function) js.eval("var f = function(n, m) { return n * m; }; f;");
Function2<Object, Object, Object> times = toFunction(LambdaJavaScript.toFn2(f));
assertEquals(6.0, times.apply(2, 3));
scala.bind("timesJS", "Function2[Any, Any, Any]", times);
assertEquals(120.0, scala.eval("List(1, 2, 3, 4, 5).reduceLeft(timesJS)"));
}
use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class JavaScriptTest method convertFnToFunction.
@Test
public void convertFnToFunction() throws ScriptException {
Function f = toFunction(Lambda.λ(s, s.toUpperCase()));
assertEquals("HELLO", f.call(Context.getCurrentContext(), null, null, new Object[] { "hello" }));
}
use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class JavaScriptTest method convertFnToFunctionKeepsDefaultValues.
@Test
public void convertFnToFunctionKeepsDefaultValues() throws ScriptException {
Function f = toFunction(Lambda.λ(s = "world", s.toUpperCase()));
assertEquals("WORLD", f.call(Context.getCurrentContext(), null, null, new Object[0]));
}
use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class JRubyTest method interactingWithJavaScript.
@Test
public void interactingWithJavaScript() throws Exception {
Ruby ruby = Ruby.getGlobalRuntime();
ScriptEngine js = JavaScriptTest.getJavaScriptEngine();
Function f = (Function) js.eval("var f = function(n, m) { return n * m; }; f;");
RubyProc proc = toProc(LambdaJavaScript.toFn2(f));
assertEquals(ruby.newFloat(6), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newFixnum(2), ruby.newFixnum(3) }));
rb.put("block", proc);
assertEquals(120.0, rb.eval("[1, 2, 3, 4, 5].inject &block"));
}
Aggregations