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

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

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

V8.executeArrayScript介绍

[英]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.
[中]在此运行时执行JS脚本,并将结果作为V8Array返回。如果结果不是V8Array,则会抛出V8ResultUndefinedException。

代码示例

代码示例来源: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.
 *
 * @return The result of the script as a V8Array, or V8ResultUndefinedException if
 * the result is not a V8Array.
 */
public V8Array executeArrayScript(final String script) {
  return executeArrayScript(script, null, 0);
}

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

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

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

@Test(expected = V8ResultUndefined.class)
public void testArrayGetDoubleWrongType() {
  V8Array array = v8.executeArrayScript("['string'];");
  try {
    array.getDouble(0);
  } finally {
    array.close();
  }
}

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

@Test(expected = V8ResultUndefined.class)
public void testArrayGetStringWrongType() {
  V8Array array = v8.executeArrayScript("[42];");
  try {
    array.getString(0);
  } finally {
    array.close();
  }
}

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

@Test(expected = V8ResultUndefined.class)
public void testGetBooleansWithoutBooleans() {
  V8Array a = v8.executeArrayScript("[true, 'a', false, false, true];");
  try {
    a.getBooleans(0, 5);
  } finally {
    a.close();
  }
}

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

@Test
public void testGetTypeRangeOfInts() {
  V8Array a = v8.executeArrayScript("[1,2,3,4,5];");
  int result = a.getType(0, 5);
  assertEquals(INTEGER, result);
  a.close();
}

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

@Test
public void testGetTypeRangeOfArrays() {
  V8Array a = v8.executeArrayScript("[1, [1], [false], ['string'], 2];");
  int result = a.getType(1, 3);
  assertEquals(V8_ARRAY, result);
  a.close();
}

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

@Test
public void testGetArrayTypeDoubleWithInts2() {
  V8Array a = v8.executeArrayScript("[1,2,3.3,4.4]");
  int type = a.getType();
  assertEquals(V8Value.DOUBLE, type);
  a.close();
}

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

@Test
public void testGetArrayTypeObjectWithArray2() {
  V8Array a = v8.executeArrayScript("[[], {}]");
  int type = a.getType();
  assertEquals(V8Value.V8_OBJECT, type);
  a.close();
}

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

@Test
public void testGetBooleanBiggerArray() {
  V8Array a = v8.executeArrayScript("[false, false, false, true]");
  boolean[] result = new boolean[40];
  int size = a.getBooleans(0, 4, result);
  assertEquals(4, size);
  a.close();
}

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

@Test
public void testGetStringSameSizeArray() {
  V8Array a = v8.executeArrayScript("['a', 'b', 'c', 'd']");
  String[] result = new String[4];
  int size = a.getStrings(0, 4, result);
  assertEquals(4, size);
  a.close();
}

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

@Test
public void testGetIsInteger() {
  V8Array array = v8.executeArrayScript("foo = [7]");
  Object result = array.get(0);
  assertTrue(result instanceof Integer);
  assertEquals(7, result);
  array.close();
}

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

@Test
public void testGetIsDouble() {
  V8Array array = v8.executeArrayScript("foo = [7.7]");
  Object result = array.get(0);
  assertTrue(result instanceof Double);
  assertEquals(7.7, result);
  array.close();
}

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

@Test
public void testGetIsObject() {
  V8Array array = v8.executeArrayScript("foo = [{}]");
  Object result = array.get(0);
  assertTrue(result instanceof V8Object);
  array.close();
  ((Releasable) result).release();
}

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

@Test
public void testGetSubArrayOfBooleans() {
  V8Array a = v8.executeArrayScript("[true, false, true, true, false];");
  boolean[] result = a.getBooleans(4, 1);
  assertEquals(1, result.length);
  assertFalse(result[0]);
  a.close();
}

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

@Test
public void testLargeArrayGetInt() {
  V8Array array = v8.executeArrayScript("foo = []; for ( var i = 0; i < 10000; i++) {foo[i] = i;}; foo");
  assertEquals(10000, array.length());
  for (int i = 0; i < 10000; i++) {
    assertEquals(i, array.getInteger(i));
  }
  array.close();
}

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

@Test
public void testGetDoublesPopulatesArray() {
  V8Array a = v8.executeArrayScript("[1.1,2.2,3.3,4]");
  double[] result = new double[4];
  a.getDoubles(0, 4, result);
  assertEquals(1.1, result[0], 0.000001);
  assertEquals(2.2, result[1], 0.000001);
  assertEquals(3.3, result[2], 0.000001);
  assertEquals(4, result[3], 0.000001);
  a.close();
}

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

/*** Get Int ***/
@Test
public void testArrayGetInt() {
  V8Array array = v8.executeArrayScript("[1,2,8];");
  assertEquals(1, array.getInteger(0));
  assertEquals(2, array.getInteger(1));
  assertEquals(8, array.getInteger(2));
  array.close();
}

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

@Test
public void testGetArrayOfInts() {
  V8Array a = v8.executeArrayScript("[1,2,3,4,5];");
  int[] result = a.getIntegers(0, 5);
  assertEquals(5, result.length);
  assertEquals(1, result[0]);
  assertEquals(2, result[1]);
  assertEquals(3, result[2]);
  assertEquals(4, result[3]);
  assertEquals(5, result[4]);
  a.close();
}

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

/**** Mixed Array ****/
@Test
public void testMixedArray() {
  V8Array array = v8.executeArrayScript("['a', 3, 3.1, true];");
  assertEquals(4, array.length());
  assertEquals("a", array.getString(0));
  assertEquals(3, array.getInteger(1));
  assertEquals(3.1, array.getDouble(2), 0.00001);
  assertTrue(array.getBoolean(3));
  array.close();
}

相关文章

V8类方法