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 // 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 var module = (function () { | 10 var module = (function () { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 builder.appendToTable([0, 1, 2, 3]); | 77 builder.appendToTable([0, 1, 2, 3]); |
| 78 | 78 |
| 79 return builder.instantiate({mul: function(a, b) { return a * b | 0; }}); | 79 return builder.instantiate({mul: function(a, b) { return a * b | 0; }}); |
| 80 })(); | 80 })(); |
| 81 | 81 |
| 82 assertEquals(-6, module.exports.main(0, -2, 3)); | 82 assertEquals(-6, module.exports.main(0, -2, 3)); |
| 83 assertEquals(99, module.exports.main(1, 22, 77)); | 83 assertEquals(99, module.exports.main(1, 22, 77)); |
| 84 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)"); | 84 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)"); |
| 85 assertTraps(kTrapFuncSigMismatch, "module.exports.main(3, 12, 33)"); | 85 assertTraps(kTrapFuncSigMismatch, "module.exports.main(3, 12, 33)"); |
| 86 assertTraps(kTrapFuncInvalid, "module.exports.main(4, 12, 33)"); | 86 assertTraps(kTrapFuncInvalid, "module.exports.main(4, 12, 33)"); |
| 87 | |
| 88 | |
| 89 module = (function () { | |
| 90 var builder = new WasmModuleBuilder(); | |
| 91 | |
| 92 builder.addFunction("mul", kSig_i_ii) | |
| 93 .addBody([ | |
| 94 kExprGetLocal, 0, // -- | |
| 95 kExprGetLocal, 1, // -- | |
| 96 kExprI32Mul // -- | |
| 97 ]); | |
| 98 builder.addFunction("add", kSig_i_ii) | |
| 99 .addBody([ | |
| 100 kExprGetLocal, 0, // -- | |
| 101 kExprGetLocal, 1, // -- | |
| 102 kExprI32Add // -- | |
| 103 ]); | |
| 104 builder.addFunction("sub", kSig_i_ii) | |
| 105 .addBody([ | |
| 106 kExprGetLocal, 0, // -- | |
| 107 kExprGetLocal, 1, // -- | |
| 108 kExprI32Sub // -- | |
| 109 ]); | |
| 110 builder.addFunction("main", kSig_i_ii) | |
| 111 .addBody([ | |
| 112 kExprI32Const, 33, // -- | |
| 113 kExprGetLocal, 0, // -- | |
| 114 kExprGetLocal, 1, // -- | |
| 115 kExprCallIndirect, 0]) // -- | |
| 116 .exportAs("main"); | |
| 117 | |
| 118 builder.appendToTable([0, 1, 2]); | |
| 119 | |
| 120 return builder.instantiate(); | |
| 121 })(); | |
| 122 | |
| 123 assertEquals(33, module.exports.main(1, 0)); | |
|
ahaas
2016/10/11 09:20:09
Could you use function index created by builder.ad
titzer
2016/10/11 11:58:31
Done.
| |
| 124 assertEquals(66, module.exports.main(2, 0)); | |
| 125 assertEquals(34, module.exports.main(1, 1)); | |
| 126 assertEquals(35, module.exports.main(2, 1)); | |
| 127 assertEquals(32, module.exports.main(1, 2)); | |
| 128 assertEquals(31, module.exports.main(2, 2)); | |
| 129 assertTraps(kTrapFuncInvalid, "module.exports.main(12, 3)"); | |
| OLD | NEW |