本文整理了Java中com.eclipsesource.v8.V8.executeIntegerScript()
方法的一些代码示例,展示了V8.executeIntegerScript()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.executeIntegerScript()
方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:executeIntegerScript
[英]Executes a JS Script on this runtime and returns the result as an integer. If the result is not an integer, then a V8ResultUndefinedException is thrown.
[中]在此运行时上执行JS脚本,并将结果作为整数返回。如果结果不是整数,则抛出V8ResultUndefinedException。
代码示例来源:origin: eclipsesource/J2V8
/**
* Executes a JS Script on this runtime and returns the result as an integer.
* If the result is not an integer, then a V8ResultUndefinedException is thrown.
*
* @param script The script to execute.
*
* @return The result of the script as an integer, or V8ResultUndefinedException if
* the result is not an integer.
*/
public int executeIntegerScript(final String script) {
return executeIntegerScript(script, null, 0);
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Executes a JS Script on this runtime and returns the result as an integer.
* If the result is not an integer, 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 excepton purposes.
*
* @return The result of the script as an integer, or V8ResultUndefinedException if
* the result is not an integer.
*/
public int executeIntegerScript(final String script, final String scriptName, final int lineNumber) {
checkThread();
checkScript(script);
return executeIntegerScript(v8RuntimePtr, script, scriptName, lineNumber);
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Executes a JS Script on this runtime and returns the result as an integer.
* If the result is not an integer, then a V8ResultUndefinedException is thrown.
*
* @param script The script to execute.
*
* @return The result of the script as an integer, or V8ResultUndefinedException if
* the result is not an integer.
*/
public int executeIntegerScript(final String script) {
return executeIntegerScript(script, null, 0);
}
代码示例来源:origin: eclipsesource/J2V8
@Override
public void run(final V8 v8) {
Assert.assertEquals(3344, v8.executeIntegerScript("i"));
}
});
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testCreateV8ObjectFromLongMap() {
Map<String, Long> map = new HashMap<String, Long>();
map.put("a", 1L);
map.put("b", 3L);
int size = registerAndRelease("result", map);
assertEquals(2, size);
assertEquals(1, v8.executeIntegerScript("result.a"));
assertEquals(3, v8.executeIntegerScript("result['b']"));
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testCreateV8ObjectFromIntegerMap() {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 1);
map.put("b", 3);
int size = registerAndRelease("result", map);
assertEquals(2, size);
assertEquals(1, v8.executeIntegerScript("result.a"));
assertEquals(3, v8.executeIntegerScript("result['b']"));
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testVoidMethodCalledFromIntScript() {
ICallback callback = mock(ICallback.class);
v8.registerJavaMethod(callback, "voidMethodNoParameters", "foo", new Class<?>[0]);
v8.executeIntegerScript("foo();1");
verify(callback).voidMethodNoParameters();
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = Error.class)
public void testCannotAccessDisposedIsolateInt() {
v8.close();
v8.executeIntegerScript("7");
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testIntScriptWithDouble() {
int result = v8.executeIntegerScript("1.9+2.9;");
assertEquals(4, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testGetTypedArrayValue() {
int result = v8.executeIntegerScript("var buf = new ArrayBuffer(4); var ints = new Int16Array(buf); ints[0] = 7; ints[0]");
assertEquals(7, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testIntMethodCalledFromScriptWithResult() {
ICallback callback = mock(ICallback.class);
doReturn(7).when(callback).intMethodNoParameters();
v8.registerJavaMethod(callback, "intMethodNoParameters", "foo", new Class<?>[0]);
int result = v8.executeIntegerScript("foo();");
assertEquals(7, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testCreateV8ArrayFromLongList() {
List<Long> list = new ArrayList<Long>();
list.add((long) 1);
int size = registerAndRelease("result", list);
assertEquals(1, size);
assertEquals(1, v8.executeIntegerScript("result[0]"));
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testResultUndefinedForWrongReturnTypeOfIntFunction() {
v8.executeIntegerScript("function foo() {return 'test';}; 42");
int result = v8.executeIntegerFunction("foo", null);
assertEquals(3, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test(expected = V8ResultUndefined.class)
public void testResultUndefinedForNoReturnInIntFunction() {
v8.executeIntegerScript("function foo() {}; 42");
int result = v8.executeIntegerFunction("foo", null);
assertEquals(3, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testWindowAliasForGlobalScope() {
setupWindowAlias();
v8.executeVoidScript("a = 1; window.b = 2;");
assertEquals(1, v8.executeIntegerScript("window.a;"));
assertEquals(2, v8.executeIntegerScript("b;"));
assertTrue(v8.executeBooleanScript("window.hasOwnProperty( \"Object\" )"));
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAddIntReplaceValue() {
v8.add("foo", 42);
v8.add("foo", 43);
int result = v8.executeIntegerScript("foo");
assertEquals(43, result);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAccessInt8TypedArrayInJavaScript() {
V8ArrayBuffer buffer = new V8ArrayBuffer(v8, 2);
V8TypedArray v8Int8Array = new V8TypedArray(v8, buffer, V8Value.BYTE, 0, 2);
v8.add("v8Int8Array", v8Int8Array);
buffer.put((byte) 4);
buffer.put((byte) 8);
assertEquals(4, v8.executeIntegerScript("v8Int8Array[0];"));
assertEquals(8, v8.executeIntegerScript("v8Int8Array[1];"));
buffer.close();
v8Int8Array.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAccessWindowObjectInStrictMode() {
setupWindowAlias();
String script = "'use strict';\n"
+ "window.foo = 7;\n"
+ "true\n";
boolean result = v8.executeBooleanScript(script);
assertTrue(result);
assertEquals(7, v8.executeIntegerScript("window.foo"));
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testGetTypedArrayValue_WithArrayBuffer() {
V8ArrayBuffer buffer = new V8ArrayBuffer(v8, 4);
v8.add("buf", buffer);
int result = v8.executeIntegerScript("var ints = new Int16Array(buf); ints[0] = 7; ints[0]");
assertEquals(7, result);
buffer.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAddObjectWithInt() {
V8Object v8Object = new V8Object(v8);
v8Object.add("integer", 75);
v8.add("foo", v8Object);
int result = v8.executeIntegerScript("foo.integer");
assertEquals(75, result);
v8Object.close();
}
内容来源于网络,如有侵权,请联系作者删除!