/** * Releases the NodeJS runtime. */ public void release() { v8.checkThread(); if (!require.isReleased()) { require.close(); } if (!v8.isReleased()) { v8.close(); } }
@Override public void run() { runtime = V8.createV8Runtime(); try { target.run(runtime); } finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null; } } } }
synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null;
@After public void tearDown() { try { v8.close(); if (V8.getActiveRuntimes() != 0) { throw new IllegalStateException("V8Runtimes not properly released"); } } catch (IllegalStateException e) { System.out.println(e.getMessage()); } }
@After public void tearDown() { if (v8 != null) { v8.close(); } if (V8.getActiveRuntimes() != 0) { throw new IllegalStateException("V8Runtimes not properly released"); } }
@After public void tearDown() { if (v8 != null) { v8.close(); } if (V8.getActiveRuntimes() != 0) { throw new IllegalStateException("V8Runtimes not properly released"); } }
@After public void tearDown() { try { debugHandler.close(); v8.close(); if (V8.getActiveRuntimes() != 0) { throw new IllegalStateException("V8Runtimes not properly released"); } } catch (IllegalStateException e) { System.out.println(e.getMessage()); } }
@After public void tearDown() { handler.close(); try { v8.close(); if (V8.getActiveRuntimes() != 0) { throw new IllegalStateException("V8Runtimes not properly released"); } } catch (IllegalStateException e) { System.out.println(e.getMessage()); } }
@After public void tearDown() { try { debugHandler.close(); v8.close(); if (V8.getActiveRuntimes() != 0) { throw new IllegalStateException("V8Runtimes not properly released"); } } catch (IllegalStateException e) { System.out.println(e.getMessage()); } }
@After public void tearDown() { try { debugHandler.close(); v8.close(); if (V8.getActiveRuntimes() != 0) { throw new IllegalStateException("V8Runtimes not properly released"); } } catch (IllegalStateException e) { System.out.println(e.getMessage()); } }
@Test(expected = Error.class) public void testCannotAccessDisposedIsolateString() { v8.close(); v8.executeStringScript("'foo'"); }
@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. }
@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. }
@Test public void testV8ReleaseHandleRemoved() { V8 testV8 = V8.createV8Runtime(); V8Runnable releaseHandler = mock(V8Runnable.class); testV8.addReleaseHandler(releaseHandler); testV8.removeReleaseHandler(releaseHandler); testV8.close(); verify(releaseHandler, never()).run(testV8); }
@SuppressWarnings("resource") @Test(expected = IllegalStateException.class) public void testDoNotReleaseArrayReference() { V8 _v8 = V8.createV8Runtime(); new V8Array(_v8); _v8.close(); }
@SuppressWarnings("resource") @Test public void testReleaseRuntimeDoesNotReleaseObject() { try { new V8Object(v8); v8.close(); } catch (IllegalStateException e) { v8 = V8.createV8Runtime(); return; } fail("Illegal State Exception not thrown."); }
@Test public void testAlternateGlobalAlias() { v8.close(); v8 = V8.createV8Runtime("document"); v8.executeVoidScript("var global = Function('return this')();"); assertTrue(v8.executeBooleanScript("global === document")); }
@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(); }
@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(); }
@Test public void testTerminateNestedExecutors() { V8 runtime = V8.createV8Runtime(); runtime.terminateExecution(); V8Executor executor = new V8Executor("while (true){}"); V8Object key = new V8Object(runtime); runtime.registerV8Executor(key, executor); runtime.shutdownExecutors(false); assertTrue(runtime.getExecutor(key).isShuttingDown()); key.close(); runtime.close(); }