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 | 5 // Flags: --expose-wasm |
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 (function TestOne() { | 10 (function TestOne() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 for (var i = 0; i < 1e11; i = i * 3 + 5) { | 74 for (var i = 0; i < 1e11; i = i * 3 + 5) { |
75 for (var j = 0; j < 10; j++) { | 75 for (var j = 0; j < 10; j++) { |
76 var val = i + 99077 + j; | 76 var val = i + 99077 + j; |
77 i32[j] = val; | 77 i32[j] = val; |
78 assertEquals(val | 0, i1.exports.foo(j * 4)); | 78 assertEquals(val | 0, i1.exports.foo(j * 4)); |
79 assertEquals(val | 0, i2.exports.bar(j * 4)); | 79 assertEquals(val | 0, i2.exports.bar(j * 4)); |
80 } | 80 } |
81 } | 81 } |
82 })(); | 82 })(); |
| 83 |
| 84 (function ValidateBoundsCheck() { |
| 85 print("Validate bounds check"); |
| 86 let memory = new WebAssembly.Memory({initial: 1, maximum: 5}); |
| 87 assertEquals(kPageSize, memory.buffer.byteLength); |
| 88 let i32 = new Int32Array(memory.buffer); |
| 89 let builder = new WasmModuleBuilder(); |
| 90 // builder.addImportedMemory("mine"); |
| 91 builder.addImportedMemory("mine"); |
| 92 builder.addFunction("load", kSig_i_i) |
| 93 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) |
| 94 .exportFunc(); |
| 95 builder.addFunction("store", kSig_i_ii) |
| 96 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0, |
| 97 kExprGetLocal, 1]) |
| 98 .exportFunc(); |
| 99 var offset; |
| 100 let instance = builder.instantiate({mine: memory}); |
| 101 function load() { return instance.exports.load(offset); } |
| 102 function store(value) { return instance.exports.store(offset, value); } |
| 103 |
| 104 for (offset = 0; offset < kPageSize -3; offset+=4) { |
| 105 store(offset); |
| 106 } |
| 107 for (offset = 0; offset < kPageSize - 3; offset+=4) { |
| 108 assertEquals(offset, load()); |
| 109 } |
| 110 for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) { |
| 111 assertTraps(kTrapMemOutOfBounds, load); |
| 112 } |
| 113 })(); |
OLD | NEW |