| 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 kExprBlock,2, |
| 19 kExprLoop,1, | 19 kExprLoop,1, |
| 20 kExprIf, | 20 kExprIf, |
| 21 kExprGetLocal,0, | 21 kExprGetLocal,0, |
| 22 kExprBr, 0, | 22 kExprBr, 0, |
| 23 kExprIfElse, | 23 kExprIfElse, |
| 24 kExprI32LoadMem,0,kExprGetLocal,0, | 24 kExprI32LoadMem,0,0,kExprGetLocal,0, |
| 25 kExprBr,2, kExprI8Const, 255, | 25 kExprBr,2, kExprI8Const, 255, |
| 26 kExprSetLocal,0, | 26 kExprSetLocal,0, |
| 27 kExprI32Sub,kExprGetLocal,0,kExprI8Const,4, | 27 kExprI32Sub,kExprGetLocal,0,kExprI8Const,4, |
| 28 kExprI8Const,0]) | 28 kExprI8Const,0]) |
| 29 .exportFunc(); | 29 .exportFunc(); |
| 30 | 30 |
| 31 return builder.instantiate(null, memory); | 31 return builder.instantiate(null, memory); |
| 32 } | 32 } |
| 33 | 33 |
| 34 function testPokeMemory() { | 34 function testPokeMemory() { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 testOuterMemorySurvivalAcrossGc(); | 115 testOuterMemorySurvivalAcrossGc(); |
| 116 testOuterMemorySurvivalAcrossGc(); | 116 testOuterMemorySurvivalAcrossGc(); |
| 117 | 117 |
| 118 | 118 |
| 119 function testOOBThrows() { | 119 function testOOBThrows() { |
| 120 var builder = new WasmModuleBuilder(); | 120 var builder = new WasmModuleBuilder(); |
| 121 | 121 |
| 122 builder.addMemory(1, 1, true); | 122 builder.addMemory(1, 1, true); |
| 123 builder.addFunction("geti", [kAstI32, kAstI32, kAstI32]) | 123 builder.addFunction("geti", [kAstI32, kAstI32, kAstI32]) |
| 124 .addBody([ | 124 .addBody([ |
| 125 kExprI32StoreMem, 0, kExprGetLocal, 0, kExprI32LoadMem, 0, kExprGetLocal,
1 | 125 kExprI32StoreMem, 0, 0, kExprGetLocal, 0, kExprI32LoadMem, 0, 0, kExprGetL
ocal, 1 |
| 126 ]) | 126 ]) |
| 127 .exportFunc(); | 127 .exportFunc(); |
| 128 | 128 |
| 129 var module = builder.instantiate(); | 129 var module = builder.instantiate(); |
| 130 | 130 |
| 131 var offset; | 131 var offset; |
| 132 | 132 |
| 133 function read() { return module.exports.geti(0, offset); } | 133 function read() { return module.exports.geti(0, offset); } |
| 134 function write() { return module.exports.geti(offset, 0); } | 134 function write() { return module.exports.geti(offset, 0); } |
| 135 | 135 |
| 136 for (offset = 0; offset < 65533; offset++) { | 136 for (offset = 0; offset < 65533; offset++) { |
| 137 assertEquals(0, read()); | 137 assertEquals(0, read()); |
| 138 assertEquals(0, write()); | 138 assertEquals(0, write()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 | 141 |
| 142 for (offset = 65534; offset < 66536; offset++) { | 142 for (offset = 65534; offset < 66536; offset++) { |
| 143 assertTraps(kTrapMemOutOfBounds, read); | 143 assertTraps(kTrapMemOutOfBounds, read); |
| 144 assertTraps(kTrapMemOutOfBounds, write); | 144 assertTraps(kTrapMemOutOfBounds, write); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 testOOBThrows(); | 148 testOOBThrows(); |
| OLD | NEW |