                   bytearray.readUTF();
               }));
 
-    // TODO: test that any UTF8 BOM is being skipped
+    // Doc sez: A RangeError will be thrown for writeUTF if the string length exceeds 65535.
+    expectRangeError("RangeError in writeUTF",
+                     (function () {
+                         var s = "86868686";
+                         while (s.length <= 65535)
+                             s = s + s;
+                         bytearray.writeUTF(s);
+                     }));
+
+    // Skip UTF-8 BOM.
+    // This seems fairly ill-defined and ad-hoc since the BOM is skipped but is accounted for in the byte count,
+    // but it's what we do, so test that we continue to do it...
+    bytearray.length = 0;
+    bytearray.position = 0;
+    bytearray.endian = "bigEndian";
+    bytearray.writeByte(0);
+    bytearray.writeByte(6);
+    bytearray.writeByte(0xEF);
+    bytearray.writeByte(0xBB);
+    bytearray.writeByte(0xBF);
+    bytearray.writeUTFBytes("string");
+    bytearray.position = 0;
+    AddTestCase("ByteArray readUTF skips UTF8 BOM after length bytes but includes it in the length",
+                "str",
+                bytearray.readUTF());
+
     // TODO: test invalid UTF - we should still get data, in a predictable way (invalid input turns into individual bytes)
 }
 

                  bytearray.readBytes(bytearray3, 0, bytearray.length+1);
              }));

    // TODO: test more combinations of offset and count
}


                          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++ ) {
