blob: 64f6fc7276c3a9c596d2335a9f157fbf08d20b66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1688616
-->
<head>
<meta charset="utf-8">
<title>Test for large ArrayBuffers and views</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1688616">Mozilla Bug 1688616</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script type="application/javascript">
/* global TestFunctions */
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]}, go);
function checkThrowsTooLarge(f) {
let ex;
try{
f();
ok(false, "Should have thrown!");
} catch (e) {
ex = e;
}
ok(ex.toString().includes("larger than 2 GB"), "Got exception: " + ex);
}
function go() {
let test = new TestFunctions();
const gb = 1 * 1024 * 1024 * 1024;
let ab = new ArrayBuffer(5 * gb);
checkThrowsTooLarge(() => test.testNotAllowShared(ab));
checkThrowsTooLarge(() => test.testAllowShared(ab));
checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBuffer: ab}));
checkThrowsTooLarge(() => test.testUnionOfBuffferSource(ab));
checkThrowsTooLarge(() => { test.arrayBuffer = ab; });
checkThrowsTooLarge(() => { test.allowSharedArrayBuffer = ab; });
checkThrowsTooLarge(() => { test.sequenceOfArrayBuffer = [ab]; });
checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBuffer = [ab]; });
let ta = new Int8Array(ab, 0, 3 * gb);
checkThrowsTooLarge(() => test.testNotAllowShared(ta));
checkThrowsTooLarge(() => test.testAllowShared(ta));
checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBufferView: ta}));
checkThrowsTooLarge(() => test.testUnionOfBuffferSource(ta));
checkThrowsTooLarge(() => { test.arrayBufferView = ta; });
checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = ta; });
checkThrowsTooLarge(() => { test.sequenceOfArrayBufferView = [ta]; });
checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [ta]; });
let dv = new DataView(ab);
checkThrowsTooLarge(() => test.testNotAllowShared(dv));
checkThrowsTooLarge(() => test.testAllowShared(dv));
checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBufferView: dv}));
checkThrowsTooLarge(() => test.testUnionOfBuffferSource(dv));
checkThrowsTooLarge(() => { test.arrayBufferView = dv; });
checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = dv; });
checkThrowsTooLarge(() => { test.sequenceOfArrayBufferView = [dv]; });
checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [dv]; });
if (this.SharedArrayBuffer) {
let sab = new SharedArrayBuffer(5 * gb);
checkThrowsTooLarge(() => test.testAllowShared(sab));
checkThrowsTooLarge(() => test.testDictWithAllowShared({allowSharedArrayBuffer: sab}));
checkThrowsTooLarge(() => test.testUnionOfAllowSharedBuffferSource(sab));
checkThrowsTooLarge(() => { test.allowSharedArrayBuffer = sab; });
checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBuffer = [sab]; });
let sta = new Int8Array(sab);
checkThrowsTooLarge(() => test.testAllowShared(sta));
checkThrowsTooLarge(() => test.testDictWithAllowShared({allowSharedArrayBufferView: sta}));
checkThrowsTooLarge(() => test.testUnionOfAllowSharedBuffferSource(sta));
checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = sta; });
checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [sta]; });
}
// Small views on large buffers are fine.
let ta2 = new Int8Array(ab, 4 * gb);
is(ta2.byteLength, 1 * gb, "Small view on large ArrayBuffer");
test.testNotAllowShared(ta2);
test.arrayBufferView = ta2;
SimpleTest.finish();
}
</script>
</body>
</html>
|