private void checkSize(final V8ArrayData arrayData) { if (arrayData.size < 0) { throw new IllegalStateException("RangeError: Invalid typed array length"); } int limit = (arrayData.size * getStructureSize(arrayData.type)) + arrayData.offset; if (limit > arrayData.buffer.limit()) { throw new IllegalStateException("RangeError: Invalid typed array length"); } }
private void checkSize(final V8ArrayData arrayData) { if (arrayData.size < 0) { throw new IllegalStateException("RangeError: Invalid typed array length"); } int limit = (arrayData.size * getStructureSize(arrayData.type)) + arrayData.offset; if (limit > arrayData.buffer.limit()) { throw new IllegalStateException("RangeError: Invalid typed array length"); } }
@Test public void testAccessArrayBuffer_Int8ArrayView() { V8ArrayBuffer buffer = (V8ArrayBuffer) v8.executeScript("var buf = new ArrayBuffer(4); var ints = new Int8Array(buf); ints[0] = 7; buf"); assertEquals(4, buffer.limit()); assertEquals(7, buffer.get(0)); buffer.close(); }
@Test public void testArrayBufferAsProperty() { V8Object root = v8.executeObjectScript("var buf = new ArrayBuffer(100);\n" + "var root = { 'items' : buf };\n" + "root;\n"); V8ArrayBuffer result = ((ArrayBuffer) V8ObjectUtils.getValue(root, "items")).getV8ArrayBuffer(); assertEquals(100, result.limit()); root.close(); result.close(); }
@Test public void testArrayBufferGetValue() { V8ArrayBuffer buf = (V8ArrayBuffer) v8.executeScript("var buf = new ArrayBuffer(100);\n" + "buf;\n"); V8ArrayBuffer result = ((ArrayBuffer) V8ObjectUtils.getValue(buf)).getV8ArrayBuffer(); assertEquals(100, result.limit()); buf.close(); result.close(); }
@Test public void testArrayTypedArrayValue_ArrayBuffer() { V8Array root = v8.executeArrayScript("var buf = new ArrayBuffer(100);\n" + "var root = [buf];\n" + "root;\n"); V8ArrayBuffer result = ((ArrayBuffer) V8ObjectUtils.getValue(root, 0)).getV8ArrayBuffer(); assertEquals(100, result.limit()); root.close(); result.close(); }