private static V8TypedArray toV8TypedArray(final V8 v8, final TypedArray typedArray, final Map<Object, V8Value> cache) { if (cache.containsKey(typedArray)) { return (V8TypedArray) cache.get(typedArray); } V8ArrayBuffer arrayBuffer = new V8ArrayBuffer(v8, typedArray.getByteBuffer()); try { V8TypedArray result = new V8TypedArray(v8, arrayBuffer, typedArray.getType(), 0, typedArray.length()); cache.put(typedArray, result); return result; } finally { arrayBuffer.release(); } }
protected TypedArray(final ByteBuffer buffer) { if (!buffer.isDirect()) { throw new IllegalArgumentException("ByteBuffer must be a allocated as a direct ByteBuffer"); } if ((buffer.limit() % V8TypedArray.getStructureSize(getType())) != 0) { throw new IllegalArgumentException("ByteBuffer must be a allocated as a direct ByteBuffer"); } this.buffer = buffer; }
protected TypedArray(final ByteBuffer buffer) { if (!buffer.isDirect()) { throw new IllegalArgumentException("ByteBuffer must be a allocated as a direct ByteBuffer"); } if ((buffer.limit() % V8TypedArray.getStructureSize(getType())) != 0) { throw new IllegalArgumentException("ByteBuffer must be a allocated as a direct ByteBuffer"); } this.buffer = buffer; }
private static V8TypedArray toV8TypedArray(final V8 v8, final TypedArray typedArray, final Map<Object, V8Value> cache) { if (cache.containsKey(typedArray)) { return (V8TypedArray) cache.get(typedArray); } V8ArrayBuffer arrayBuffer = new V8ArrayBuffer(v8, typedArray.getByteBuffer()); try { V8TypedArray result = new V8TypedArray(v8, arrayBuffer, typedArray.getType(), 0, typedArray.length()); cache.put(typedArray, result); return result; } finally { arrayBuffer.release(); } }