本文整理了Java中com.eclipsesource.v8.V8.executeObjectFunction()
方法的一些代码示例,展示了V8.executeObjectFunction()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.executeObjectFunction()
方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:executeObjectFunction
暂无
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ScriptExecutionException.class)
public void testV8ScriptExceptionObjectCall() {
v8.executeVoidScript(errorFunction);
v8.executeObjectFunction("myFunction", null);
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testResultUndefinedForWrongReturnTypeOfObjectFunction() {
v8.executeVoidScript("function foo() {return 'foo';}");
v8.executeObjectFunction("foo", null);
}
代码示例来源:origin: eclipsesource/J2V8
@SuppressWarnings("resource")
@Test
public void testObjectMethodReturnsV8Object() {
ICallback callback = mock(ICallback.class);
doReturn(new V8Object(v8).add("foo", "bar")).when(callback).objectMethodNoParameter();
v8.registerJavaMethod(callback, "objectMethodNoParameter", "foo", new Class<?>[] {});
V8Object result = v8.executeObjectFunction("foo", null);
assertEquals("bar", result.getString("foo"));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testResultUndefinedForNoReturnInobjectFunction() {
v8.executeVoidScript("function foo() {};");
V8Object result = v8.executeObjectFunction("foo", null);
assertTrue(result.isUndefined());
}
代码示例来源:origin: eclipsesource/J2V8
/*** Object Function ***/
@Test
public void testSimpleObjectFunction() {
v8.executeVoidScript("function foo() {return {foo:true};}");
V8Object result = v8.executeObjectFunction("foo", null);
assertTrue(result.getBoolean("foo"));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
/*** Execute Object Function ***/
@Test
public void testObjectScript() {
v8.executeVoidScript("function foo() { return { x : 7 }} ");
V8Object result = v8.executeObjectFunction("foo", null);
assertEquals(7, result.getInteger("x"));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testObjectFunctionCallNullParameters() {
v8.executeVoidScript("function foo() {return {a:'b'};}");
V8Object result = v8.executeObjectFunction("foo", null);
assertEquals("b", result.getString("a"));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testObjectFunctionNotObject() {
v8.executeVoidScript("function add(x, y) {return 7;}");
V8Array parameters = new V8Array(v8);
parameters.push(7);
parameters.push(8);
try {
v8.executeObjectFunction("add", parameters);
} finally {
parameters.close();
}
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testObjectFunctionCallNoParameters() {
v8.executeVoidScript("function foo() {return {bar:8};}");
V8Array parameters = new V8Array(v8);
V8Object result = v8.executeObjectFunction("foo", parameters);
assertEquals(8, result.getInteger("bar"));
parameters.close();
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = Error.class)
public void testSharingObjectsAsFunctionCallParameters_ObjectFunction() {
V8 engine = null;
V8 engine2 = null;
try {
engine = V8.createV8Runtime();
engine2 = V8.createV8Runtime();
engine.executeScript("b = function(param){return param;}");
engine2.executeScript("a = [{name: 'joe'}];");
V8Array a = (V8Array) engine2.get("a");
engine.executeObjectFunction("b", a);
} finally {
engine.release(false);
engine2.release(false);
}
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testEqualsPassByReference() {
v8.executeVoidScript("o = {}");
v8.executeVoidScript("function ident(x){return x;}");
V8Object o1 = v8.executeObjectScript("o");
V8Array parameters = new V8Array(v8);
parameters.push(o1);
V8Object o2 = v8.executeObjectFunction("ident", parameters);
assertEquals(o1, o2);
assertNotSame(o1, o2);
o1.close();
o2.close();
parameters.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testObjectFunctionCall() {
v8.executeVoidScript("function getPerson(first, last, age) {return {'first':first, 'last':last, 'age':age};}");
V8Array parameters = new V8Array(v8);
parameters.push("John");
parameters.push("Smith");
parameters.push(7);
V8Object result = v8.executeObjectFunction("getPerson", parameters);
assertEquals("John", result.getString("first"));
assertEquals("Smith", result.getString("last"));
assertEquals(7, result.getInteger("age"));
parameters.close();
result.close();
}
代码示例来源:origin: michel-kraemer/citeproc-java
@Override
@SuppressWarnings("unchecked")
public <T> T callMethod(String name, Class<T> resultType, Object... args)
throws ScriptRunnerException {
Set<V8Value> newValues = new HashSet<>();
V8Array parameters = convertArguments(args, newValues);
try {
if (String.class.isAssignableFrom(resultType)) {
return (T)runtime.executeStringFunction(name, parameters);
}
return convert(runtime.executeObjectFunction(name, parameters), resultType);
} catch (V8RuntimeException e) {
throw new ScriptRunnerException("Could not call method", e);
} finally {
newValues.forEach(V8Value::release);
}
}
代码示例来源:origin: de.undercouch/citeproc-java
@Override
@SuppressWarnings("unchecked")
public <T> T callMethod(String name, Class<T> resultType, Object... args)
throws ScriptRunnerException {
Set<V8Value> newValues = new HashSet<>();
V8Array parameters = convertArguments(args, newValues);
try {
if (String.class.isAssignableFrom(resultType)) {
return (T)runtime.executeStringFunction(name, parameters);
}
return convert(runtime.executeObjectFunction(name, parameters), resultType);
} catch (V8RuntimeException e) {
throw new ScriptRunnerException("Could not call method", e);
} finally {
newValues.forEach(V8Value::release);
}
}
内容来源于网络,如有侵权,请联系作者删除!