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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 var f = AddFunctions(builder); | 178 var f = AddFunctions(builder); |
179 builder.addFunction("main", kSig_i_ii) | 179 builder.addFunction("main", kSig_i_ii) |
180 .addBody([ | 180 .addBody([ |
181 kExprI32Const, 33, // -- | 181 kExprI32Const, 33, // -- |
182 kExprGetLocal, 0, // -- | 182 kExprGetLocal, 0, // -- |
183 kExprGetLocal, 1, // -- | 183 kExprGetLocal, 1, // -- |
184 kExprCallIndirect, 0, kTableZero]) // -- | 184 kExprCallIndirect, 0, kTableZero]) // -- |
185 .exportAs("main"); | 185 .exportAs("main"); |
186 | 186 |
187 builder.setFunctionTableLength(10); | 187 builder.setFunctionTableLength(10); |
188 var g = builder.addImportedGlobal("fff", "base", kAstI32); | 188 var g = builder.addImportedGlobal("fff", "base", kWasmI32); |
189 builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, f.sub.index])
; | 189 builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, f.sub.index])
; |
190 | 190 |
191 var module = new WebAssembly.Module(builder.toBuffer()); | 191 var module = new WebAssembly.Module(builder.toBuffer()); |
192 | 192 |
193 for (var i = 0; i < 5; i++) { | 193 for (var i = 0; i < 5; i++) { |
194 print(" base = " + i); | 194 print(" base = " + i); |
195 var instance = new WebAssembly.Instance(module, {fff: {base: i}}); | 195 var instance = new WebAssembly.Instance(module, {fff: {base: i}}); |
196 main = instance.exports.main; | 196 main = instance.exports.main; |
197 for (var j = 0; j < i; j++) { | 197 for (var j = 0; j < i; j++) { |
198 assertTraps(kTrapFuncSigMismatch, "main(12, " + j + ")"); | 198 assertTraps(kTrapFuncSigMismatch, "main(12, " + j + ")"); |
199 } | 199 } |
200 assertEquals(33, main(1, i + 0)); | 200 assertEquals(33, main(1, i + 0)); |
201 assertEquals(66, main(2, i + 0)); | 201 assertEquals(66, main(2, i + 0)); |
202 assertEquals(34, main(1, i + 1)); | 202 assertEquals(34, main(1, i + 1)); |
203 assertEquals(35, main(2, i + 1)); | 203 assertEquals(35, main(2, i + 1)); |
204 assertEquals(32, main(1, i + 2)); | 204 assertEquals(32, main(1, i + 2)); |
205 assertEquals(31, main(2, i + 2)); | 205 assertEquals(31, main(2, i + 2)); |
206 assertTraps(kTrapFuncInvalid, "main(12, 10)"); | 206 assertTraps(kTrapFuncInvalid, "main(12, 10)"); |
207 } | 207 } |
208 })(); | 208 })(); |
OLD | NEW |