| 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 function testCallImport(func, check) { | 10 function testCallImport(func, check) { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 kExprI8Const, 97, // -- | 248 kExprI8Const, 97, // -- |
| 249 kExprCallFunction, 0, // -- | 249 kExprCallFunction, 0, // -- |
| 250 kExprGetLocal, 0, // -- | 250 kExprGetLocal, 0, // -- |
| 251 kExprCallFunction, 1 // -- | 251 kExprCallFunction, 1 // -- |
| 252 ]) | 252 ]) |
| 253 .exportFunc(); | 253 .exportFunc(); |
| 254 | 254 |
| 255 var main = builder.instantiate({print: print}).exports.main; | 255 var main = builder.instantiate({print: print}).exports.main; |
| 256 | 256 |
| 257 for (var i = -9; i < 900; i += 16.125) { | 257 for (var i = -9; i < 900; i += 16.125) { |
| 258 main(i); | 258 main(i); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 testCallPrint(); | 262 testCallPrint(); |
| 263 testCallPrint(); | 263 testCallPrint(); |
| 264 | 264 |
| 265 | 265 |
| 266 function testCallImport2(foo, bar, expected) { | 266 function testCallImport2(foo, bar, expected) { |
| 267 var builder = new WasmModuleBuilder(); | 267 var builder = new WasmModuleBuilder(); |
| 268 | 268 |
| 269 builder.addImport("foo", kSig_i_v); | 269 builder.addImport("foo", kSig_i_v); |
| 270 builder.addImport("bar", kSig_i_v); | 270 builder.addImport("bar", kSig_i_v); |
| 271 builder.addFunction("main", kSig_i_v) | 271 builder.addFunction("main", kSig_i_v) |
| 272 .addBody([ | 272 .addBody([ |
| 273 kExprCallFunction, 0, // -- | 273 kExprCallFunction, 0, // -- |
| 274 kExprCallFunction, 1, // -- | 274 kExprCallFunction, 1, // -- |
| 275 kExprI32Add, // -- | 275 kExprI32Add, // -- |
| 276 ]) // -- | 276 ]) // -- |
| 277 .exportFunc(); | 277 .exportFunc(); |
| 278 | 278 |
| 279 var main = builder.instantiate({foo: foo, bar: bar}).exports.main; | 279 var main = builder.instantiate({foo: foo, bar: bar}).exports.main; |
| 280 assertEquals(expected, main()); | 280 assertEquals(expected, main()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 testCallImport2(function() { return 33; }, function () { return 44; }, 77); | 283 testCallImport2(function() { return 33; }, function () { return 44; }, 77); |
| 284 |
| 285 |
| 286 function testImportName(name) { |
| 287 var builder = new WasmModuleBuilder(); |
| 288 builder.addImportWithModule("M", name, kSig_i_v); |
| 289 builder.addFunction("main", kSig_i_v) |
| 290 .addBody([ |
| 291 kExprCallFunction, 0 |
| 292 ]) |
| 293 .exportFunc(); |
| 294 |
| 295 let main = builder.instantiate({M: {[name]: () => 42}}).exports.main; |
| 296 assertEquals(42, main()); |
| 297 } |
| 298 |
| 299 testImportName("bla"); |
| 300 testImportName("0"); |
| 301 testImportName(" a @#$2 324 "); |
| 302 // TODO(bradnelson): This should succeed. |
| 303 // testImportName(""); |
| OLD | NEW |