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

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

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

V8.createV8Runtime介绍

[英]Creates a new V8Runtime and loads the required native libraries if they are not already loaded. The current thread is given the lock to this runtime.
[中]创建新的V8Runtime,并加载所需的本机库(如果尚未加载)。当前线程被授予此运行时的锁。

代码示例

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

/**
 * Creates a new V8Runtime and loads the required
 * native libraries if they are not already loaded.
 * The current thread is given the lock to this runtime.
 *
 * @return A new isolated V8 Runtime.
 */
public static V8 createV8Runtime() {
  return createV8Runtime(null, null);
}

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

/**
 * Creates a new V8Runtime and loads the required native libraries if they
 * are not already loaded. An alias is also set for the global scope. For example,
 * 'window' can be set as the global scope name.
 *
 * The current thread is given the lock to this runtime.
 *
 * @param globalAlias The name to associate with the global scope.
 *
 * @return A new isolated V8 Runtime.
 */
public static V8 createV8Runtime(final String globalAlias) {
  return createV8Runtime(globalAlias, null);
}

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

/**
 * Create a new ConcurrentV8. A ConcurrentV8 allows multiple
 * threads to work with the same V8 engine by releasing
 * the locks between calls.
 */
public ConcurrentV8() {
  v8 = V8.createV8Runtime();
  v8.getLocker().release();
}

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

private V8Engine v8(String id, String scope) {
 return cache.computeIfAbsent(Thread.currentThread().getName() + ":" + id, name -> {
  V8 v8 = V8.createV8Runtime(scope);
  MemoryManager mem = new MemoryManager(v8);
  console(v8, id);
  assets(getClass(), v8);
  b64(v8);
  return new V8Engine(v8, mem, id);
 });
}

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

@Override
public void run() {
  runtime = V8.createV8Runtime();
  try {
    target.run(runtime);
  } finally {
    synchronized (this) {
      if (runtime.getLocker().hasLock()) {
        runtime.close();
        runtime = null;
      }
    }
  }
}

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

V8 v8 = V8.createV8Runtime(GLOBAL);
final NodeJS node = new NodeJS(v8);
v8.registerJavaMethod(new JavaVoidCallback() {

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

/**
 * Creates a new V8Runtime and loads the required
 * native libraries if they are not already loaded.
 * The current thread is given the lock to this runtime.
 *
 * @return A new isolated V8 Runtime.
 */
public static V8 createV8Runtime() {
  return createV8Runtime(null, null);
}

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

@Override
public void run() {
  synchronized (this) {
    runtime = V8.createV8Runtime();
    runtime.registerJavaMethod(new ExecutorTermination(), "__j2v8__checkThreadTerminate");
    setup(runtime);

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

@Test
public void testV8MultipleReleaseHandlers() {
  V8 testV8 = V8.createV8Runtime();
  V8Runnable releaseHandler1 = mock(V8Runnable.class);
  V8Runnable releaseHandler2 = mock(V8Runnable.class);
  testV8.addReleaseHandler(releaseHandler1);
  testV8.addReleaseHandler(releaseHandler2);
  testV8.close();
  verify(releaseHandler1, times(1)).run(any(V8.class)); // cannot check against the real v8 because it's released.
  verify(releaseHandler2, times(1)).run(any(V8.class)); // cannot check against the real v8 because it's released.
}

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

@Test
public void testV8UnknownReleaseHandleRemoved() {
  V8 testV8 = V8.createV8Runtime();
  V8Runnable releaseHandler1 = mock(V8Runnable.class);
  V8Runnable releaseHandler2 = mock(V8Runnable.class);
  testV8.addReleaseHandler(releaseHandler1);
  testV8.removeReleaseHandler(releaseHandler2);
  testV8.close();
  verify(releaseHandler1, times(1)).run(any(V8.class)); // cannot check against the real v8 because it's released.
}

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

@SuppressWarnings("resource")
@Test(expected = IllegalStateException.class)
public void testISEThrownOnShutdown() {
  V8 v8_ = V8.createV8Runtime();
  new V8Object(v8_);
  v8_.release(true);
}

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

@Before
public void setup() {
  V8.setFlags("--expose-debug-as=" + DebugHandler.DEBUG_OBJECT_NAME);
  v8 = V8.createV8Runtime();
  debugHandler = new DebugHandler(v8);
  debugHandler.setScriptBreakpoint("script", 14);
  breakHandler = mock(BreakHandler.class);
  debugHandler.addBreakHandler(breakHandler);
}

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

@Before
public void setup() {
  V8.setFlags("--expose-debug-as=" + DebugHandler.DEBUG_OBJECT_NAME);
  v8 = V8.createV8Runtime();
  debugHandler = new DebugHandler(v8);
  debugHandler.setScriptBreakpoint("script", 2);
  breakHandler = mock(BreakHandler.class);
  debugHandler.addBreakHandler(breakHandler);
}

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

@Test
public void testReleaseAfterV8Released() {
  V8Locker v8Locker = new V8Locker(v8);
  v8.close();
  v8Locker.release();
  v8 = V8.createV8Runtime(); // Create a new runtime so the teardown doesn't fail
}

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

@Test
public void testAlternateGlobalAlias() {
  v8.close();
  v8 = V8.createV8Runtime("document");
  v8.executeVoidScript("var global = Function('return this')();");
  assertTrue(v8.executeBooleanScript("global === document"));
}

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

@Test
public void testToStringWorksOnReleasedV8Runtime_V8Function() {
  @SuppressWarnings("resource")
  V8Object v8Object = new V8Function(v8);
  v8.release(false);
  assertEquals("[Function released]", v8Object.toString());
  v8 = V8.createV8Runtime();
}

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

@Test
public void testToStringWorksOnReleasedV8Runtime_V8Array() {
  @SuppressWarnings("resource")
  V8Object v8Object = new V8Array(v8);
  v8.release(false);
  assertEquals("[Array released]", v8Object.toString());
  v8 = V8.createV8Runtime();
}

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

@Test
public void testReleaseAttachedMap() {
  V8 runtime = V8.createV8Runtime();
  V8Map<String> v8Map = new V8Map<String>();
  V8Object v8Object = new V8Object(runtime);
  v8Map.put(v8Object, "foo");
  v8Object.close();
  runtime.registerResource(v8Map);
  runtime.release(true);
}

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

@Test
public void testNestedExecutorExecution() throws InterruptedException {
  V8 runtime = V8.createV8Runtime();
  runtime.terminateExecution();
  V8Executor executor = new V8Executor("");
  executor.start();
  V8Object key = new V8Object(runtime);
  runtime.registerV8Executor(key, executor);
  key.close();
  runtime.close();
  executor.join();
}

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

@Test
public void testGetNestedExecutor() {
  V8 runtime = V8.createV8Runtime();
  runtime.terminateExecution();
  V8Executor executor = new V8Executor("");
  V8Object key = new V8Object(runtime);
  runtime.registerV8Executor(key, executor);
  assertEquals(executor, runtime.getExecutor(key));
  key.close();
  runtime.close();
}

相关文章

V8类方法