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(); |
| 159 builder.addGlobal(kAstI32); |
| 160 builder.addFunction("read", kSig_i_v) |
| 161 .addBody([ |
| 162 kExprGetGlobal, 0]) |
| 163 .exportFunc(); |
| 164 |
| 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() { |
158 var builder = new WasmModuleBuilder(); | 182 var builder = new WasmModuleBuilder(); |
159 builder.addGlobal(kAstI32); | 183 builder.addMemory(1,1, true); |
160 builder.addFunction("read", kSig_i_v) | 184 |
| 185 builder.addFunction("f", kSig_i) |
161 .addBody([ | 186 .addBody([ |
162 kExprGetGlobal, 0]) | 187 kExprI32Const, 0, |
163 .exportFunc(); | 188 kExprI32LoadMem, 0, 0 |
| 189 ]).exportFunc(); |
164 | 190 |
165 builder.addFunction("write", kSig_v_i) | 191 var mem_1 = new ArrayBuffer(65536); |
166 .addBody([ | 192 var mem_2 = new ArrayBuffer(65536); |
167 kExprGetLocal, 0, | 193 var view_1 = new Int32Array(mem_1); |
168 kExprSetGlobal, 0]) | 194 var view_2 = new Int32Array(mem_2); |
169 .exportFunc(); | 195 view_1[0] = 1; |
| 196 view_2[0] = 1000; |
170 | 197 |
171 var module = new WebAssembly.Module(builder.toBuffer()); | 198 var module = new WebAssembly.Module(builder.toBuffer()); |
172 var i1 = new WebAssembly.Instance(module); | 199 var i1 = new WebAssembly.Instance(module, null, mem_1); |
173 var i2 = new WebAssembly.Instance(module); | 200 var i2 = new WebAssembly.Instance(module, null, mem_2); |
174 i1.exports.write(1); | 201 |
175 i2.exports.write(2); | 202 assertEquals(1, i1.exports.f()); |
176 assertEquals(1, i1.exports.read()); | 203 assertEquals(1000, i2.exports.f()); |
177 assertEquals(2, i2.exports.read()); | |
178 })(); | 204 })(); |
OLD | NEW |