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

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

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

V8.add介绍

[英]Adds a ReferenceHandler to track when new V8Objects are created.
[中]添加ReferenceHandler以跟踪新V8对象的创建时间。

代码示例

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

/**
 * Adds a key value pair to the receiver where the value is a String.
 *
 * @param key The key to associate the value with.
 * @param value The value to add.
 *
 * @return The receiver.
 */
public V8Object add(final String key, final String value) {
  v8.checkThread();
  checkReleased();
  if (value == null) {
    v8.addNull(v8.getV8RuntimePtr(), objectHandle, key);
  } else if (value.equals(V8.getUndefined())) {
    v8.addUndefined(v8.getV8RuntimePtr(), objectHandle, key);
  } else {
    v8.add(v8.getV8RuntimePtr(), objectHandle, key, value);
  }
  return this;
}

代码示例来源:origin: jooby-project/jooby

}));
v8.add("j2v8", j2v8);

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

/**
 * Adds a key value pair to the receiver where the value is an integer.
 *
 * @param key The key to associate the value with.
 * @param value The value to add.
 *
 * @return The receiver.
 */
public V8Object add(final String key, final int value) {
  v8.checkThread();
  checkReleased();
  v8.add(v8.getV8RuntimePtr(), objectHandle, key, value);
  return this;
}

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

/**
 * Adds a key value pair to the receiver where the value is a boolean.
 *
 * @param key The key to associate the value with.
 * @param value The value to add.
 *
 * @return The receiver.
 */
public V8Object add(final String key, final boolean value) {
  v8.checkThread();
  checkReleased();
  v8.add(v8.getV8RuntimePtr(), objectHandle, key, value);
  return this;
}

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

/**
 * Adds a key value pair to the receiver where the value is a double.
 *
 * @param key The key to associate the value with.
 * @param value The value to add.
 *
 * @return The receiver.
 */
public V8Object add(final String key, final double value) {
  v8.checkThread();
  checkReleased();
  v8.add(v8.getV8RuntimePtr(), objectHandle, key, value);
  return this;
}

代码示例来源:origin: jooby-project/jooby

.collect(Collectors.joining("\n  ", "{\n  ", "\n}")));
v8.add("$options", toV8Object(v8, options));
v8.add("svg2png", new V8Function(v8, (receiver, params) -> {
 String svgPath = params.get(0).toString();
 String pngPath = params.get(1).toString();

代码示例来源:origin: jooby-project/jooby

private static void assets(Class<?> loader, final V8 v8) {
 V8Object assets = new V8Object(v8);
 v8.add("assets", assets);
 assets.registerJavaMethod((JavaCallback) (receiver, args) -> {
  try {
   return V8Engine.readFile(loader, args.get(0).toString());
  } catch (IOException ex) {
   // we can't fire exceptions from Java :S
   return V8.getUndefined();
  }
 }, "readFile");
 assets.registerJavaMethod(
   (JavaCallback) (receiver, args) -> V8Engine.exists(loader, args.get(0).toString()),
   "exists");
 assets.registerJavaMethod((JavaCallback) (receiver, args) -> {
  try {
   return load(loader, v8, args.get(0).toString());
  } catch (Exception ex) {
   // we can't fire exceptions from Java :S
   return V8.getUndefined();
  }
 }, "load");
}

代码示例来源:origin: jooby-project/jooby

private static void console(V8 v8, final String logname) {
 V8Object console = new V8Object(v8);
 Logger log = LoggerFactory.getLogger(logname);
 v8.add("console", console);
 console.registerJavaMethod(console(v8, log::info), "log");
 console.registerJavaMethod(console(v8, log::info), "info");
 console.registerJavaMethod(console(v8, log::error), "error");
 console.registerJavaMethod(console(v8, log::debug), "debug");
 console.registerJavaMethod(console(v8, log::warn), "warn");
}

代码示例来源: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 testAddStringReplaceValue() {
  v8.add("foo", "hello");
  v8.add("foo", "world");
  String result = v8.executeStringScript("foo");
  assertEquals("world", result);
}

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

@Test
public void testDoesNotContainsKey() {
  v8.add("foo", true);
  boolean result = v8.contains("bar");
  assertFalse(result);
}

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

/*** Null ***/
@Test
public void testStringIsNull() {
  v8.add("nullString", (V8Object) null);
  assertNull(v8.getString("nullString"));
}

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

private int registerAndRelease(final String name, final List<? extends Object> list) {
  V8Array array = V8ObjectUtils.toV8Array(v8, list);
  v8.add(name, array);
  int size = array.length();
  array.close();
  return size;
}

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

@Test
public void testGetInt8TypedArray() {
  V8ArrayBuffer buffer = new V8ArrayBuffer(v8, 4);
  v8.add("buf", buffer);
  V8Array array = (V8Array) v8.executeScript("new Int8Array(buf);");
  assertTrue(array instanceof V8TypedArray);
  array.close();
  buffer.close();
}

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

/*** Add Object ***/
@Test
public void testAddObject() {
  V8Object v8Object = new V8Object(v8);
  v8.add("foo", v8Object);
  V8Object result = v8.executeObjectScript("foo");
  assertNotNull(result);
  result.close();
  v8Object.close();
}

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

/*** Add Array ***/
@Test
public void testAddArray() {
  V8Array array = new V8Array(v8);
  v8.add("foo", array);
  V8Array result = v8.executeArrayScript("foo");
  assertNotNull(result);
  array.close();
  result.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 testInt32TypedArray_CustomLength() {
  V8ArrayBuffer buffer = new V8ArrayBuffer(v8, 8);
  V8TypedArray v8Int32Array = new V8TypedArray(v8, buffer, V8Value.INTEGER, 0, 1);
  v8.add("v8Int32Array", v8Int32Array);
  assertEquals(1, v8Int32Array.length());
  buffer.close();
  v8Int32Array.close();
}

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

@Test
public void testAddObjectToObject() {
  V8Object nested = new V8Object(v8);
  nested.add("foo", "bar");
  V8Object v8Object = new V8Object(v8);
  v8Object.add("nested", nested);
  v8.add("foo", v8Object);
  String result = v8.executeStringScript("foo.nested.foo");
  assertEquals("bar", result);
  v8Object.close();
  nested.close();
}

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

@Test
public void testGetTypedRangeArrayValue_FromBackingStore() {
  V8ArrayBuffer buffer = new V8ArrayBuffer(v8, 100);
  v8.add("buf", buffer);
  v8.executeVoidScript("var ints = new Int32Array(buf); for(var i = 0; i < 25; i++) {ints[i] = i;};");
  assertEquals(25, buffer.intLimit());
  for (int i = 0; i < buffer.intLimit(); i++) {
    assertEquals(i, buffer.getInt(i * 4));
  }
  buffer.close();
}

相关文章

微信公众号

最新文章

更多

V8类方法