本文整理了Java中com.eclipsesource.v8.V8.executeScript()
方法的一些代码示例,展示了V8.executeScript()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.executeScript()
方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:executeScript
[英]Executes a JS Script on this runtime and returns the result as a Java Object. Primitives will be boxed.
[中]在此运行时执行JS脚本,并将结果作为Java对象返回。原语将被装箱。
代码示例来源:origin: eclipsesource/J2V8
/**
* Executes a JS Script on this runtime and returns the result as a Java Object.
* Primitives will be boxed.
*
* @param script The script to execute.
*
* @return The result of the script as a Java Object.
*/
public Object executeScript(final String script) {
return executeScript(script, null, 0);
}
代码示例来源:origin: jooby-project/jooby
private static Object load(Class<?> loader, V8 v8, final String path) throws Exception {
return v8.executeScript(V8Engine.readFile(loader, path), path, 0);
}
}
代码示例来源:origin: jooby-project/jooby
private static Object load(Class<?> loader, V8 v8, final String path) throws Exception {
return register(v8, v8.executeScript(readFile(loader, path), path, 0));
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Executes a JS Script on this runtime and returns the result as a V8Array.
* If the result is not a V8Array, then a V8ResultUndefinedException is thrown.
*
* @param script The script to execute.
* @param scriptName The name of the script
* @param lineNumber The line number that is considered to be the first line of
* the script. Typically 0, but could be set to another value for exception stack trace purposes.
*
* @return The result of the script as a V8Array, or V8ResultUndefinedException if
* the result is not a V8Array.
*/
public V8Array executeArrayScript(final String script, final String scriptName, final int lineNumber) {
checkThread();
Object result = this.executeScript(script, scriptName, lineNumber);
if (result instanceof V8Array) {
return (V8Array) result;
}
throw new V8ResultUndefined();
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Executes a JS Script on this runtime and returns the result as a V8Object.
* If the result is not a V8Object, then a V8ResultUndefinedException is thrown.
*
* @param script The script to execute.
* @param scriptName The name of the script
* @param lineNumber The line number that is considered to be the first line of
* the script. Typically 0, but could be set to another value for exception stack trace purposes.
*
* @return The result of the script as a V8Object, or V8ResultUndefinedException if
* the result is not a V8Object.
*/
public V8Object executeObjectScript(final String script, final String scriptName, final int lineNumber) {
checkThread();
Object result = this.executeScript(script, scriptName, lineNumber);
if (result instanceof V8Object) {
return (V8Object) result;
}
throw new V8ResultUndefined();
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Executes a JS Script on this runtime and returns the result as a Java Object.
* Primitives will be boxed.
*
* @param script The script to execute.
* @param scriptName The name of the script
* @param lineNumber The line number that is considered to be the first line of
* the script. Typically 0, but could be set to another value for exception stack trace purposes.
*
* @return The result of the script as a Java Object.
*/
public Object executeScript(final String script, final String scriptName, final int lineNumber) {
checkThread();
checkScript(script);
return executeScript(getV8RuntimePtr(), UNKNOWN, script, scriptName, lineNumber);
}
代码示例来源:origin: eclipsesource/J2V8
Object scriptResult = runtime.executeScript("__j2v8__checkThreadTerminate();\n" + script, getName(), -1);
if (scriptResult != null) {
result = scriptResult.toString();
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAnyScriptReturnString() {
Object result = v8.executeScript("'foo';");
assertEquals("foo", result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAnyScriptReturnBoolean() {
Object result = v8.executeScript("false;");
assertFalse((Boolean) result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleCreated_AccessedArray() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8Array object = (V8Array) v8.executeScript("[1,2,3];");
verify(referenceHandler, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8RuntimeException.class)
public void testCannotPushStringToTypedArray() {
V8Array array = (V8Array) v8.executeScript("var buf = new ArrayBuffer(8); var ints = new Int32Array(buf); ints");
try {
array.push("foo");
} finally {
array.close();
}
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAnyScriptReturnsV8Object() {
V8Object result = (V8Object) v8.executeScript("foo = {hello:'world'}; foo;");
assertEquals("world", result.getString("hello"));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAnyScriptWithName() {
V8Object result = (V8Object) v8.executeScript("foo = {hello:'world'}; foo;", "name", 6);
assertEquals("world", result.getString("hello"));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testEmptyArrayBufferReturned() {
V8ArrayBuffer arrayBuffer = (V8ArrayBuffer) v8.executeScript("new ArrayBuffer(0);");
assertEquals(arrayBuffer.capacity(), 0);
arrayBuffer.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testGetTypedArrayIntType() {
V8Array result = (V8Array) v8.executeScript("var buf = new ArrayBuffer(4); var ints = new Int16Array(buf); ints[0] = 7; ints");
assertEquals(V8Value.INTEGER, result.getType(0));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testGetTypedArrayType16BitValue() {
V8Array result = (V8Array) v8.executeScript("var buf = new ArrayBuffer(4); var ints = new Int16Array(buf); ints[0] = 255; ints");
assertEquals((short) 255, result.get(0));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testGetTypedArrayType32BitFloatValue() {
V8Array result = (V8Array) v8.executeScript("var buf = new ArrayBuffer(4); var floats = new Float32Array(buf); floats[0] = 255.5; floats");
assertEquals(255.5, result.getDouble(0), 0.00001);
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAccessArrayBuffer_Int8ArrayView() {
V8ArrayBuffer buffer = (V8ArrayBuffer) v8.executeScript("var buf = new ArrayBuffer(4); var ints = new Int8Array(buf); ints[0] = 7; buf");
assertEquals(4, buffer.limit());
assertEquals(7, buffer.get(0));
buffer.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAccessArrayBuffer_Float32rrayView() {
V8ArrayBuffer buffer = (V8ArrayBuffer) v8.executeScript("var buf = new ArrayBuffer(4); var floats = new Float32Array(buf); floats[0] = 7.7; buf");
assertEquals(1, buffer.floatLimit());
assertEquals(7.7, buffer.getFloat(0), 0.00001);
buffer.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testGetBytesFromTypedArray() {
V8Array result = (V8Array) v8.executeScript("var buf = new ArrayBuffer(8); var bytes = new Int8Array(buf); bytes[0] = 1; bytes[1] = 256; bytes");
assertEquals(V8Value.BYTE, result.getType());
assertEquals(1, result.getByte(0));
assertEquals(0, result.getByte(1));
result.close();
}
内容来源于网络,如有侵权,请联系作者删除!