private static V8TypedArray toV8TypedArray(final V8 v8, final TypedArray typeArray, final Map<Object, V8Value> cache) { if (cache.containsKey(typeArray)) { return (V8TypedArray) cache.get(typeArray); } V8TypedArray result = typeArray.getV8TypedArray(); cache.put(typeArray, result); return result; }
private static V8TypedArray toV8TypedArray(final V8 v8, final TypedArray typeArray, final Map<Object, V8Value> cache) { if (cache.containsKey(typeArray)) { return (V8TypedArray) cache.get(typeArray); } V8TypedArray result = typeArray.getV8TypedArray(); cache.put(typeArray, result); return result; }
@Override public Boolean invoke(final V8Object receiver, final V8Array parameters) { V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(parameters, 0)).getV8TypedArray(); try { return result.getType() == V8Value.FLOAT_64_ARRAY; } finally { result.close(); } } };
@Override public Boolean invoke(final V8Object receiver, final V8Array parameters) { V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(parameters, 0)).getV8TypedArray(); try { return result.getType() == V8Value.FLOAT_32_ARRAY; } finally { result.close(); } } };
@Override public Boolean invoke(final V8Object receiver, final V8Array parameters) { V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(parameters, 0)).getV8TypedArray(); try { return result.getType() == V8Value.INT_32_ARRAY; } finally { result.close(); } } };
@Override public Boolean invoke(final V8Object receiver, final V8Array parameters) { V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(parameters, 0)).getV8TypedArray(); try { return result.getType() == V8Value.UNSIGNED_INT_16_ARRAY; } finally { result.close(); } } };
@Override public Boolean invoke(final V8Object receiver, final V8Array parameters) { V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(parameters, 0)).getV8TypedArray(); try { return result.getType() == V8Value.UNSIGNED_INT_32_ARRAY; } finally { result.close(); } } };
@Override public Boolean invoke(final V8Object receiver, final V8Array parameters) { V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(parameters, 0)).getV8TypedArray(); try { return result.getType() == V8Value.INT_16_ARRAY; } finally { result.close(); } } };
@Override public Boolean invoke(final V8Object receiver, final V8Array parameters) { V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(parameters, 0)).getV8TypedArray(); try { return result.getType() == V8Value.UNSIGNED_INT_8_ARRAY; } finally { result.close(); } } };
@Override public Boolean invoke(final V8Object receiver, final V8Array parameters) { V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(parameters, 0)).getV8TypedArray(); try { return result.getType() == V8Value.UNSIGNED_INT_8_CLAMPED_ARRAY; } finally { result.close(); } } };
@Test public void testGetV8TypedArray() { TypedArray typedArray = new TypedArray(v8, new ArrayBuffer(v8, ByteBuffer.allocateDirect(8)), V8Value.INT_8_ARRAY, 0, 8); V8TypedArray v8TypedArray = typedArray.getV8TypedArray(); assertNotNull(v8TypedArray); v8TypedArray.close(); }
@Test public void testArrayTypedArrayValue_Int8ArrayWithoutBackingStore() { V8Array root = v8.executeArrayScript("" + "var intsArray = new Int8Array(24);\n" + "var root = [intsArray];\n" + "root;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(root, 0)).getV8TypedArray(); assertEquals(24, result.length()); root.close(); result.close(); }
@Test public void testTypedArrayGetValue_Uint8ClampedArray() { V8Array int8ClampedArray = v8.executeArrayScript("var buf = new ArrayBuffer(100);\n" + "var int8ClampedArray = new Uint8ClampedArray(buf);\n" + "int8ClampedArray[0] = 16;\n" + "int8ClampedArray;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(int8ClampedArray)).getV8TypedArray(); assertEquals(100, result.length()); assertEquals((short) 16, result.get(0)); int8ClampedArray.close(); result.close(); }
@Test public void testTypedArrayGetValue_Uint16Array() { V8Array intsArray = v8.executeArrayScript("var buf = new ArrayBuffer(100);\n" + "var intsArray = new Uint16Array(buf);\n" + "intsArray[0] = 16;\n" + "intsArray;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(intsArray)).getV8TypedArray(); assertEquals(50, result.length()); assertEquals(16, result.get(0)); intsArray.close(); result.close(); }
@Test public void testTypedArrayGetValue_Uint8Array() { V8Array intsArray = v8.executeArrayScript("var buf = new ArrayBuffer(100);\n" + "var intsArray = new Uint8Array(buf);\n" + "intsArray[0] = 16;\n" + "intsArray;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(intsArray)).getV8TypedArray(); assertEquals(100, result.length()); assertEquals((short) 16, result.get(0)); intsArray.close(); result.close(); }
@Test public void testTypedArrayGetValue_Uint32Array() { V8Array intsArray = v8.executeArrayScript("var buf = new ArrayBuffer(100);\n" + "var intsArray = new Uint32Array(buf);\n" + "intsArray[0] = 16;\n" + "intsArray;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(intsArray)).getV8TypedArray(); assertEquals(25, result.length()); assertEquals(16L, result.get(0)); intsArray.close(); result.close(); }
@Test public void testTypedArrayGetValue_Float64Array() { V8Array floatsArray = v8.executeArrayScript("var buf = new ArrayBuffer(80);\n" + "var floatsArray = new Float64Array(buf);\n" + "floatsArray[0] = 16.2;\n" + "floatsArray;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(floatsArray)).getV8TypedArray(); assertEquals(10, result.length()); assertEquals(16.2, (Double) result.get(0), 0.0001); floatsArray.close(); result.close(); }
@Test public void testArrayTypedArrayValue_Int16Array() { V8Array root = v8.executeArrayScript("var buf = new ArrayBuffer(100);\n" + "var intsArray = new Int16Array(buf);\n" + "intsArray[0] = 16;\n" + "var root = [intsArray];\n" + "root;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(root, 0)).getV8TypedArray(); assertEquals(50, result.length()); assertEquals((short) 16, result.get(0)); root.close(); result.close(); }
@Test public void testTypedArrayValue_Int32Array() { V8Object root = v8.executeObjectScript("var buf = new ArrayBuffer(100);\n" + "var intsArray = new Int32Array(buf);\n" + "intsArray[0] = 16;\n" + "var root = { 'items' : intsArray };\n" + "root;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(root, "items")).getV8TypedArray(); assertEquals(25, result.length()); assertEquals(16, result.get(0)); root.close(); result.close(); }
@Test public void testTypedArrayGetValue_Float32Array() { V8Array floatsArray = v8.executeArrayScript("var buf = new ArrayBuffer(100);\n" + "var floatsArray = new Float32Array(buf);\n" + "floatsArray[0] = 16.2;\n" + "floatsArray;\n"); V8TypedArray result = ((TypedArray) V8ObjectUtils.getValue(floatsArray)).getV8TypedArray(); assertEquals(25, result.length()); assertEquals(16.2, (Float) result.get(0), 0.00001); floatsArray.close(); result.close(); }