本文整理了Java中com.eclipsesource.v8.V8.executeDoubleFunction()
方法的一些代码示例,展示了V8.executeDoubleFunction()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.executeDoubleFunction()
方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:executeDoubleFunction
暂无
代码示例来源:origin: eclipsesource/J2V8
/**
* Invoke a JavaScript function and return the result as a double. If the
* result is not a double, or does not exist, then V8ResultUndefined is thrown.
*
* @param name The name of the JS Function to call.
*
* @param parameters The parameters to pass to the function. Parameters must be released.
*
* @return A double representing the result of the function call or V8ResultUndefined
* if the result is not a double.
*/
public double executeDoubleFunction(final String name, final V8Array parameters) {
v8.checkThread();
checkReleased();
v8.checkRuntime(parameters);
long parametersHandle = parameters == null ? 0 : parameters.getHandle();
return v8.executeDoubleFunction(v8.getV8RuntimePtr(), getHandle(), name, parametersHandle);
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testResultUndefinedForNoReturnInDoubleFunction() {
v8.executeVoidScript("function foo() {};");
v8.executeDoubleFunction("foo", null);
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testResultUndefinedForWrongReturnTypeOfDoubleFunction() {
v8.executeVoidScript("function foo() {return 'foo';}");
v8.executeDoubleFunction("foo", null);
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ScriptExecutionException.class)
public void testV8ScriptExceptionDoubleCall() {
v8.executeVoidScript(errorFunction);
v8.executeDoubleFunction("myFunction", null);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testObjectMethodReturnsDouble() {
ICallback callback = mock(ICallback.class);
doReturn(7.7).when(callback).objectMethodNoParameter();
v8.registerJavaMethod(callback, "objectMethodNoParameter", "foo", new Class<?>[] {});
double result = v8.executeDoubleFunction("foo", null);
assertEquals(7.7, result, 0.000001);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testDoubleFunctionCallNullParameters() {
v8.executeVoidScript("function foo() {return 7.1;}");
double result = v8.executeDoubleFunction("foo", null);
assertEquals(7.1, result, 0.000001);
}
代码示例来源:origin: eclipsesource/J2V8
/*** Double Function ***/
@Test
public void testSimpleDoubleFunction() {
v8.executeVoidScript("function foo() {return 3.14 + 1;}");
double result = v8.executeDoubleFunction("foo", null);
assertEquals(4.14, result, 0.000001);
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Invoke a JavaScript function and return the result as a double. If the
* result is not a double, or does not exist, then V8ResultUndefined is thrown.
*
* @param name The name of the JS Function to call.
*
* @param parameters The parameters to pass to the function. Parameters must be released.
*
* @return A double representing the result of the function call or V8ResultUndefined
* if the result is not a double.
*/
public double executeDoubleFunction(final String name, final V8Array parameters) {
v8.checkThread();
checkReleased();
v8.checkRuntime(parameters);
long parametersHandle = parameters == null ? 0 : parameters.getHandle();
return v8.executeDoubleFunction(v8.getV8RuntimePtr(), getHandle(), name, parametersHandle);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testDoubleFunctionCallNoParameters() {
v8.executeVoidScript("function foo() {return 7.2;}");
V8Array parameters = new V8Array(v8);
double result = v8.executeDoubleFunction("foo", parameters);
assertEquals(7.2, result, 0.0000001);
parameters.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testDoubleFunctionNotDouble() {
v8.executeVoidScript("function add(x, y) {return 'bar';}");
V8Array parameters = new V8Array(v8);
parameters.push(7);
parameters.push(8);
try {
v8.executeDoubleFunction("add", parameters);
} finally {
parameters.close();
}
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testDoubleFunctionNoReturn() {
v8.executeVoidScript("function add(x, y) {;}");
V8Array parameters = new V8Array(v8);
parameters.push(7);
parameters.push(8);
try {
v8.executeDoubleFunction("add", parameters);
} finally {
parameters.close();
}
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testDoubleFunctionCall() {
v8.executeVoidScript("function add(x, y) {return x+y;}");
V8Array parameters = new V8Array(v8);
parameters.push(1.1);
parameters.push(2.2);
double result = v8.executeDoubleFunction("add", parameters);
assertEquals(3.3, result, 0.000001);
parameters.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = Error.class)
public void testSharingObjectsAsFunctionCallParameters_DoubleFunction() {
V8 engine = null;
V8 engine2 = null;
try {
engine = V8.createV8Runtime();
engine2 = V8.createV8Runtime();
engine.executeScript("b = function(param){return param;}");
engine2.executeScript("a = [3.14];");
V8Array a = (V8Array) engine2.get("a");
engine.executeDoubleFunction("b", a);
} finally {
engine.release(false);
engine2.release(false);
}
}
代码示例来源:origin: com.eclipsesource.j2v8/j2v8_win32_x86_64
/**
* Invoke a JavaScript function and return the result as a double. If the
* result is not a double, or does not exist, then V8ResultUndefined is thrown.
*
* @param name The name of the JS Function to call.
*
* @param parameters The parameters to pass to the function. Parameters must be released.
*
* @return A double representing the result of the function call or V8ResultUndefined
* if the result is not a double.
*/
public double executeDoubleFunction(final String name, final V8Array parameters) {
v8.checkThread();
checkReleased();
long parametersHandle = parameters == null ? 0 : parameters.getHandle();
return v8.executeDoubleFunction(v8.getV8RuntimePtr(), getHandle(), name, parametersHandle);
}
代码示例来源:origin: com.eclipsesource.j2v8/j2v8_macosx_x86_64
/**
* Invoke a JavaScript function and return the result as a double. If the
* result is not a double, or does not exist, then V8ResultUndefined is thrown.
*
* @param name The name of the JS Function to call.
*
* @param parameters The parameters to pass to the function. Parameters must be released.
*
* @return A double representing the result of the function call or V8ResultUndefined
* if the result is not a double.
*/
public double executeDoubleFunction(final String name, final V8Array parameters) {
v8.checkThread();
checkReleased();
long parametersHandle = parameters == null ? 0 : parameters.getHandle();
return v8.executeDoubleFunction(v8.getV8RuntimePtr(), getHandle(), name, parametersHandle);
}
内容来源于网络,如有侵权,请联系作者删除!