OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm --expose-gc --stress-compaction | 5 // Flags: --expose-wasm --expose-gc --stress-compaction |
6 | 6 |
7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
9 | 9 |
10 var kMemSize = 65536; | 10 var kMemSize = 65536; |
11 | 11 |
12 function genModule(memory) { | 12 function genModule(memory) { |
13 var builder = new WasmModuleBuilder(); | 13 var builder = new WasmModuleBuilder(); |
14 | 14 |
15 builder.addMemory(1, 1, true); | 15 builder.addMemory(1, 1, true); |
16 builder.addFunction("main", [kAstI32, kAstI32]) | 16 builder.addFunction("main", [kAstI32, kAstI32]) |
17 .addBody([ | 17 .addBody([ |
18 kExprBlock,2, | 18 // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0; |
19 kExprLoop,1, | 19 kExprLoop, |
| 20 kExprGetLocal,0, |
| 21 kExprIf, |
| 22 kExprGetLocal,0, |
| 23 kExprI32LoadMem,0,0, |
20 kExprIf, | 24 kExprIf, |
21 kExprGetLocal,0, | 25 kExprI8Const,255, |
22 kExprBr, 0, | 26 kExprReturn, kArity1, |
23 kExprIfElse, | 27 kExprEnd, |
24 kExprI32LoadMem,0,0,kExprGetLocal,0, | 28 kExprGetLocal,0, |
25 kExprBr,2, kExprI8Const, 255, | 29 kExprI8Const,4, |
26 kExprSetLocal,0, | 30 kExprI32Sub, |
27 kExprI32Sub,kExprGetLocal,0,kExprI8Const,4, | 31 kExprSetLocal,0, |
28 kExprI8Const,0]) | 32 kExprBr, kArity1, 1, |
| 33 kExprEnd, |
| 34 kExprEnd, |
| 35 kExprI8Const,0 |
| 36 ]) |
29 .exportFunc(); | 37 .exportFunc(); |
30 | 38 |
31 return builder.instantiate(null, memory); | 39 return builder.instantiate(null, memory); |
32 } | 40 } |
33 | 41 |
34 function testPokeMemory() { | 42 function testPokeMemory() { |
35 var module = genModule(null); | 43 var module = genModule(null); |
36 var buffer = module.exports.memory; | 44 var buffer = module.exports.memory; |
37 var main = module.exports.main; | 45 var main = module.exports.main; |
38 assertEquals(kMemSize, buffer.byteLength); | 46 assertEquals(kMemSize, buffer.byteLength); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 testOuterMemorySurvivalAcrossGc(); | 123 testOuterMemorySurvivalAcrossGc(); |
116 testOuterMemorySurvivalAcrossGc(); | 124 testOuterMemorySurvivalAcrossGc(); |
117 | 125 |
118 | 126 |
119 function testOOBThrows() { | 127 function testOOBThrows() { |
120 var builder = new WasmModuleBuilder(); | 128 var builder = new WasmModuleBuilder(); |
121 | 129 |
122 builder.addMemory(1, 1, true); | 130 builder.addMemory(1, 1, true); |
123 builder.addFunction("geti", [kAstI32, kAstI32, kAstI32]) | 131 builder.addFunction("geti", [kAstI32, kAstI32, kAstI32]) |
124 .addBody([ | 132 .addBody([ |
125 kExprI32StoreMem, 0, 0, kExprGetLocal, 0, kExprI32LoadMem, 0, 0, kExprGetL
ocal, 1 | 133 kExprGetLocal, 0, |
| 134 kExprGetLocal, 1, |
| 135 kExprI32LoadMem, 0, 0, |
| 136 kExprI32StoreMem, 0, 0 |
126 ]) | 137 ]) |
127 .exportFunc(); | 138 .exportFunc(); |
128 | 139 |
129 var module = builder.instantiate(); | 140 var module = builder.instantiate(); |
130 | |
131 var offset; | 141 var offset; |
132 | 142 |
133 function read() { return module.exports.geti(0, offset); } | 143 function read() { return module.exports.geti(0, offset); } |
134 function write() { return module.exports.geti(offset, 0); } | 144 function write() { return module.exports.geti(offset, 0); } |
135 | 145 |
136 for (offset = 0; offset < 65533; offset++) { | 146 for (offset = 0; offset < 65533; offset++) { |
137 assertEquals(0, read()); | 147 assertEquals(0, read()); |
138 assertEquals(0, write()); | 148 assertEquals(0, write()); |
139 } | 149 } |
140 | 150 |
141 | 151 |
142 for (offset = 65534; offset < 66536; offset++) { | 152 for (offset = 65534; offset < 66536; offset++) { |
143 assertTraps(kTrapMemOutOfBounds, read); | 153 assertTraps(kTrapMemOutOfBounds, read); |
144 assertTraps(kTrapMemOutOfBounds, write); | 154 assertTraps(kTrapMemOutOfBounds, write); |
145 } | 155 } |
146 } | 156 } |
147 | 157 |
148 testOOBThrows(); | 158 testOOBThrows(); |
OLD | NEW |