@@ -422,14 +422,16 @@ protected DynamicObject getJSObject(DynamicObject thisObj,
422422 protected DynamicObject getForeignObject (Object thisObj ,
423423 @ CachedLibrary ("thisObj" ) InteropLibrary interop ,
424424 @ CachedLibrary (limit = "3" ) InteropLibrary members ,
425- @ Cached ("create()" ) ImportValueNode toJSType ) {
425+ @ Cached ("create()" ) ImportValueNode toJSType ,
426+ @ Cached BranchProfile errorBranch ) {
426427 DynamicObject result = JSOrdinary .create (getContext ());
427428
428429 try {
429430 if (interop .hasMembers (thisObj )) {
430431 Object keysObj = interop .getMembers (thisObj );
431432 long size = members .getArraySize (keysObj );
432433 if (size < 0 || size >= Integer .MAX_VALUE ) {
434+ errorBranch .enter ();
433435 throw Errors .createRangeErrorInvalidArrayLength ();
434436 }
435437 for (int i = 0 ; i < size ; i ++) {
@@ -448,6 +450,7 @@ protected DynamicObject getForeignObject(Object thisObj,
448450 if (interop .hasArrayElements (thisObj )) {
449451 long size = interop .getArraySize (thisObj );
450452 if (size < 0 || size >= Integer .MAX_VALUE ) {
453+ errorBranch .enter ();
451454 throw Errors .createRangeErrorInvalidArrayLength ();
452455 }
453456 for (long i = 0 ; i < size ; i ++) {
@@ -513,13 +516,15 @@ protected DynamicObject getForeignObjectSymbols(@SuppressWarnings("unused") Obje
513516 @ Specialization (guards = {"isForeignObject(thisObj)" , "!symbols" }, limit = "3" )
514517 protected DynamicObject getForeignObjectNames (Object thisObj ,
515518 @ CachedLibrary ("thisObj" ) InteropLibrary interop ,
516- @ CachedLibrary (limit = "3" ) InteropLibrary members ) {
519+ @ CachedLibrary (limit = "3" ) InteropLibrary members ,
520+ @ Cached BranchProfile errorBranch ) {
517521 Object [] array ;
518522 if (interop .hasMembers (thisObj )) {
519523 try {
520524 Object keysObj = interop .getMembers (thisObj );
521525 long size = members .getArraySize (keysObj );
522526 if (size < 0 || size >= Integer .MAX_VALUE ) {
527+ errorBranch .enter ();
523528 throw Errors .createRangeErrorInvalidArrayLength ();
524529 }
525530 array = new Object [(int ) size ];
@@ -819,12 +824,14 @@ protected DynamicObject keysOther(Object thisObj) {
819824 protected DynamicObject keysForeign (Object obj ,
820825 @ CachedLibrary ("obj" ) InteropLibrary interop ,
821826 @ CachedLibrary (limit = "3" ) InteropLibrary members ,
822- @ Cached BranchProfile growProfile ) {
827+ @ Cached BranchProfile growProfile ,
828+ @ Cached BranchProfile errorBranch ) {
823829 if (interop .hasMembers (obj )) {
824830 try {
825831 Object keysObj = interop .getMembers (obj );
826832 long size = members .getArraySize (keysObj );
827833 if (size < 0 || size >= Integer .MAX_VALUE ) {
834+ errorBranch .enter ();
828835 throw Errors .createRangeErrorInvalidArrayLength ();
829836 }
830837 if (size > 0 ) {
@@ -1060,11 +1067,13 @@ protected DynamicObject enumerableOwnPropertyNamesForeign(Object thisObj,
10601067 @ CachedLibrary ("thisObj" ) InteropLibrary interop ,
10611068 @ CachedLibrary (limit = "3" ) InteropLibrary members ,
10621069 @ Cached ImportValueNode importValue ,
1063- @ Cached BranchProfile growProfile ) {
1070+ @ Cached BranchProfile growProfile ,
1071+ @ Cached BranchProfile errorBranch ) {
10641072 try {
10651073 Object keysObj = interop .getMembers (thisObj );
10661074 long size = members .getArraySize (keysObj );
10671075 if (size < 0 || size >= Integer .MAX_VALUE ) {
1076+ errorBranch .enter ();
10681077 throw Errors .createRangeErrorInvalidArrayLength ();
10691078 }
10701079 SimpleArrayList <Object > values = SimpleArrayList .create (size );
0 commit comments