@@ -303,31 +303,44 @@ public long getArraySize(
303
303
304
304
@ ExportMessage
305
305
public boolean isArrayElementReadable (@ SuppressWarnings ("unused" ) long idx ,
306
+ @ Shared ("getItemNode" ) @ Cached PInteropSubscriptNode getItemNode ,
306
307
@ Shared ("callLenNode" ) @ Cached LookupAndCallUnaryDynamicNode callLenNode ) {
307
- return isInBounds (callLenNode , idx );
308
+ return isInBounds (callLenNode , getItemNode , idx );
308
309
}
309
310
310
311
@ ExportMessage
311
312
public boolean isArrayElementModifiable (@ SuppressWarnings ("unused" ) long idx ,
313
+ @ Shared ("getItemNode" ) @ Cached PInteropSubscriptNode getItemNode ,
312
314
@ Shared ("callLenNode" ) @ Cached LookupAndCallUnaryDynamicNode callLenNode ) {
313
- return !(this instanceof PTuple ) && !(this instanceof PBytes ) && isInBounds (callLenNode , idx );
315
+ return !(this instanceof PTuple ) && !(this instanceof PBytes ) && isInBounds (callLenNode , getItemNode , idx );
314
316
}
315
317
316
318
@ ExportMessage
317
319
public boolean isArrayElementInsertable (@ SuppressWarnings ("unused" ) long idx ,
320
+ @ Shared ("getItemNode" ) @ Cached PInteropSubscriptNode getItemNode ,
318
321
@ Shared ("callLenNode" ) @ Cached LookupAndCallUnaryDynamicNode callLenNode ) {
319
- return !(this instanceof PTuple ) && !(this instanceof PBytes ) && !isInBounds (callLenNode , idx );
322
+ return !(this instanceof PTuple ) && !(this instanceof PBytes ) && !isInBounds (callLenNode , getItemNode , idx );
320
323
}
321
324
322
325
@ ExportMessage
323
326
public boolean isArrayElementRemovable (@ SuppressWarnings ("unused" ) long idx ,
327
+ @ Shared ("getItemNode" ) @ Cached PInteropSubscriptNode getItemNode ,
324
328
@ Shared ("callLenNode" ) @ Cached LookupAndCallUnaryDynamicNode callLenNode ) {
325
- return !(this instanceof PTuple ) && !(this instanceof PBytes ) && isInBounds (callLenNode , idx );
329
+ return !(this instanceof PTuple ) && !(this instanceof PBytes ) && isInBounds (callLenNode , getItemNode , idx );
326
330
}
327
331
328
- private boolean isInBounds (LookupAndCallUnaryDynamicNode callLenNode , long idx ) {
332
+ private boolean isInBounds (LookupAndCallUnaryDynamicNode callLenNode , PInteropSubscriptNode getItemNode , long idx ) {
329
333
long len = getArraySizeSafe (callLenNode );
330
- return 0 <= idx && idx < len ;
334
+ if (0 <= idx && idx < len ) {
335
+ try {
336
+ getItemNode .execute (this , idx );
337
+ return true ;
338
+ } catch (PException e ) {
339
+ return false ;
340
+ }
341
+ } else {
342
+ return false ;
343
+ }
331
344
}
332
345
333
346
private long getArraySizeSafe (LookupAndCallUnaryDynamicNode callLenNode ) {
0 commit comments