test_arraybufferinputstream_large.html (1426B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>ArrayBuffer stream with large ArrayBuffer test</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 9 <script type="text/javascript"> 10 add_task(async function testLargeArrayBuffer() { 11 let ab = new ArrayBuffer(4.5 * 1024 * 1024 * 1024); // 4.5 GB. 12 let ta = new Uint8Array(ab); 13 14 const { Cc, Ci } = SpecialPowers; 15 let abis = Cc["@mozilla.org/io/arraybuffer-input-stream;1"] 16 .createInstance(Ci.nsIArrayBufferInputStream); 17 18 let sis = Cc["@mozilla.org/scriptableinputstream;1"] 19 .createInstance(Ci.nsIScriptableInputStream); 20 sis.init(abis); 21 22 // The stream currently doesn't support more than UINT32_MAX bytes. 23 let ex; 24 try { 25 abis.setData(ab, 0, ab.byteLength); 26 } catch (e) { 27 ex = e; 28 } 29 is(ex.message.includes("NS_ERROR_ILLEGAL_VALUE"), true, "Expecting exception"); 30 31 // Reading a small slice of the large ArrayBuffer is fine, even near the end. 32 ta[ta.length - 10] = "a".charCodeAt(0); 33 ta[ta.length - 9] = "b".charCodeAt(0); 34 ta[ta.length - 8] = "c".charCodeAt(0); 35 abis.setData(ab, ab.byteLength - 10, 2); 36 is(sis.read(1), "a", "should read 'a' after init"); 37 is(sis.read(1), "b", "should read 'b' after 'a'"); 38 is(sis.read(1), "", "Should be done reading data"); 39 }); 40 </script> 41 42 </head> 43 <body> 44 </body> 45 </html>