guijemont@igalia.com | 1d54fba | 2018-11-19 14:00:06 +0000 | [diff] [blame] | 1 | //@ skip if $memoryLimited |
fpizlo@apple.com | f8ae08b | 2018-11-17 00:42:44 +0000 | [diff] [blame] | 2 | |
keith_miller@apple.com | 5292785 | 2018-12-06 18:59:44 +0000 | [diff] [blame] | 3 | function test() { |
| 4 | |
| 5 | // We don't support WebAssembly everywhere, so check for its existance before doing anything else. |
| 6 | if (!this.WebAssembly) |
fpizlo@apple.com | f8ae08b | 2018-11-17 00:42:44 +0000 | [diff] [blame] | 7 | return; |
keith_miller@apple.com | 5292785 | 2018-12-06 18:59:44 +0000 | [diff] [blame] | 8 | |
| 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.com | f8ae08b | 2018-11-17 00:42:44 +0000 | [diff] [blame] | 43 | } |
| 44 | |
keith_miller@apple.com | 5292785 | 2018-12-06 18:59:44 +0000 | [diff] [blame] | 45 | test(); |