| 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.addImportedMemory("", "memory", 1, 1); |
| 16 builder.exportMemoryAs("memory"); |
| 16 builder.addFunction("main", kSig_i_i) | 17 builder.addFunction("main", kSig_i_i) |
| 17 .addBody([ | 18 .addBody([ |
| 18 // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0; | 19 // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0; |
| 19 // TODO(titzer): this manual bytecode has a copy of test-run-wasm.cc | 20 // TODO(titzer): this manual bytecode has a copy of test-run-wasm.cc |
| 20 /**/ kExprLoop, kWasmStmt, // -- | 21 /**/ kExprLoop, kWasmStmt, // -- |
| 21 /* */ kExprGetLocal, 0, // -- | 22 /* */ kExprGetLocal, 0, // -- |
| 22 /* */ kExprIf, kWasmStmt, // -- | 23 /* */ kExprIf, kWasmStmt, // -- |
| 23 /* */ kExprGetLocal, 0, // -- | 24 /* */ kExprGetLocal, 0, // -- |
| 24 /* */ kExprI32LoadMem, 0, 0, // -- | 25 /* */ kExprI32LoadMem, 0, 0, // -- |
| 25 /* */ kExprIf, kWasmStmt, // -- | 26 /* */ kExprIf, kWasmStmt, // -- |
| 26 /* */ kExprI32Const, 127, // -- | 27 /* */ kExprI32Const, 127, // -- |
| 27 /* */ kExprReturn, // -- | 28 /* */ kExprReturn, // -- |
| 28 /* */ kExprEnd, // -- | 29 /* */ kExprEnd, // -- |
| 29 /* */ kExprGetLocal, 0, // -- | 30 /* */ kExprGetLocal, 0, // -- |
| 30 /* */ kExprI32Const, 4, // -- | 31 /* */ kExprI32Const, 4, // -- |
| 31 /* */ kExprI32Sub, // -- | 32 /* */ kExprI32Sub, // -- |
| 32 /* */ kExprSetLocal, 0, // -- | 33 /* */ kExprSetLocal, 0, // -- |
| 33 /* */ kExprBr, 1, // -- | 34 /* */ kExprBr, 1, // -- |
| 34 /* */ kExprEnd, // -- | 35 /* */ kExprEnd, // -- |
| 35 /* */ kExprEnd, // -- | 36 /* */ kExprEnd, // -- |
| 36 /**/ kExprI32Const, 0 // -- | 37 /**/ kExprI32Const, 0 // -- |
| 37 ]) | 38 ]) |
| 38 .exportFunc(); | 39 .exportFunc(); |
| 39 var module = builder.instantiate(null, memory); | 40 var module = builder.instantiate({"": {memory:memory}}); |
| 40 assertTrue(module.exports.memory instanceof WebAssembly.Memory); | 41 assertTrue(module.exports.memory instanceof WebAssembly.Memory); |
| 41 if (memory != null) assertEquals(memory.buffer, module.exports.memory.buffer); | 42 if (memory != null) assertEquals(memory.buffer, module.exports.memory.buffer); |
| 42 return module; | 43 return module; |
| 43 } | 44 } |
| 44 | 45 |
| 45 function testPokeMemory() { | 46 function testPokeMemory() { |
| 46 print("testPokeMemory"); | 47 print("testPokeMemory"); |
| 47 var module = genModule(null); | 48 var module = genModule(new WebAssembly.Memory({initial: 1})); |
| 48 var buffer = module.exports.memory.buffer; | 49 var buffer = module.exports.memory.buffer; |
| 49 var main = module.exports.main; | 50 var main = module.exports.main; |
| 50 assertEquals(kMemSize, buffer.byteLength); | 51 assertEquals(kMemSize, buffer.byteLength); |
| 51 | 52 |
| 52 var array = new Int8Array(buffer); | 53 var array = new Int8Array(buffer); |
| 53 assertEquals(kMemSize, array.length); | 54 assertEquals(kMemSize, array.length); |
| 54 | 55 |
| 55 for (var i = 0; i < kMemSize; i++) { | 56 for (var i = 0; i < kMemSize; i++) { |
| 56 assertEquals(0, array[i]); | 57 assertEquals(0, array[i]); |
| 57 } | 58 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 | 71 |
| 71 testPokeMemory(); | 72 testPokeMemory(); |
| 72 | 73 |
| 73 function genAndGetMain(buffer) { | 74 function genAndGetMain(buffer) { |
| 74 return genModule(buffer).exports.main; // to prevent intermediates living | 75 return genModule(buffer).exports.main; // to prevent intermediates living |
| 75 } | 76 } |
| 76 | 77 |
| 77 function testSurvivalAcrossGc() { | 78 function testSurvivalAcrossGc() { |
| 78 var checker = genAndGetMain(null); | 79 var checker = genAndGetMain(new WebAssembly.Memory({initial: 1})); |
| 79 for (var i = 0; i < 3; i++) { | 80 for (var i = 0; i < 3; i++) { |
| 80 print("gc run ", i); | 81 print("gc run ", i); |
| 81 assertEquals(0, checker(kMemSize - 4)); | 82 assertEquals(0, checker(kMemSize - 4)); |
| 82 gc(); | 83 gc(); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 testSurvivalAcrossGc(); | 87 testSurvivalAcrossGc(); |
| 87 testSurvivalAcrossGc(); | 88 testSurvivalAcrossGc(); |
| 88 testSurvivalAcrossGc(); | 89 testSurvivalAcrossGc(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 161 } |
| 161 | 162 |
| 162 | 163 |
| 163 for (offset = 65534; offset < 66536; offset++) { | 164 for (offset = 65534; offset < 66536; offset++) { |
| 164 assertTraps(kTrapMemOutOfBounds, read); | 165 assertTraps(kTrapMemOutOfBounds, read); |
| 165 assertTraps(kTrapMemOutOfBounds, write); | 166 assertTraps(kTrapMemOutOfBounds, write); |
| 166 } | 167 } |
| 167 } | 168 } |
| 168 | 169 |
| 169 testOOBThrows(); | 170 testOOBThrows(); |
| OLD | NEW |