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

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

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

V8.executeVoidFunction介绍

暂无

代码示例

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

/**
 * Invokes a JavaScript function which does not return a result.
 *
 * @param name The name of the JS Function to call.
 *
 * @param parameters The parameters to pass to the function. Parameters must be released.
 */
public void executeVoidFunction(final String name, final V8Array parameters) {
  v8.checkThread();
  checkReleased();
  v8.checkRuntime(parameters);
  long parametersHandle = parameters == null ? 0 : parameters.getHandle();
  v8.executeVoidFunction(v8.getV8RuntimePtr(), objectHandle, name, parametersHandle);
}

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

runtime.executeVoidFunction(messageHandler, parameters);
} finally {
  strings.close();

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

@Test
public void testRegisterJavaVoidCallbackExecuteFunction() {
  JavaVoidCallback callback = mock(JavaVoidCallback.class);
  v8.registerJavaMethod(callback, "foo");
  v8.executeVoidFunction("foo", null);
  verify(callback).invoke(any(V8Object.class), any(V8Array.class));
}

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

@Test
public void testRegisterJavaCallbackExecuteFunction() {
  JavaCallback callback = mock(JavaCallback.class);
  v8.registerJavaMethod(callback, "foo");
  v8.executeVoidFunction("foo", null);
  verify(callback).invoke(any(V8Object.class), any(V8Array.class));
}

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

@Test
public void testInvokeCallbackOnGlobalFunctionUsesGlobalScopeAsReciver() {
  JavaVoidCallback callback = mock(JavaVoidCallback.class);
  v8.registerJavaMethod(callback, "foo");
  doAnswer(constructAnswer(v8, null, null)).when(callback).invoke(any(V8Object.class), any(V8Array.class));
  v8.executeVoidFunction("foo", null);
}

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

@Test(expected = V8ScriptExecutionException.class)
public void testV8ScriptExceptionVoidCall() {
  v8.executeVoidScript(errorFunction);
  v8.executeVoidFunction("myFunction", null);
}

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

/**
 * Invokes a JavaScript function which does not return a result.
 *
 * @param name The name of the JS Function to call.
 *
 * @param parameters The parameters to pass to the function. Parameters must be released.
 */
public void executeVoidFunction(final String name, final V8Array parameters) {
  v8.checkThread();
  checkReleased();
  v8.checkRuntime(parameters);
  long parametersHandle = parameters == null ? 0 : parameters.getHandle();
  v8.executeVoidFunction(v8.getV8RuntimePtr(), objectHandle, name, parametersHandle);
}

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

@Test
public void testUnaccessibleMethod() {
  final boolean[] called = new boolean[] { false };
  Runnable r = new Runnable() {
    @Override
    public void run() {
      called[0] = true;
    }
  };
  v8.registerJavaMethod(r, "run", "run", new Class<?>[0]);
  v8.executeVoidFunction("run", null);
  assertTrue(called[0]);
}

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

/*** Void Function ***/
@Test
public void testSimpleVoidFunction() {
  v8.executeVoidScript("function foo() {x=1}");
  v8.executeVoidFunction("foo", null);
  assertEquals(1, v8.getInteger("x"));
}

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

@Test
public void testVoidFunctionCallNullParameters() {
  v8.executeVoidScript("function foo() {x=7;}");
  v8.executeVoidFunction("foo", null);
  assertEquals(7, v8.getInteger("x"));
}

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

runtime.executeVoidFunction(messageHandler, parameters);
} finally {
  strings.close();

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

@Test
public void testVoidFunctionCallNoParameters() {
  v8.executeVoidScript("function foo() {x=7;}");
  V8Array parameters = new V8Array(v8);
  v8.executeVoidFunction("foo", parameters);
  assertEquals(7, v8.getInteger("x"));
  parameters.close();
}

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

@Test
public void testInvokeCallbackWithParameters() {
  JavaCallback callback = mock(JavaCallback.class);
  v8.registerJavaMethod(callback, "foo");
  V8Object object = new V8Object(v8);
  object.add("foo", "bar");
  V8Array array = new V8Array(v8);
  array.push(1).push(2).push(3);
  V8Array parameters = new V8Array(v8);
  parameters.push(7);
  parameters.push("test");
  parameters.push(3.14159);
  parameters.push(true);
  parameters.push(object);
  parameters.push(array);
  doAnswer(constructAnswer(null, parameters, null)).when(callback).invoke(any(V8Object.class), any(V8Array.class));
  v8.executeVoidFunction("foo", parameters);
  parameters.close();
  object.close();
  array.close();
}

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

@Test
public void testInvokeVoidCallbackWithParameters() {
  JavaVoidCallback callback = mock(JavaVoidCallback.class);
  v8.registerJavaMethod(callback, "foo");
  V8Object object = new V8Object(v8);
  object.add("foo", "bar");
  V8Array array = new V8Array(v8);
  array.push(1).push(2).push(3);
  V8Array parameters = new V8Array(v8);
  parameters.push(7);
  parameters.push("test");
  parameters.push(3.14159);
  parameters.push(true);
  parameters.push(object);
  parameters.push(array);
  doAnswer(constructAnswer(null, parameters, null)).when(callback).invoke(any(V8Object.class), any(V8Array.class));
  v8.executeVoidFunction("foo", parameters);
  parameters.close();
  object.close();
  array.close();
}

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

@Test(expected = Error.class)
public void testSharingObjectsAsFunctionCallParameters_VoidFunction() {
  V8 engine = null;
  V8 engine2 = null;
  try {
    engine = V8.createV8Runtime();
    engine2 = V8.createV8Runtime();
    engine.executeScript("b = function(param1, param2){ param1 + param2;}");
    engine2.executeScript("a = [3, 4];");
    V8Array a = (V8Array) engine2.get("a");
    engine.executeVoidFunction("b", a);
  } finally {
    engine.release(false);
    engine2.release(false);
  }
}

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

@Test
public void testCreateV8Function_CalledFromJS() {
  v8.executeScript("function doSomething(callback) { callback(); }");
  V8Function function = new V8Function(v8, new JavaCallback() {
    @Override
    public Object invoke(final V8Object receiver, final V8Array parameters) {
      result = "passed";
      return null;
    }
  });
  V8Array parameters = new V8Array(v8);
  parameters.push(function);
  v8.executeVoidFunction("doSomething", parameters);
  function.close();
  parameters.close();
  assertEquals("passed", result);
}

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

@Test
public void testCreateV8Function_CalledFromJS_AfterFunctionReleased() {
  v8.executeScript("function doSomething(callback) { callback(); }");
  V8Function function = new V8Function(v8, new JavaCallback() {
    @Override
    public Object invoke(final V8Object receiver, final V8Array parameters) {
      result = "passed";
      return null;
    }
  });
  V8Array parameters = new V8Array(v8);
  parameters.push(function);
  function.close();
  v8.executeVoidFunction("doSomething", parameters);
  parameters.close();
  assertEquals("passed", result);
}

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

@Test
public void testVoidFunctionCall() {
  v8.executeVoidScript("function setPerson(first, last, age) {person = {'first':first, 'last':last, 'age':age};}");
  V8Array parameters = new V8Array(v8);
  parameters.push("John");
  parameters.push("Smith");
  parameters.push(7);
  v8.executeVoidFunction("setPerson", parameters);
  V8Object result = v8.getObject("person");
  assertEquals("John", result.getString("first"));
  assertEquals("Smith", result.getString("last"));
  assertEquals(7, result.getInteger("age"));
  parameters.close();
  result.close();
}

代码示例来源:origin: com.eclipsesource.j2v8/j2v8_win32_x86_64

/**
 * Invokes a JavaScript function which does not return a result.
 *
 * @param name The name of the JS Function to call.
 *
 * @param parameters The parameters to pass to the function. Parameters must be released.
 */
public void executeVoidFunction(final String name, final V8Array parameters) {
  v8.checkThread();
  checkReleased();
  long parametersHandle = parameters == null ? 0 : parameters.getHandle();
  v8.executeVoidFunction(v8.getV8RuntimePtr(), objectHandle, name, parametersHandle);
}

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

@Test
public void testCreateMatrix() {
  V8Array a1 = new V8Array(v8);
  V8Array a2 = new V8Array(v8);
  V8Array a3 = new V8Array(v8);
  a1.push(1);
  a1.push(2);
  a1.push(3);
  a2.push(4);
  a2.push(5);
  a2.push(6);
  a3.push(7);
  a3.push(8);
  a3.push(9);
  V8Array array = new V8Array(v8);
  array.push(a1);
  array.push(a2);
  array.push(a3);
  V8Array parameters = new V8Array(v8);
  parameters.push(array);
  v8.executeVoidScript("var total = 0; function add(matrix) { for(var i = 0; i < 3; i++) { for (var j = 0; j < 3; j++) { total = total + matrix[i][j]; }}};");
  v8.executeVoidFunction("add", parameters);
  int result = v8.getInteger("total");
  assertEquals(45, result);
  a1.close();
  a2.close();
  a3.close();
  array.close();
  parameters.close();
}

相关文章

V8类方法