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

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

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

V8.executeDoubleScript介绍

[英]Executes a JS Script on this runtime and returns the result as a double. If the result is not a double, then a V8ResultUndefinedException is thrown.
[中]在此运行时上执行JS脚本,并以双精度返回结果。如果结果不是double,则抛出V8ResultUndefinedException。

代码示例

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

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

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

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

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

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

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

@Test(expected = V8ResultUndefined.class)
public void testResultUndefinedExceptionDoubleScript() {
  v8.executeDoubleScript("");
}

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

@Test(expected = V8ScriptCompilationException.class)
public void testV8ScriptCompilationExceptionForDoubleScript() {
  v8.executeDoubleScript(script);
}

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

@Test
public void testCreateV8ObjectFromFloatMap() {
  Map<String, Float> map = new HashMap<String, Float>();
  map.put("a", 1.1f);
  map.put("b", 3.14159f);
  map.put("c", 4.999f);
  int size = registerAndRelease("result", map);
  assertEquals(3, size);
  assertEquals(1.1, v8.executeDoubleScript("result.a"), 0.000001);
  assertEquals(3.14159, v8.executeDoubleScript("result['b']"), 0.000001);
  assertEquals(4.999, v8.executeDoubleScript("result['c']"), 0.000001);
}

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

@Test
public void testCreateV8ArrayFromDoubleList() {
  List<Double> list = new ArrayList<Double>();
  list.add(3.14159);
  list.add(4.1);
  list.add(5.3);
  int size = registerAndRelease("result", list);
  assertEquals(3, size);
  assertEquals(3.14159, v8.executeDoubleScript("result[0]"), 0.000001);
  assertEquals(4.1, v8.executeDoubleScript("result[1]"), 0.000001);
  assertEquals(5.3, v8.executeDoubleScript("result[2]"), 0.000001);
}

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

@Test
public void testCreateV8ObjectFromDoubleMap() {
  Map<String, Double> map = new HashMap<String, Double>();
  map.put("a", 1.1);
  map.put("b", 3.14159);
  map.put("c", 4.999);
  int size = registerAndRelease("result", map);
  assertEquals(3, size);
  assertEquals(1.1, v8.executeDoubleScript("result.a"), 0.000001);
  assertEquals(3.14159, v8.executeDoubleScript("result['b']"), 0.000001);
  assertEquals(4.999, v8.executeDoubleScript("result['c']"), 0.000001);
}

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

@Test
public void testCreateV8ObjectFromMaxLongMap() {
  Map<String, Long> map = new HashMap<String, Long>();
  map.put("a", Long.MAX_VALUE);
  map.put("b", Long.MIN_VALUE);
  int size = registerAndRelease("result", map);
  assertEquals(2, size);
  assertEquals(Long.MAX_VALUE, (long) v8.executeDoubleScript("result.a"));
  assertEquals(Long.MIN_VALUE, (long) v8.executeDoubleScript("result.b"));
}

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

/*** Double Script ***/
@Test
public void testSimpleDoubleScript() {
  double result = v8.executeDoubleScript("3.14159;");
  assertEquals(3.14159, result, 0.00001);
}

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

@Test
public void testDoubleScriptWithInt() {
  double result = v8.executeDoubleScript("1");
  assertEquals(1.0, result, 0.00001);
}

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

@Test
public void testDoubleScriptHandlesInts() {
  int result = (int) v8.executeDoubleScript("1");
  assertEquals(1, result);
}

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

@Test
public void testDoubleScriptWithName() {
  double result = v8.executeDoubleScript("3.14159;", "name", 3);
  assertEquals(3.14159, result, 0.00001);
}

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

@Test
public void testDoubleMethodCalledFromScriptWithResult() {
  ICallback callback = mock(ICallback.class);
  doReturn(3.14159).when(callback).doubleMethodNoParameters();
  v8.registerJavaMethod(callback, "doubleMethodNoParameters", "foo", new Class<?>[0]);
  double result = v8.executeDoubleScript("foo();");
  assertEquals(3.14159, result, 0.0000001);
}

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

@Test
public void testCreateV8ArrayFromFloatList() {
  List<Float> list = new ArrayList<Float>();
  list.add(1.1f);
  int size = registerAndRelease("result", list);
  assertEquals(1, size);
  assertEquals(1.1, v8.executeDoubleScript("result[0]"), 0.0000001);
}

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

@Test
public void testCreateV8ObjectFromLongTimestampMap() {
  Map<String, Long> map = new HashMap<String, Long>();
  map.put("a", 1477486236000L);
  int size = registerAndRelease("result", map);
  assertEquals(1, size);
  assertEquals(1477486236000L, (long) v8.executeDoubleScript("result.a"));
}

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

@Test
public void testCreateV8ArrayFromMaxValueLong() {
  List<Long> list = new ArrayList<Long>();
  list.add(Long.MAX_VALUE);
  int size = registerAndRelease("result", list);
  assertEquals(1, size);
  assertEquals(Long.MAX_VALUE, v8.executeDoubleScript("result[0]"), 0.0000001);
}

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

/*** Add Double ***/
@Test
public void testAddDouble() {
  v8.add("foo", 3.14159);
  double result = v8.executeDoubleScript("foo");
  assertEquals(3.14159, result, 0.000001);
}

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

@Test
public void testAddDoubleReplaceValue() {
  v8.add("foo", 42.1);
  v8.add("foo", 43.1);
  double result = v8.executeDoubleScript("foo");
  assertEquals(43.1, result, 0.000001);
}

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

@Test
public void testAddObjectWithDouble() {
  V8Object v8Object = new V8Object(v8);
  v8Object.add("double", 75.5);
  v8.add("foo", v8Object);
  double result = v8.executeDoubleScript("foo.double");
  assertEquals(75.5, result, 0.000001);
  v8Object.close();
}

相关文章

V8类方法