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 --stress-gc | 5 // Flags: --expose-wasm --stress-gc |
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 run(f) { | 10 function run(f) { |
11 var builder = new WasmModuleBuilder(); | 11 var builder = new WasmModuleBuilder(); |
12 builder.addImport("f", kSig_i_i); | 12 builder.addImport("m", "f", kSig_i_i); |
13 builder.addFunction("main", kSig_i_i) | 13 builder.addFunction("main", kSig_i_i) |
14 .addBody([ | 14 .addBody([ |
15 kExprGetLocal, 0, | 15 kExprGetLocal, 0, |
16 kExprCallFunction, 0]) | 16 kExprCallFunction, 0]) |
17 .exportAs("main"); | 17 .exportAs("main"); |
18 | 18 |
19 print("module"); | 19 print("module"); |
20 var module = new WebAssembly.Module(builder.toBuffer()); | 20 var module = new WebAssembly.Module(builder.toBuffer()); |
21 | 21 |
22 for (var i = 0; i < 10; i++) { | 22 for (var i = 0; i < 10; i++) { |
23 print(" instance " + i); | 23 print(" instance " + i); |
24 var instance = new WebAssembly.Instance(module, {f: f}); | 24 var instance = new WebAssembly.Instance(module, {m: {f: f}}); |
25 var g = instance.exports.main; | 25 var g = instance.exports.main; |
26 for (var j = 0; j < 10; j++) { | 26 for (var j = 0; j < 10; j++) { |
27 assertEquals(f(j), g(j)); | 27 assertEquals(f(j), g(j)); |
28 } | 28 } |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 (function test() { | 32 (function test() { |
33 for (var i = 0; i < 100; i++) { | 33 for (var i = 0; i < 100; i++) { |
34 run(x => (x + 19)); | 34 run(x => (x + 19)); |
35 run(x => (x - 18)); | 35 run(x => (x - 18)); |
36 } | 36 } |
37 })(); | 37 })(); |
OLD | NEW |