Skip to content

Commit 4b84adf

Browse files
committed
Adding test of ArrayBuffer.prototype.byteLength of detached interop array buffer.
1 parent ea7cc54 commit 4b84adf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/interop/InteropByteBufferTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,19 @@ public void testReadOnlyByteBuffer() {
278278
assertThrows(() -> jsBuffer.setArrayElement(0, 42), e -> assertTrue(e.getMessage(), e.getMessage().startsWith("TypeError")));
279279
}
280280
}
281+
282+
@Test
283+
public void testDetachedInteropArrayBuffer() {
284+
HostAccess hostAccess = HostAccess.newBuilder().allowBufferAccess(true).build();
285+
try (Context context = JSTest.newContextBuilder().allowHostAccess(hostAccess).allowExperimentalOptions(true).option("js.debug-builtin", "true").option("js.v8-compat", "true").build()) {
286+
ByteBuffer buffer = ByteBuffer.wrap(new byte[]{1, 2, 3});
287+
context.getBindings("js").putMember("buffer", buffer);
288+
Value byteLength = context.eval(ID, "" +
289+
"var arrayBuffer = new ArrayBuffer(buffer);\n" +
290+
"Debug.typedArrayDetachBuffer(arrayBuffer);\n" +
291+
"arrayBuffer.byteLength;");
292+
assertEquals(0, byteLength.asInt());
293+
}
294+
}
295+
281296
}

0 commit comments

Comments
 (0)