本文整理了Java中com.eclipsesource.v8.V8.executeJSFunction()
方法的一些代码示例,展示了V8.executeJSFunction()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.executeJSFunction()
方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:executeJSFunction
暂无
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = IllegalArgumentException.class)
public void testExecuteJSFunction_InvalidArg() {
v8.executeVoidScript("function add(p1, p2) {return p1 + p2;}");
v8.executeJSFunction("add", new Object(), 8);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_VarArgs() {
v8.executeVoidScript("function add() {return arguments.length;}");
int result = (Integer) v8.executeJSFunction("add", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertEquals(10, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_Float() {
v8.executeVoidScript("function add(p1, p2) {return p1 + p2;}");
double result = (Double) v8.executeJSFunction("add", 3.1f, 2.2f);
assertEquals(5.3, result, 0.00001);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_BooleanSingleParam() {
v8.executeVoidScript("function add(p1) {return p1;}");
boolean result = (Boolean) v8.executeJSFunction("add", false);
assertFalse(result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_IntegerSingleParam() {
v8.executeVoidScript("function add(p1) {return p1;}");
int result = (Integer) v8.executeJSFunction("add", 7);
assertEquals(7, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_nullArray() {
v8.executeVoidScript("function test() { return 'passed';}");
String result = (String) v8.executeJSFunction("test", (Object[]) null);
assertEquals("passed", result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_NoParameters() {
v8.executeVoidScript("function test() { return 'passed';}");
String result = (String) v8.executeJSFunction("test");
assertEquals("passed", result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_Double() {
v8.executeVoidScript("function add(p1, p2) {return p1 + p2;}");
double result = (Double) v8.executeJSFunction("add", 3.1d, 2.2d);
assertEquals(5.3, result, 0.00001);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_null() {
v8.executeVoidScript("function test(p1) { if (!p1) { return 'passed';} }");
String result = (String) v8.executeJSFunction("test", new Object[] { null });
assertEquals("passed", result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_Integer() {
v8.executeVoidScript("function add(p1, p2) {return p1 + p2;}");
int result = (Integer) v8.executeJSFunction("add", 7, 8);
assertEquals(15, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_String() {
v8.executeVoidScript("function add(p1, p2) {return p1 + p2;}");
String result = (String) v8.executeJSFunction("add", "seven", "eight");
assertEquals("seveneight", result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_undefined() {
v8.executeVoidScript("function test(p1) { if (!p1) { return 'passed';} }");
String result = (String) v8.executeJSFunction("test", V8.getUndefined());
assertEquals("passed", result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_Function() {
v8.executeVoidScript("function add(p1, p2) {return p1();}");
V8Function function = new V8Function(v8, new JavaCallback() {
@Override
public Object invoke(final V8Object receiver, final V8Array parameters) {
return 7;
}
});
int result = (Integer) v8.executeJSFunction("add", function);
assertEquals(7, result);
function.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_V8Object() {
V8Object object = new V8Object(v8);
object.add("first", 7).add("second", 8);
v8.executeVoidScript("function add(p1) {return p1.first + p1.second;}");
int result = (Integer) v8.executeJSFunction("add", object);
assertEquals(15, result);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_V8Array() {
V8Array array = new V8Array(v8);
array.push(7).push(8);
v8.executeVoidScript("function add(p1) {return p1[0] + p1[1];}");
int result = (Integer) v8.executeJSFunction("add", array);
assertEquals(15, result);
array.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = Error.class)
public void testSharingObjectsAsFunctionCallParameters_JSFunction() {
V8 engine = null;
V8 engine2 = null;
try {
engine = V8.createV8Runtime();
engine2 = V8.createV8Runtime();
engine.executeScript("b = function(param){ param[0] + param[1];}");
engine2.executeScript("a = [3, 4];");
V8Array a = (V8Array) engine2.get("a");
engine.executeJSFunction("b", a);
} finally {
engine.release(false);
engine2.release(false);
}
}
代码示例来源:origin: stackoverflow.com
V8 v8 = V8.createV8Runtime();
v8.executeScript(readFileAsString("script1")); // contains the function foo();
v8.executeScript(readFileAsString("script2")); // contains the function add(x, y);
v8.executeJSFunction("foo");
v8.executeJSFunction("bar", 7, 8);
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteJSFunction_Mixed() {
V8Array array = new V8Array(v8);
array.push(7).push(8);
V8Object object = new V8Object(v8);
object.add("first", 7).add("second", 8);
v8.executeVoidScript("function add(p1, p2) {return p1[0] + p1[1] + p2.first + p2.second ;}");
int result = (Integer) v8.executeJSFunction("add", array, object);
assertEquals(30, result);
object.close();
array.close();
}
内容来源于网络,如有侵权,请联系作者删除!