Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // | |
|
bradn
2016/06/16 08:00:20
Extra line.
Separate file?
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 4 | 5 |
| 5 // Flags: --expose-wasm | 6 // Flags: --expose-wasm |
| 7 // Flags: --wasm-jit-prototpe | |
| 6 | 8 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | 9 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 10 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 | 11 |
| 10 var module = (function () { | 12 var module = (function () { |
| 11 var builder = new WasmModuleBuilder(); | 13 var builder = new WasmModuleBuilder(); |
| 12 | 14 |
| 13 var sig_index = builder.addSignature(kSig_i_ii); | 15 var sig_index = builder.addSignature(kSig_i_ii); |
| 14 builder.addImport("add", sig_index); | 16 builder.addImport("add", sig_index); |
| 15 builder.addFunction("add", sig_index) | 17 builder.addFunction("add", sig_index) |
| 16 .addBody([ | 18 .addBody([ |
| 17 kExprGetLocal, 0, kExprGetLocal, 1, kExprCallImport, kArity2, 0 | 19 kExprGetLocal, 0, kExprGetLocal, 1, kExprCallImport, kArity2, 0 |
| 18 ]); | 20 ]); |
| 19 builder.addFunction("sub", sig_index) | 21 builder.addFunction("sub", sig_index) |
| 20 .addBody([ | 22 .addBody([ |
| 21 kExprGetLocal, 0, // -- | 23 kExprGetLocal, 0, // -- |
| 22 kExprGetLocal, 1, // -- | 24 kExprGetLocal, 1, // -- |
| 23 kExprI32Sub, // -- | 25 kExprI32Sub, // -- |
| 24 ]); | 26 ]); |
| 27 builder.appendToFunctionTable([0, 1]); | |
| 28 for (var i = 0; i < 2000; i++) { | |
| 29 builder.addFunction("sub".concat(i.toString()), sig_index) | |
| 30 .addBody([ | |
| 31 kExprGetLocal, 0, | |
| 32 kExprGetLocal, 1, | |
| 33 kExprI32Sub, | |
| 34 ]); | |
| 35 builder.appendToFunctionTable([i + 2]); | |
| 36 } | |
| 25 builder.addFunction("main", kSig_i_iii) | 37 builder.addFunction("main", kSig_i_iii) |
| 26 .addBody([ | 38 .addBody([ |
| 27 kExprGetLocal, 0, | 39 kExprGetLocal, 0, |
| 28 kExprGetLocal, 1, | 40 kExprGetLocal, 1, |
| 29 kExprGetLocal, 2, | 41 kExprGetLocal, 2, |
| 30 kExprCallIndirect, kArity2, sig_index | 42 kExprCallIndirect, kArity2, sig_index |
| 31 ]) | 43 ]) |
| 32 .exportFunc() | 44 .exportFunc() |
| 33 builder.appendToFunctionTable([0, 1, 2]); | 45 builder.appendToFunctionTable([2002]); |
| 34 | 46 |
| 35 return builder.instantiate({add: function(a, b) { return a + b | 0; }}); | 47 return builder.instantiate({add: function(a, b) { return a + b | 0; }}); |
| 36 })(); | 48 })(); |
| 37 | 49 |
| 38 // Check the module exists. | 50 // Check the module exists. |
| 39 assertFalse(module === undefined); | 51 assertFalse(module === undefined); |
| 40 assertFalse(module === null); | 52 assertFalse(module === null); |
| 41 assertFalse(module === 0); | 53 assertFalse(module === 0); |
| 42 assertEquals("object", typeof module.exports); | 54 assertEquals("object", typeof module.exports); |
| 43 assertEquals("function", typeof module.exports.main); | 55 assertEquals("function", typeof module.exports.main); |
| 44 | 56 |
| 45 assertEquals(5, module.exports.main(1, 12, 7)); | 57 assertEquals(5, module.exports.main(1, 12, 7)); |
| 46 assertEquals(19, module.exports.main(0, 12, 7)); | 58 assertEquals(19, module.exports.main(0, 12, 7)); |
| 47 | 59 |
| 48 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)"); | 60 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2002, 12, 33)"); |
| 49 assertTraps(kTrapFuncInvalid, "module.exports.main(3, 12, 33)"); | 61 assertTraps(kTrapFuncInvalid, "module.exports.main(-1, 12, 33)"); |
| 62 assertTraps(kTrapFuncInvalid, "module.exports.main(2003, 12, 33)"); | |
| 63 assertTraps(kTrapFuncInvalid, "module.exports.main(4005, 12, 33)"); | |
| 64 assertTraps(kTrapFuncInvalid, "module.exports.main(4006, 12, 33)"); | |
| 65 assertTraps(kTrapFuncInvalid, "module.exports.main(4004, 12, 33)"); | |
| 66 assertTraps(kTrapFuncInvalid, "module.exports.main(100000, 12, 33)"); | |
| OLD | NEW |