Skip to content

Commit 49257f7

Browse files
committed
Test reading an out-of-bounds array element.
1 parent 08249f8 commit 49257f7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ public void testArrayHoles() {
204204
}
205205
}
206206

207+
/**
208+
* Test reading out of bounds.
209+
*/
210+
@Test(expected = ArrayIndexOutOfBoundsException.class)
211+
public void testArrayIndexOutOfBounds() {
212+
try (Context context = JSTest.newContextBuilder().build()) {
213+
Value array = context.eval(ID, "[3, 4, 1, 5]");
214+
assertEquals(4, array.getArraySize());
215+
array.getArrayElement(4);
216+
}
217+
}
218+
207219
private static final int[] JAVA_ARRAY = new int[]{3, 4, 1, 5};
208220
private static final List<Integer> JAVA_LIST = Arrays.stream(JAVA_ARRAY).boxed().collect(Collectors.toList());
209221
private static final String JS_ARRAY_STRING = Arrays.toString(JAVA_ARRAY);

0 commit comments

Comments
 (0)