Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>ArrayBuffer stream with large ArrayBuffer test</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript">
add_task(async function testLargeArrayBuffer() {
let ab = new ArrayBuffer(4.5 * 1024 * 1024 * 1024); // 4.5 GB.
let ta = new Uint8Array(ab);
const { Cc, Ci } = SpecialPowers;
let abis = Cc["@mozilla.org/io/arraybuffer-input-stream;1"]
.createInstance(Ci.nsIArrayBufferInputStream);
let sis = Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
sis.init(abis);
// The stream currently doesn't support more than UINT32_MAX bytes.
let ex;
try {
abis.setData(ab, 0, ab.byteLength);
} catch (e) {
ex = e;
}
is(ex.message.includes("NS_ERROR_ILLEGAL_VALUE"), true, "Expecting exception");
// Reading a small slice of the large ArrayBuffer is fine, even near the end.
ta[ta.length - 10] = "a".charCodeAt(0);
ta[ta.length - 9] = "b".charCodeAt(0);
ta[ta.length - 8] = "c".charCodeAt(0);
abis.setData(ab, ab.byteLength - 10, 2);
is(sis.read(1), "a", "should read 'a' after init");
is(sis.read(1), "b", "should read 'b' after 'a'");
is(sis.read(1), "", "Should be done reading data");
});
</script>
</head>
<body>
</body>
</html>