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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 assertEquals(offset * 2, load()); | 142 assertEquals(offset * 2, load()); |
143 } | 143 } |
144 for (offset = 5 * kPageSize; offset < 5 * kPageSize + 4; offset++) { | 144 for (offset = 5 * kPageSize; offset < 5 * kPageSize + 4; offset++) { |
145 assertThrows(load); | 145 assertThrows(load); |
146 } | 146 } |
147 assertThrows(() => memory.grow(1)); | 147 assertThrows(() => memory.grow(1)); |
148 })(); | 148 })(); |
149 | 149 |
150 (function TestGrowMemoryZeroInitialMemory() { | 150 (function TestGrowMemoryZeroInitialMemory() { |
151 print("ZeroInitialMemory"); | 151 print("ZeroInitialMemory"); |
| 152 let kV8MaxPages = 32767; |
152 let memory = new WebAssembly.Memory({initial: 0}); | 153 let memory = new WebAssembly.Memory({initial: 0}); |
153 assertEquals(0, memory.buffer.byteLength); | 154 assertEquals(0, memory.buffer.byteLength); |
154 let i32 = new Int32Array(memory.buffer); | 155 let i32 = new Int32Array(memory.buffer); |
155 let builder = new WasmModuleBuilder(); | 156 let builder = new WasmModuleBuilder(); |
156 builder.addImportedMemory("mine", "fro"); | 157 builder.addImportedMemory("mine", "fro"); |
157 builder.addFunction("load", kSig_i_i) | 158 builder.addFunction("load", kSig_i_i) |
158 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) | 159 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) |
159 .exportFunc(); | 160 .exportFunc(); |
160 builder.addFunction("store", kSig_i_ii) | 161 builder.addFunction("store", kSig_i_ii) |
161 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0, | 162 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0, |
162 kExprGetLocal, 1]) | 163 kExprGetLocal, 1]) |
163 .exportFunc(); | 164 .exportFunc(); |
164 var offset; | 165 var offset; |
165 let instance = builder.instantiate({mine: {fro: memory}}); | 166 let instance = builder.instantiate({mine: {fro: memory}}); |
166 function load() { return instance.exports.load(offset); } | 167 function load() { return instance.exports.load(offset); } |
167 function store(value) { return instance.exports.store(offset, value); } | 168 function store(value) { return instance.exports.store(offset, value); } |
168 | 169 |
169 for (var i = 1; i < 5; i++) { | 170 for (var i = 1; i < 5; i++) { |
170 assertEquals(i - 1, memory.grow(1)); | 171 assertEquals(i - 1, memory.grow(1)); |
171 assertEquals(i * kPageSize, memory.buffer.byteLength); | 172 assertEquals(i * kPageSize, memory.buffer.byteLength); |
172 for (offset = (i - 1) * kPageSize; offset < i * kPageSize - 3; offset++) { | 173 for (offset = (i - 1) * kPageSize; offset < i * kPageSize - 3; offset++) { |
173 store(offset * 2); | 174 store(offset * 2); |
174 } | 175 } |
175 } | 176 } |
176 for (offset = 5 * kPageSize; offset < 5 * kPageSize + 4; offset++) { | 177 for (offset = 5 * kPageSize; offset < 5 * kPageSize + 4; offset++) { |
177 assertThrows(load); | 178 assertThrows(load); |
178 } | 179 } |
179 assertThrows(() => memory.grow(16381)); | 180 assertThrows(() => memory.grow(kV8MaxPages - 3)); |
180 })(); | 181 })(); |
181 | 182 |
182 (function ImportedMemoryBufferLength() { | 183 (function ImportedMemoryBufferLength() { |
183 print("ImportedMemoryBufferLength"); | 184 print("ImportedMemoryBufferLength"); |
184 let memory = new WebAssembly.Memory({initial: 2, maximum: 10}); | 185 let memory = new WebAssembly.Memory({initial: 2, maximum: 10}); |
185 assertEquals(2*kPageSize, memory.buffer.byteLength); | 186 assertEquals(2*kPageSize, memory.buffer.byteLength); |
186 let builder = new WasmModuleBuilder(); | 187 let builder = new WasmModuleBuilder(); |
187 builder.addFunction("grow", kSig_i_i) | 188 builder.addFunction("grow", kSig_i_i) |
188 .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) | 189 .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) |
189 .exportFunc(); | 190 .exportFunc(); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 var builder = new WasmModuleBuilder(); | 405 var builder = new WasmModuleBuilder(); |
405 builder.addImportedMemory("m", "imported_mem"); | 406 builder.addImportedMemory("m", "imported_mem"); |
406 let instance = builder.instantiate({m: {imported_mem: memory}}); | 407 let instance = builder.instantiate({m: {imported_mem: memory}}); |
407 let buffer = memory.buffer; | 408 let buffer = memory.buffer; |
408 assertEquals(kPageSize, buffer.byteLength); | 409 assertEquals(kPageSize, buffer.byteLength); |
409 assertEquals(1, memory.grow(2)); | 410 assertEquals(1, memory.grow(2)); |
410 assertTrue(buffer !== memory.buffer); | 411 assertTrue(buffer !== memory.buffer); |
411 assertEquals(0, buffer.byteLength); | 412 assertEquals(0, buffer.byteLength); |
412 assertEquals(3*kPageSize, memory.buffer.byteLength); | 413 assertEquals(3*kPageSize, memory.buffer.byteLength); |
413 })(); | 414 })(); |
OLD | NEW |