本文整理了Java中com.eclipsesource.v8.V8.executeStringFunction()
方法的一些代码示例,展示了V8.executeStringFunction()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.executeStringFunction()
方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:executeStringFunction
暂无
代码示例来源:origin: eclipsesource/J2V8
/**
* Invoke a JavaScript function and return the result as a String. If the
* result is not a String, 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 String representing the result of the function call or V8ResultUndefined
* if the result is not a String.
*/
public String executeStringFunction(final String name, final V8Array parameters) {
v8.checkThread();
checkReleased();
v8.checkRuntime(parameters);
long parametersHandle = parameters == null ? 0 : parameters.getHandle();
return v8.executeStringFunction(v8.getV8RuntimePtr(), getHandle(), name, parametersHandle);
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testResultUndefinedForNoReturnInStringFunction() {
v8.executeVoidScript("function foo() {};");
v8.executeStringFunction("foo", null);
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testResultUndefinedForWrongReturnTypeOfStringFunction() {
v8.executeVoidScript("function foo() {return 42;}");
v8.executeStringFunction("foo", null);
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ScriptExecutionException.class)
public void testV8ScriptExceptionStringCall() {
v8.executeVoidScript(errorFunction);
v8.executeStringFunction("myFunction", null);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testObjectMethodReturnsString() {
ICallback callback = mock(ICallback.class);
doReturn("foobar").when(callback).objectMethodNoParameter();
v8.registerJavaMethod(callback, "objectMethodNoParameter", "foo", new Class<?>[] {});
String result = v8.executeStringFunction("foo", null);
assertEquals("foobar", result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testExecuteUnicodeFunction() {
v8.executeVoidScript("var ಠ_ಠ = function() { return '🌞' + '💐'; }; ");
assertEquals("🌞💐", v8.executeStringFunction("ಠ_ಠ", null));
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testStringFunctionCallNullParameters() {
v8.executeVoidScript("function foo() {return 'hello';}");
String result = v8.executeStringFunction("foo", null);
assertEquals("hello", result);
}
代码示例来源:origin: eclipsesource/J2V8
/*** String Function ***/
@Test
public void testSimpleStringFunction() {
v8.executeVoidScript("function foo() {return 'hello';}");
String result = v8.executeStringFunction("foo", null);
assertEquals("hello", result);
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Invoke a JavaScript function and return the result as a String. If the
* result is not a String, 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 String representing the result of the function call or V8ResultUndefined
* if the result is not a String.
*/
public String executeStringFunction(final String name, final V8Array parameters) {
v8.checkThread();
checkReleased();
v8.checkRuntime(parameters);
long parametersHandle = parameters == null ? 0 : parameters.getHandle();
return v8.executeStringFunction(v8.getV8RuntimePtr(), getHandle(), name, parametersHandle);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testStringFunctionCallNoParameters() {
v8.executeVoidScript("function foo() {return 'hello';}");
V8Array parameters = new V8Array(v8);
String result = v8.executeStringFunction("foo", parameters);
assertEquals("hello", result);
parameters.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testStringFunctionNoReturn() {
v8.executeVoidScript("function add(x, y) {;}");
V8Array parameters = new V8Array(v8);
parameters.push(7);
parameters.push(8);
try {
v8.executeStringFunction("add", parameters);
} finally {
parameters.close();
}
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testStringFunctionNotString() {
v8.executeVoidScript("function add(x, y) {return 7;}");
V8Array parameters = new V8Array(v8);
parameters.push(7);
parameters.push(8);
try {
v8.executeStringFunction("add", parameters);
} finally {
parameters.close();
}
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testStringFunctionCall() {
v8.executeVoidScript("function add(x, y) {return x+y;}");
V8Array parameters = new V8Array(v8);
parameters.push("hello, ");
parameters.push("world!");
String result = v8.executeStringFunction("add", parameters);
assertEquals("hello, world!", result);
parameters.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = Error.class)
public void testSharingObjectsAsFunctionCallParameters_StringFunction() {
V8 engine = null;
V8 engine2 = null;
try {
engine = V8.createV8Runtime();
engine2 = V8.createV8Runtime();
engine.executeScript("b = function(param){return param;}");
engine2.executeScript("a = ['foo'];");
V8Array a = (V8Array) engine2.get("a");
engine.executeStringFunction("b", a);
} finally {
engine.release(false);
engine2.release(false);
}
}
代码示例来源:origin: org.sheinbergon/useragent-analyzer-processor-uaparserjs
static Optional<String> executeV8Function(V8 v8, String userAgent) {
V8Array v8FunctionParams = null;
try {
v8.getLocker().acquire();
v8FunctionParams = new V8Array(v8).push(userAgent);
return Optional.ofNullable(v8.executeStringFunction(WRAPPER_FUNCTION, v8FunctionParams));
} finally {
// Release V8 engine function parameters array
Optional.ofNullable(v8FunctionParams)
.ifPresent(V8Array::release);
// Release V8 engine lock
Optional.of(v8.getLocker())
.filter(V8Locker::hasLock)
.ifPresent(V8Locker::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);
}
}
代码示例来源: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: com.eclipsesource.j2v8/j2v8_win32_x86_64
/**
* Invoke a JavaScript function and return the result as a String. If the
* result is not a String, 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 String representing the result of the function call or V8ResultUndefined
* if the result is not a String.
*/
public String executeStringFunction(final String name, final V8Array parameters) {
v8.checkThread();
checkReleased();
long parametersHandle = parameters == null ? 0 : parameters.getHandle();
return v8.executeStringFunction(v8.getV8RuntimePtr(), getHandle(), name, parametersHandle);
}
代码示例来源:origin: com.eclipsesource.j2v8/j2v8_macosx_x86_64
/**
* Invoke a JavaScript function and return the result as a String. If the
* result is not a String, 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 String representing the result of the function call or V8ResultUndefined
* if the result is not a String.
*/
public String executeStringFunction(final String name, final V8Array parameters) {
v8.checkThread();
checkReleased();
long parametersHandle = parameters == null ? 0 : parameters.getHandle();
return v8.executeStringFunction(v8.getV8RuntimePtr(), getHandle(), name, parametersHandle);
}
代码示例来源:origin: michel-kraemer/vertx-lang-typescript
return runtime.executeStringFunction("compileTypescript", args);
} finally {
args.release();
内容来源于网络,如有侵权,请联系作者删除!