use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class GroovyTest 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;");
ClosureFn2 closure = toClosure(LambdaJavaScript.toFn2(f));
assertEquals(6.0, closure.call(new Object[] { 2, 3 }));
groovy.put("closure", closure);
assertEquals(120.0, groovy.eval("[1, 2, 3, 4, 5].inject(1, closure)"));
}
use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class JavaScriptTest method convertFunctionToFn.
@Test
public void convertFunctionToFn() throws ScriptException {
Function f = (Function) js.eval("var f = function(s) { return s.toUpperCase(); }; f;");
assertEquals("HELLO", toFn1(f).call("hello"));
}
use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class ClojureTest 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;");
IFn times = toIFn(LambdaJavaScript.toFn2(f));
assertEquals(6.0, times.invoke(2, 3));
defn("times-js", times);
assertEquals(120.0, clj.eval("(reduce times-js 1 [1, 2, 3, 4, 5])"));
}
use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class JavaScriptTest method convertedFunctionIgnoresExtraArguments.
public void convertedFunctionIgnoresExtraArguments() throws ScriptException {
Function f = toFunction(Lambda.λ(s, s.toUpperCase()));
assertEquals("HELLO", f.call(Context.getCurrentContext(), null, null, new Object[] { "hello", "world" }));
}
use of sun.org.mozilla.javascript.internal.Function in project enumerable by hraberg.
the class JavaScriptTest method convertedFunctionThrowsExceptionWhenCalledWithTooFewArguments.
@Test(expected = NullPointerException.class)
public void convertedFunctionThrowsExceptionWhenCalledWithTooFewArguments() throws ScriptException {
Function f = toFunction(Lambda.λ(s, s.toUpperCase()));
f.call(Context.getCurrentContext(), null, null, new Object[0]);
}
Aggregations