OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --expose-wasm --stress-gc --expose-gc |
| 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 |
| 10 function run(f) { |
| 11 // wrap the creation in a closure so that the only thing returned is |
| 12 // the module (i.e. the underlying array buffer of WASM wire bytes dies). |
| 13 var module = (() => { |
| 14 var builder = new WasmModuleBuilder(); |
| 15 builder.addImport("the_name_of_my_import", kSig_i_i); |
| 16 builder.addFunction("main", kSig_i_i) |
| 17 .addBody([ |
| 18 kExprGetLocal, 0, |
| 19 kExprCallFunction, 0]) |
| 20 .exportAs("main"); |
| 21 print("module"); |
| 22 return new WebAssembly.Module(builder.toBuffer()); |
| 23 })(); |
| 24 |
| 25 gc(); |
| 26 for (var i = 0; i < 10; i++) { |
| 27 print(" instance " + i); |
| 28 var instance = new WebAssembly.Instance(module, {the_name_of_my_import: f}); |
| 29 var g = instance.exports.main; |
| 30 assertEquals("function", typeof g); |
| 31 for (var j = 0; j < 10; j++) { |
| 32 assertEquals(f(j), g(j)); |
| 33 } |
| 34 } |
| 35 } |
| 36 |
| 37 (function test() { |
| 38 for (var i = 0; i < 3; i++) { |
| 39 run(x => (x + 19)); |
| 40 run(x => (x - 18)); |
| 41 } |
| 42 })(); |
OLD | NEW |