blob: 5b80dca1822ec2c14da4de44621dc20ce5d46ddd [file] [log] [blame]
guijemont@igalia.com1d54fba2018-11-19 14:00:06 +00001//@ skip if $memoryLimited
fpizlo@apple.comf8ae08b2018-11-17 00:42:44 +00002
keith_miller@apple.com52927852018-12-06 18:59:44 +00003function test() {
4
5 // We don't support WebAssembly everywhere, so check for its existance before doing anything else.
6 if (!this.WebAssembly)
fpizlo@apple.comf8ae08b2018-11-17 00:42:44 +00007 return;
keith_miller@apple.com52927852018-12-06 18:59:44 +00008
9 let bigArray = new Array(0x7000000);
10 bigArray[0] = 1.1;
11 bigArray[1] = 1.2;
12
13 function foo(array) {
14 var index = array.length;
15 if (index >= bigArray.length || (index - 0x1ffdc01) < 0)
16 return;
17 return bigArray[index - 0x1ffdc01];
18 }
19
20 noInline(foo);
21
22 var okArray = new Uint8Array(0x1ffdc02);
23
24 for (var i = 0; i < 10000; ++i)
25 foo(okArray);
26
27 var ok = false;
28 try {
29 var memory = new WebAssembly.Memory({ initial: 0x1000 });
30 memory.grow(0x7000);
31 var result = foo(new Uint8Array(memory.buffer));
32 if (result !== void 0)
33 throw "Error: bad result at end: " + result;
34 ok = true;
35 } catch (e) {
36 if (e.toString() != "Error: Out of memory")
37 throw e;
38 }
39
40 if (ok)
41 throw "Error: did not throw error";
42
fpizlo@apple.comf8ae08b2018-11-17 00:42:44 +000043}
44
keith_miller@apple.com52927852018-12-06 18:59:44 +000045test();