void checkThread() { locker.checkThread(); if (isReleased()) { throw new Error("Runtime disposed error"); } }
@Override public String toString() { if (released || v8.isReleased()) { return "[Function released]"; } return super.toString(); }
@Override public String toString() { if (released || v8.isReleased()) { return "[Array released]"; } return super.toString(); }
void checkRuntime(final V8Value value) { if ((value == null) || value.isUndefined()) { return; } V8 runtime = value.getRuntime(); if ((runtime == null) || runtime.isReleased() || (runtime != this)) { throw new Error("Invalid target runtime"); } }
/** * Releases the underlying {@link V8} instance. * * This method should be invoked once you're done using this object, * otherwise a large amount of garbage could be left on the JVM due to * native resources. * * <b>Note:</b> If this method has already been called once, it * will do nothing. */ public void release() { if ((v8 != null) && !v8.isReleased()) { // Release the V8 instance from the V8 thread context. run(new V8Runnable() { @Override public void run(final V8 v8) { if ((v8 != null) && !v8.isReleased()) { v8.close(); } } }); } } }
/** * Release the lock if it's currently held by the calling thread. * If the current thread does not hold the lock, and error will be * thrown. If no thread holds the lock then nothing will happen. */ public synchronized void release() { if ((released && (thread == null)) || runtime.isReleased()) { return; } checkThread(); runtime.releaseLock(runtime.getV8RuntimePtr()); thread = null; released = true; }
/** * Releases the NodeJS runtime. */ public void release() { v8.checkThread(); if (!require.isReleased()) { require.close(); } if (!v8.isReleased()) { v8.close(); } }
@Override public String toString() { if (isReleased() || v8.isReleased()) { return "[Object released]"; } v8.checkThread(); return v8.toString(v8.getV8RuntimePtr(), getHandle()); }
if (isReleased()) { return;
@Override public String toString() { if (released || v8.isReleased()) { return "[Array released]"; } return super.toString(); }
@Override public String toString() { if (released || v8.isReleased()) { return "[Function released]"; } return super.toString(); }
void checkThread() { locker.checkThread(); if (isReleased()) { throw new Error("Runtime disposed error"); } }
void checkRuntime(final V8Value value) { if ((value == null) || value.isUndefined()) { return; } V8 runtime = value.getRuntime(); if ((runtime == null) || runtime.isReleased() || (runtime != this)) { throw new Error("Invalid target runtime"); } }
/** * Releases the underlying {@link V8} instance. * * This method should be invoked once you're done using this object, * otherwise a large amount of garbage could be left on the JVM due to * native resources. * * <b>Note:</b> If this method has already been called once, it * will do nothing. */ public void release() { if ((v8 != null) && !v8.isReleased()) { // Release the V8 instance from the V8 thread context. run(new V8Runnable() { @Override public void run(final V8 v8) { if ((v8 != null) && !v8.isReleased()) { v8.close(); } } }); } } }
/** * Release the lock if it's currently held by the calling thread. * If the current thread does not hold the lock, and error will be * thrown. If no thread holds the lock then nothing will happen. */ public synchronized void release() { if ((released && (thread == null)) || runtime.isReleased()) { return; } checkThread(); runtime.releaseLock(runtime.getV8RuntimePtr()); thread = null; released = true; }
/** * Releases the NodeJS runtime. */ public void release() { v8.checkThread(); if (!require.isReleased()) { require.close(); } if (!v8.isReleased()) { v8.close(); } }
@Override public String toString() { if (isReleased() || v8.isReleased()) { return "[Object released]"; } v8.checkThread(); return v8.toString(v8.getV8RuntimePtr(), getHandle()); }
@Test public void testExceptionInReleaseHandlerStillReleasesV8() { V8 testV8 = V8.createV8Runtime(); V8Runnable releaseHandler = mock(V8Runnable.class); doThrow(new RuntimeException()).when(releaseHandler).run(any(V8.class)); testV8.addReleaseHandler(releaseHandler); try { testV8.close(); } catch (Exception e) { assertTrue(testV8.isReleased()); return; } fail("Exception should have been caught."); }
if (isReleased()) { return;
/** * Releases the NodeJS runtime. */ public void release() { v8.checkThread(); if (!require.isReleased()) { require.release(); } if (!v8.isReleased()) { v8.release(); } }