OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 kPageSize = 0x10000; | 10 var kPageSize = 0x10000; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 319 |
320 val = 0; | 320 val = 0; |
321 | 321 |
322 for(offset = 0; offset <= (kPageSize - 1); offset++, val++) { | 322 for(offset = 0; offset <= (kPageSize - 1); offset++, val++) { |
323 assertEquals(val, peek()); | 323 assertEquals(val, peek()); |
324 if (val == 255) val = 0; | 324 if (val == 255) val = 0; |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 testGrowMemoryPreservesDataMemOp8(); | 328 testGrowMemoryPreservesDataMemOp8(); |
| 329 |
| 330 function testGrowMemoryOutOfBoundsOffset() { |
| 331 var builder = genGrowMemoryBuilder(); |
| 332 builder.addMemory(1, 1, false); |
| 333 var module = builder.instantiate(); |
| 334 var offset, val; |
| 335 function peek() { return module.exports.load(offset); } |
| 336 function poke(value) { return module.exports.store(offset, value); } |
| 337 function growMem(pages) { return module.exports.grow_memory(pages); } |
| 338 |
| 339 offset = 3*kPageSize + 4; |
| 340 assertTraps(kTrapMemOutOfBounds, poke); |
| 341 |
| 342 assertEquals(1, growMem(1)); |
| 343 assertTraps(kTrapMemOutOfBounds, poke); |
| 344 |
| 345 assertEquals(2, growMem(1)); |
| 346 assertTraps(kTrapMemOutOfBounds, poke); |
| 347 |
| 348 assertEquals(3, growMem(1)); |
| 349 |
| 350 for (offset = 3*kPageSize; offset <= 4*kPageSize - 4; offset++) { |
| 351 poke(0xaced); |
| 352 assertEquals(0xaced, peek()); |
| 353 } |
| 354 |
| 355 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) { |
| 356 assertTraps(kTrapMemOutOfBounds, poke); |
| 357 } |
| 358 } |
| 359 |
| 360 testGrowMemoryOutOfBoundsOffset(); |
OLD | NEW |