com.eclipsesource.v8.V8.executeBooleanScript()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(84)

本文整理了Java中com.eclipsesource.v8.V8.executeBooleanScript()方法的一些代码示例,展示了V8.executeBooleanScript()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.executeBooleanScript()方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:executeBooleanScript

V8.executeBooleanScript介绍

[英]Executes a JS Script on this runtime and returns the result as a boolean. If the result is not a boolean, then a V8ResultUndefinedException is thrown.
[中]在此运行时上执行JS脚本,并将结果作为布尔值返回。如果结果不是布尔值,则抛出V8ResultUndefinedException。

代码示例

代码示例来源:origin: eclipsesource/J2V8

/**
 * Executes a JS Script on this runtime and returns the result as a boolean.
 * If the result is not a boolean, then a V8ResultUndefinedException is thrown.
 *
 * @param script The script to execute.
 *
 * @return The result of the script as a boolean, or V8ResultUndefinedException if
 * the result is not a boolean.
 */
public boolean executeBooleanScript(final String script) {
  return executeBooleanScript(script, null, 0);
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Executes a JS Script on this runtime and returns the result as a boolean.
 * If the result is not a boolean, 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 boolean, or V8ResultUndefinedException if
 * the result is not a boolean.
 */
public boolean executeBooleanScript(final String script, final String scriptName, final int lineNumber) {
  checkThread();
  checkScript(script);
  return executeBooleanScript(v8RuntimePtr, script, scriptName, lineNumber);
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Executes a JS Script on this runtime and returns the result as a boolean.
 * If the result is not a boolean, then a V8ResultUndefinedException is thrown.
 *
 * @param script The script to execute.
 *
 * @return The result of the script as a boolean, or V8ResultUndefinedException if
 * the result is not a boolean.
 */
public boolean executeBooleanScript(final String script) {
  return executeBooleanScript(script, null, 0);
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testCreatev8ObjectWithNulls() {
  Map<String, Boolean> map = new HashMap<String, Boolean>();
  map.put("a", true);
  map.put("b", null);
  int size = registerAndRelease("result", map);
  assertTrue(v8.executeBooleanScript("result.a"));
  assertTrue(v8.executeBooleanScript("typeof result.b === 'undefined'"));
  assertEquals(2, size);
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testBooleanScriptWithName() {
  boolean result = v8.executeBooleanScript("true", "name", 4);
  assertTrue(result);
}

代码示例来源:origin: eclipsesource/J2V8

@Test(expected = Error.class)
public void testCannotAccessDisposedIsolateBoolean() {
  v8.close();
  v8.executeBooleanScript("true");
}

代码示例来源:origin: eclipsesource/J2V8

/*** Boolean Script ***/
@Test
public void testSimpleBooleanScript() {
  boolean result = v8.executeBooleanScript("true");
  assertTrue(result);
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testStringMethodCalledFromScriptWithNull() {
  ICallback callback = mock(ICallback.class);
  doReturn(null).when(callback).stringMethodNoParameters();
  v8.registerJavaMethod(callback, "stringMethodNoParameters", "foo", new Class<?>[0]);
  boolean result = v8.executeBooleanScript("foo() === null");
  assertTrue(result);
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testV8ObjectMethodReturnsNull() {
  ICallback callback = mock(ICallback.class);
  doReturn(null).when(callback).v8ObjectMethodNoParameters();
  v8.registerJavaMethod(callback, "v8ObjectMethodNoParameters", "foo", new Class<?>[0]);
  boolean result = v8.executeBooleanScript("foo() === null");
  assertTrue(result);
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testV8ObjectMethodReturnsUndefined() {
  ICallback callback = mock(ICallback.class);
  doReturn(V8.getUndefined()).when(callback).v8ObjectMethodNoParameters();
  v8.registerJavaMethod(callback, "v8ObjectMethodNoParameters", "foo", new Class<?>[0]);
  boolean result = v8.executeBooleanScript("typeof foo() === 'undefined'");
  assertTrue(result);
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testWindowWindowWindowWindow() {
  setupWindowAlias();
  assertTrue(v8.executeBooleanScript("window.window.window === window"));
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testAccessGlobalViaWindow() {
  setupWindowAlias();
  String script = "var global = {data: 0};\n" + "global === window.global";
  assertTrue(v8.executeBooleanScript(script));
}

代码示例来源:origin: eclipsesource/J2V8

/*** Add Boolean ***/
@Test
public void testAddBoolean() {
  v8.add("foo", true);
  boolean result = v8.executeBooleanScript("foo");
  assertTrue(result);
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testwindowIsInstanceOfWindow() {
  setupWindowAlias();
  assertTrue(v8.executeBooleanScript("window instanceof Window"));
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testWindowIsGlobal2() {
  setupWindowAlias();
  v8.executeVoidScript("var global = Function('return this')();");
  assertTrue(v8.executeBooleanScript("window === global"));
}

代码示例来源: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 testAddObjectWithBoolean() {
  V8Object v8Object = new V8Object(v8);
  v8Object.add("boolean", false);
  v8.add("foo", v8Object);
  boolean result = v8.executeBooleanScript("foo.boolean");
  assertFalse(result);
  v8Object.close();
}

代码示例来源:origin: eclipsesource/J2V8

@SuppressWarnings("unchecked")
@Test
public void testCloneV8Array_GetValue() {
  V8Array list = v8.executeArrayScript("var l = [{first:'ian', last:'bull'}, {first:'sadie', last:'bull'}]; l;");
  V8Array v8Object = V8ObjectUtils.toV8Array(v8, (List<? extends Object>) V8ObjectUtils.getValue(list));
  v8.add("l2", v8Object);
  v8.executeBooleanScript("JSON.stringify(l) === JSON.stringify(l2);");
  list.close();
  v8Object.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testCloneV8Array() {
  V8Array list = v8.executeArrayScript("var l = [{first:'ian', last:'bull'}, {first:'sadie', last:'bull'}]; l;");
  V8Array v8Object = V8ObjectUtils.toV8Array(v8, V8ObjectUtils.toList(list));
  v8.add("l2", v8Object);
  v8.executeBooleanScript("JSON.stringify(l) === JSON.stringify(l2);");
  list.close();
  v8Object.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testCloneV8Object() {
  V8Object list = v8.executeObjectScript("var l = [{first:'ian', last:'bull'}, {first:'sadie', last:'bull'}]; l;");
  V8Object v8Object = V8ObjectUtils.toV8Object(v8, V8ObjectUtils.toMap(list));
  v8.add("l2", v8Object);
  v8.executeBooleanScript("JSON.stringify(l) === JSON.stringify(l2);");
  list.close();
  v8Object.close();
}

相关文章

微信公众号

最新文章

更多

V8类方法