use of com.oracle.truffle.api.interop.InvalidArrayIndexException in project graal by oracle.
the class TestMemberAccess method testArrayOutOfBoundsAccess.
@Test
public void testArrayOutOfBoundsAccess() throws InteropException {
Object[] array = new Object[1];
TruffleObject arrayObject = asTruffleObject(array);
assertTrue(INTEROP.hasArrayElements(arrayObject));
INTEROP.readArrayElement(arrayObject, 0);
try {
INTEROP.readArrayElement(arrayObject, 1);
fail();
} catch (InvalidArrayIndexException e) {
}
}
use of com.oracle.truffle.api.interop.InvalidArrayIndexException in project graal by oracle.
the class HostToTypeNode method truffleObjectToArray.
private static Object truffleObjectToArray(HostContext hostContext, InteropLibrary interop, Object receiver, Class<?> arrayType, Type genericArrayType) {
Class<?> componentType = arrayType.getComponentType();
long size;
try {
size = interop.getArraySize(receiver);
} catch (UnsupportedMessageException e1) {
assert false : "unexpected language behavior";
size = 0;
}
size = Math.min(size, Integer.MAX_VALUE);
Object array = Array.newInstance(componentType, (int) size);
Type genericComponentType = getGenericArrayComponentType(genericArrayType);
for (int i = 0; i < size; i++) {
Object guestValue;
try {
guestValue = interop.readArrayElement(receiver, i);
} catch (InvalidArrayIndexException e) {
throw HostInteropErrors.invalidArrayIndex(hostContext, receiver, componentType, i);
} catch (UnsupportedMessageException e) {
throw HostInteropErrors.arrayReadUnsupported(hostContext, receiver, componentType);
}
Object hostValue = HostToTypeNodeGen.getUncached().execute(hostContext, guestValue, componentType, genericComponentType, true);
Array.set(array, i, hostValue);
}
return array;
}
Aggregations