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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 writer: (x)=>outval_2 = x }, mem_2); | 148 writer: (x)=>outval_2 = x }, mem_2); |
149 | 149 |
150 assertEquals(43, i1.exports.main(0)); | 150 assertEquals(43, i1.exports.main(0)); |
151 assertEquals(1002, i2.exports.main(0)); | 151 assertEquals(1002, i2.exports.main(0)); |
152 | 152 |
153 assertEquals(42, outval_1); | 153 assertEquals(42, outval_1); |
154 assertEquals(1000, outval_2); | 154 assertEquals(1000, outval_2); |
155 })(); | 155 })(); |
156 | 156 |
157 (function GlobalsArePrivateToTheInstance() { | 157 (function GlobalsArePrivateToTheInstance() { |
158 var builder = new WasmModuleBuilder(); | 158 var builder = new WasmModuleBuilder(); |
159 builder.addGlobal(kAstI32); | 159 builder.addGlobal(kAstI32); |
160 builder.addFunction("read", kSig_i_v) | 160 builder.addFunction("read", kSig_i_v) |
161 .addBody([ | 161 .addBody([ |
162 kExprGetGlobal, 0]) | 162 kExprGetGlobal, 0]) |
163 .exportFunc(); | 163 .exportFunc(); |
164 | 164 |
165 builder.addFunction("write", kSig_v_i) | 165 builder.addFunction("write", kSig_v_i) |
166 .addBody([ | |
167 kExprGetLocal, 0, | |
168 kExprSetGlobal, 0]) | |
169 .exportFunc(); | |
170 | |
171 var module = new WebAssembly.Module(builder.toBuffer()); | |
172 var i1 = new WebAssembly.Instance(module); | |
173 var i2 = new WebAssembly.Instance(module); | |
174 i1.exports.write(1); | |
175 i2.exports.write(2); | |
176 assertEquals(1, i1.exports.read()); | |
177 assertEquals(2, i2.exports.read()); | |
178 })(); | |
179 | |
180 | |
181 (function InstanceMemoryIsIsolated() { | |
182 var builder = new WasmModuleBuilder(); | |
183 builder.addMemory(1,1, true); | |
184 | |
185 builder.addFunction("f", kSig_i) | |
186 .addBody([ | 166 .addBody([ |
187 kExprI32Const, 0, | 167 kExprGetLocal, 0, |
188 kExprI32LoadMem, 0, 0 | 168 kExprSetGlobal, 0]) |
189 ]).exportFunc(); | 169 .exportFunc(); |
190 | |
191 var mem_1 = new ArrayBuffer(65536); | |
192 var mem_2 = new ArrayBuffer(65536); | |
193 var view_1 = new Int32Array(mem_1); | |
194 var view_2 = new Int32Array(mem_2); | |
195 view_1[0] = 1; | |
196 view_2[0] = 1000; | |
197 | 170 |
198 var module = new WebAssembly.Module(builder.toBuffer()); | 171 var module = new WebAssembly.Module(builder.toBuffer()); |
199 var i1 = new WebAssembly.Instance(module, null, mem_1); | 172 var i1 = new WebAssembly.Instance(module); |
200 var i2 = new WebAssembly.Instance(module, null, mem_2); | 173 var i2 = new WebAssembly.Instance(module); |
201 | 174 i1.exports.write(1); |
202 assertEquals(1, i1.exports.f()); | 175 i2.exports.write(2); |
203 assertEquals(1000, i2.exports.f()); | 176 assertEquals(1, i1.exports.read()); |
| 177 assertEquals(2, i2.exports.read()); |
204 })(); | 178 })(); |
OLD | NEW |