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 | 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 let kReturnValue = 117; | 10 let kReturnValue = 117; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // writer(mem[i]); | 134 // writer(mem[i]); |
135 // return mem[i] + some_value(); | 135 // return mem[i] + some_value(); |
136 builder.addFunction("_wrap_writer", signature) | 136 builder.addFunction("_wrap_writer", signature) |
137 .addBody([ | 137 .addBody([ |
138 kExprGetLocal, 0, | 138 kExprGetLocal, 0, |
139 kExprCallFunction, 1]); | 139 kExprCallFunction, 1]); |
140 builder.appendToTable([2, 3]); | 140 builder.appendToTable([2, 3]); |
141 | 141 |
142 | 142 |
143 var module = new WebAssembly.Module(builder.toBuffer()); | 143 var module = new WebAssembly.Module(builder.toBuffer()); |
144 var mem_1 = new ArrayBuffer(4); | 144 var mem_1 = new WebAssembly.Memory({initial: 1}); |
145 var mem_2 = new ArrayBuffer(4); | 145 var mem_2 = new WebAssembly.Memory({initial: 1}); |
146 var view_1 = new Int32Array(mem_1); | 146 var view_1 = new Int32Array(mem_1.buffer); |
147 var view_2 = new Int32Array(mem_2); | 147 var view_2 = new Int32Array(mem_2.buffer); |
148 | 148 |
149 view_1[0] = 42; | 149 view_1[0] = 42; |
150 view_2[0] = 1000; | 150 view_2[0] = 1000; |
151 | 151 |
152 var outval_1; | 152 var outval_1; |
153 var outval_2; | 153 var outval_2; |
154 var i1 = new WebAssembly.Instance(module, {some_value: () => 1, | 154 var i1 = new WebAssembly.Instance(module, {some_value: () => 1, |
155 writer: (x)=>outval_1 = x }, mem_1); | 155 writer: (x)=>outval_1 = x }, mem_1); |
156 var i2 = new WebAssembly.Instance(module, {some_value: () => 2, | 156 var i2 = new WebAssembly.Instance(module, {some_value: () => 2, |
157 writer: (x)=>outval_2 = x }, mem_2); | 157 writer: (x)=>outval_2 = x }, mem_2); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 print("InstanceMemoryIsIsolated..."); | 192 print("InstanceMemoryIsIsolated..."); |
193 var builder = new WasmModuleBuilder(); | 193 var builder = new WasmModuleBuilder(); |
194 builder.addMemory(1,1, true); | 194 builder.addMemory(1,1, true); |
195 | 195 |
196 builder.addFunction("f", kSig_i_v) | 196 builder.addFunction("f", kSig_i_v) |
197 .addBody([ | 197 .addBody([ |
198 kExprI32Const, 0, | 198 kExprI32Const, 0, |
199 kExprI32LoadMem, 0, 0 | 199 kExprI32LoadMem, 0, 0 |
200 ]).exportFunc(); | 200 ]).exportFunc(); |
201 | 201 |
202 var mem_1 = new ArrayBuffer(65536); | 202 var mem_1 = new WebAssembly.Memory({initial: 1}); |
203 var mem_2 = new ArrayBuffer(65536); | 203 var mem_2 = new WebAssembly.Memory({initial: 1}); |
204 var view_1 = new Int32Array(mem_1); | 204 var view_1 = new Int32Array(mem_1.buffer); |
205 var view_2 = new Int32Array(mem_2); | 205 var view_2 = new Int32Array(mem_2.buffer); |
206 view_1[0] = 1; | 206 view_1[0] = 1; |
207 view_2[0] = 1000; | 207 view_2[0] = 1000; |
208 | 208 |
209 var module = new WebAssembly.Module(builder.toBuffer()); | 209 var module = new WebAssembly.Module(builder.toBuffer()); |
210 var i1 = new WebAssembly.Instance(module, null, mem_1); | 210 var i1 = new WebAssembly.Instance(module, null, mem_1); |
211 var i2 = new WebAssembly.Instance(module, null, mem_2); | 211 var i2 = new WebAssembly.Instance(module, null, mem_2); |
212 | 212 |
213 assertEquals(1, i1.exports.f()); | 213 assertEquals(1, i1.exports.f()); |
214 assertEquals(1000, i2.exports.f()); | 214 assertEquals(1000, i2.exports.f()); |
215 })(); | 215 })(); |
| 216 |
| 217 (function MustBeMemory() { |
| 218 var memory = new ArrayBuffer(65536); |
| 219 var module = new WebAssembly.Module(buffer); |
| 220 assertThrows(() => new WebAssembly.Instance(module, null, memory), TypeError); |
| 221 })(); |
OLD | NEW |