| 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", kSig_i_i) |
| 17 .addBody([ | 17 .addBody([ |
| 18 // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0; | 18 // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0; |
| 19 kExprLoop, | 19 kExprLoop, |
| 20 kExprGetLocal,0, | 20 kExprGetLocal,0, |
| 21 kExprIf, | 21 kExprIf, |
| 22 kExprGetLocal,0, | 22 kExprGetLocal,0, |
| 23 kExprI32LoadMem,0,0, | 23 kExprI32LoadMem,0,0, |
| 24 kExprIf, | 24 kExprIf, |
| 25 kExprI8Const,255, | 25 kExprI8Const,255, |
| 26 kExprReturn, kArity1, | 26 kExprReturn, kArity1, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 testOuterMemorySurvivalAcrossGc(); | 121 testOuterMemorySurvivalAcrossGc(); |
| 122 testOuterMemorySurvivalAcrossGc(); | 122 testOuterMemorySurvivalAcrossGc(); |
| 123 testOuterMemorySurvivalAcrossGc(); | 123 testOuterMemorySurvivalAcrossGc(); |
| 124 testOuterMemorySurvivalAcrossGc(); | 124 testOuterMemorySurvivalAcrossGc(); |
| 125 | 125 |
| 126 | 126 |
| 127 function testOOBThrows() { | 127 function testOOBThrows() { |
| 128 var builder = new WasmModuleBuilder(); | 128 var builder = new WasmModuleBuilder(); |
| 129 | 129 |
| 130 builder.addMemory(1, 1, true); | 130 builder.addMemory(1, 1, true); |
| 131 builder.addFunction("geti", [kAstI32, kAstI32, kAstI32]) | 131 builder.addFunction("geti", kSig_i_ii) |
| 132 .addBody([ | 132 .addBody([ |
| 133 kExprGetLocal, 0, | 133 kExprGetLocal, 0, |
| 134 kExprGetLocal, 1, | 134 kExprGetLocal, 1, |
| 135 kExprI32LoadMem, 0, 0, | 135 kExprI32LoadMem, 0, 0, |
| 136 kExprI32StoreMem, 0, 0 | 136 kExprI32StoreMem, 0, 0 |
| 137 ]) | 137 ]) |
| 138 .exportFunc(); | 138 .exportFunc(); |
| 139 | 139 |
| 140 var module = builder.instantiate(); | 140 var module = builder.instantiate(); |
| 141 var offset; | 141 var offset; |
| 142 | 142 |
| 143 function read() { return module.exports.geti(0, offset); } | 143 function read() { return module.exports.geti(0, offset); } |
| 144 function write() { return module.exports.geti(offset, 0); } | 144 function write() { return module.exports.geti(offset, 0); } |
| 145 | 145 |
| 146 for (offset = 0; offset < 65533; offset++) { | 146 for (offset = 0; offset < 65533; offset++) { |
| 147 assertEquals(0, read()); | 147 assertEquals(0, read()); |
| 148 assertEquals(0, write()); | 148 assertEquals(0, write()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 | 151 |
| 152 for (offset = 65534; offset < 66536; offset++) { | 152 for (offset = 65534; offset < 66536; offset++) { |
| 153 assertTraps(kTrapMemOutOfBounds, read); | 153 assertTraps(kTrapMemOutOfBounds, read); |
| 154 assertTraps(kTrapMemOutOfBounds, write); | 154 assertTraps(kTrapMemOutOfBounds, write); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 testOOBThrows(); | 158 testOOBThrows(); |
| OLD | NEW |