private void releaseNow(Object value) { if (value instanceof V8Value) { V8Value ref = (V8Value) value; if (!ref.isReleased()) { ref.release(); } } } }
private void releaseArguments(final Object[] args, final boolean hasVarArgs) { if (hasVarArgs && ((args.length > 0) && (args[args.length - 1] instanceof Object[]))) { Object[] varArgs = (Object[]) args[args.length - 1]; for (Object object : varArgs) { if (object instanceof V8Value) { ((V8Value) object).release(); } } } for (Object arg : args) { if (arg instanceof V8Value) { ((V8Value) arg).release(); } } }
private void releaseArguments(final Object[] args, final boolean hasVarArgs) { if (hasVarArgs && ((args.length > 0) && (args[args.length - 1] instanceof Object[]))) { Object[] varArgs = (Object[]) args[args.length - 1]; for (Object object : varArgs) { if (object instanceof V8Value) { ((V8Value) object).release(); } } } for (Object arg : args) { if (arg instanceof V8Value) { ((V8Value) arg).release(); } } }
@Override public void clear() { map.clear(); for (V8Value V8Value : twinMap.keySet()) { V8Value.release(); } twinMap.clear(); }
@Override public V remove(final Object key) { V result = map.remove(key); V8Value twin = twinMap.remove(key); if (twin != null) { twin.release(); } return result; }
@Override public V remove(final Object key) { V result = map.remove(key); V8Value twin = twinMap.remove(key); if (twin != null) { twin.release(); } return result; }
@Override public void clear() { map.clear(); for (V8Value V8Value : twinMap.keySet()) { V8Value.release(); } twinMap.clear(); }
/** * Pushes a Java Object to a V8Array by first converting it to a V8Value if needed. * If the value is a boxed primitive, then the primitive will be pushed. If the object * is a Map / List then a deep copy will be performed, converting the object to a * V8Object / V8Array first. * * @param v8 The runtime on which to create any needed V8Values. * @param array The array to push the elements to. * @param value The value to push to the array. */ public static void pushValue(final V8 v8, final V8Array array, final Object value) { Map<Object, V8Value> cache = new Hashtable<Object, V8Value>(); try { pushValue(v8, array, value, cache); } finally { for (V8Value v8Object : cache.values()) { v8Object.release(); } } }
/** * Pushes a Java Object to a V8Array by first converting it to a V8Value if needed. * If the value is a boxed primitive, then the primitive will be pushed. If the object * is a Map / List then a deep copy will be performed, converting the object to a * V8Object / V8Array first. * * @param v8 The runtime on which to create any needed V8Values. * @param array The array to push the elements to. * @param value The value to push to the array. */ public static void pushValue(final V8 v8, final V8Array array, final Object value) { Map<Object, V8Value> cache = new Hashtable<Object, V8Value>(); try { pushValue(v8, array, value, cache); } finally { for (V8Value v8Object : cache.values()) { v8Object.release(); } } }
/** * Creates a V8Array from a java.util.List. This is a deep copy, so if the list * contains other lists (or maps) they will also be converted. * * @param v8 The runtime on which to create the result. * @param list The list to convert to a V8Array. * * @return A V8Array representing the list. */ public static V8Array toV8Array(final V8 v8, final List<? extends Object> list) { Map<Object, V8Value> cache = new Hashtable<Object, V8Value>(); try { return toV8Array(v8, list, cache).twin(); } finally { for (V8Value v8Object : cache.values()) { v8Object.release(); } } }
/** * Creates a V8Object from a java.util.Map. This is a deep copy, so if the map * contains other maps (or lists) they will also be converted. * * @param v8 The runtime on which to create the result. * @param map The map to convert to a V8Object. * * @return A V8Object representing the map. */ public static V8Object toV8Object(final V8 v8, final Map<String, ? extends Object> map) { Map<Object, V8Value> cache = new Hashtable<Object, V8Value>(); try { return toV8Object(v8, map, cache).twin(); } finally { for (V8Value v8Object : cache.values()) { v8Object.release(); } } }
/** * Creates a V8Object from a java.util.Map. This is a deep copy, so if the map * contains other maps (or lists) they will also be converted. * * @param v8 The runtime on which to create the result. * @param map The map to convert to a V8Object. * * @return A V8Object representing the map. */ public static V8Object toV8Object(final V8 v8, final Map<String, ? extends Object> map) { Map<Object, V8Value> cache = new Hashtable<Object, V8Value>(); try { return toV8Object(v8, map, cache).twin(); } finally { for (V8Value v8Object : cache.values()) { v8Object.release(); } } }
/** * Creates a V8Array from a java.util.List. This is a deep copy, so if the list * contains other lists (or maps) they will also be converted. * * @param v8 The runtime on which to create the result. * @param list The list to convert to a V8Array. * * @return A V8Array representing the list. */ public static V8Array toV8Array(final V8 v8, final List<? extends Object> list) { Map<Object, V8Value> cache = new Hashtable<Object, V8Value>(); try { return toV8Array(v8, list, cache).twin(); } finally { for (V8Value v8Object : cache.values()) { v8Object.release(); } } }
} finally { for (V8Value v8Object : cache.values()) { v8Object.release();
/** * Releases this Memory Manager and all V8Objects that were created while * this memory manager was active. */ public void release() { v8.getLocker().checkThread(); if (released) { return; } releasing = true; try { for (V8Value reference : references) { reference.release(); } v8.removeReferenceHandler(memoryManagerReferenceHandler); references.clear(); } finally { releasing = false; } released = true; }
/** * Releases this Memory Manager and all V8Objects that were created while * this memory manager was active. */ public void release() { v8.getLocker().checkThread(); if (released) { return; } releasing = true; try { for (V8Value reference : references) { reference.release(); } v8.removeReferenceHandler(memoryManagerReferenceHandler); references.clear(); } finally { releasing = false; } released = true; }