                   bytearray.readBytes(bytearray3, 0, bytearray.length+1);
               }));
 
+    // Doc sez: A RangeError will be thrown if the value of offset+length exceeds 2^32-1
+    expectRangeError("RangeError in readBytes",
+                     (function () {
+                         bytearray3.position = 0;
+                         bytearray.readBytes(bytearray3, 0xFFFFFFFF, 1);
+                     }));
+
     // TODO: test more combinations of offset and count
 }
 

    return bytearray;
}

// Utility to test for EOFError
function expectEOF(tag, thunk)
{

                          v = bytearray.readInt();
                      }));
        }

        // Testing for wraparound problems when reading with position
        // much greater than length.  Given that the bytevector size
        // is 1000, a length of 0xFFFFFFF0 will always wrap around on
        // a 32-bit system.  On a 64-bit system we depend on the C++
        // run-time code using uint32_t to represent length and
        // position; if it did not we might abort due to a too-large
        // allocation attempt.

        bytearray.length = 1000;
        expectEOF("ByteArray readInt_3 #2 at position=2^32-16",
                  (function () {
                      bytearray.position = 0xFFFFFFF0;
                      v = bytearray.readInt();
                    }));
    }

    for ( var offs=0 ; offs < 4 ; offs++ ) {
