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 |
| 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 |
| 10 function testCallImport(func, expected, a, b) { |
| 11 var builder = new WasmModuleBuilder(); |
| 12 |
| 13 var sig_index = builder.addType(kSig_i_dd); |
| 14 builder.addImport("func", sig_index); |
| 15 builder.addFunction("main", sig_index) |
| 16 .addBody([ |
| 17 kExprGetLocal, 0, // -- |
| 18 kExprGetLocal, 1, // -- |
| 19 kExprCallImport, 2, 0]) // -- |
| 20 .exportAs("main"); |
| 21 |
| 22 var main = builder.instantiate({func: func}).exports.main; |
| 23 |
| 24 assertEquals(expected, main(a, b)); |
| 25 } |
| 26 |
| 27 var global = (function() { return this; })(); |
| 28 |
| 29 function sloppyReceiver(a, b) { |
| 30 assertEquals(global, this); |
| 31 assertEquals(33.3, a); |
| 32 assertEquals(44.4, b); |
| 33 return 11; |
| 34 } |
| 35 |
| 36 function strictReceiver(a, b) { |
| 37 'use strict'; |
| 38 assertEquals(undefined, this); |
| 39 assertEquals(55.5, a); |
| 40 assertEquals(66.6, b); |
| 41 return 22; |
| 42 } |
| 43 |
| 44 testCallImport(sloppyReceiver, 11, 33.3, 44.4); |
| 45 testCallImport(strictReceiver, 22, 55.5, 66.6); |
OLD | NEW |