OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 load("test/mjsunit/wasm/wasm-constants.js"); |
| 6 |
| 7 function testCallFFI(ffi) { |
| 8 var kBodySize = 6; |
| 9 var kNameAddOffset = 28 + kBodySize + 1; |
| 10 var kNameMainOffset = kNameAddOffset + 4; |
| 11 |
| 12 var data = bytes( |
| 13 kDeclMemory, |
| 14 12, 12, 1, // memory |
| 15 // -- signatures |
| 16 kDeclSignatures, 1, |
| 17 2, kAstI32, kAstF64, kAstF64, // (f64,f64)->int |
| 18 // -- foreign function |
| 19 kDeclFunctions, 2, |
| 20 kDeclFunctionName | kDeclFunctionImport, |
| 21 0, 0, // signature index |
| 22 kNameAddOffset, 0, 0, 0, // name offset |
| 23 // -- main function |
| 24 kDeclFunctionName | kDeclFunctionExport, |
| 25 0, 0, // signature index |
| 26 kNameMainOffset, 0, 0, 0, // name offset |
| 27 kBodySize, 0, |
| 28 // main body |
| 29 kExprCallFunction, 0, // -- |
| 30 kExprGetLocal, 0, // -- |
| 31 kExprGetLocal, 1, // -- |
| 32 // names |
| 33 kDeclEnd, |
| 34 'f', 'u', 'n', 0, // -- |
| 35 'm', 'a', 'i', 'n', 0 // -- |
| 36 ); |
| 37 |
| 38 print("instantiate FFI"); |
| 39 var module = WASM.instantiateModule(data, ffi); |
| 40 } |
| 41 |
| 42 // everything is good. |
| 43 (function() { |
| 44 var ffi = new Object(); |
| 45 ffi.fun = function(a, b) { print(a, b); } |
| 46 testCallFFI(ffi); |
| 47 })(); |
| 48 |
| 49 |
| 50 // FFI object should be an object. |
| 51 assertThrows(function() { |
| 52 var ffi = 0; |
| 53 testCallFFI(ffi); |
| 54 }); |
| 55 |
| 56 |
| 57 // FFI object should have a "fun" property. |
| 58 assertThrows(function() { |
| 59 var ffi = new Object(); |
| 60 testCallFFI(ffi); |
| 61 }); |
| 62 |
| 63 |
| 64 // "fun" should be a JS function. |
| 65 assertThrows(function() { |
| 66 var ffi = new Object(); |
| 67 ffi.fun = new Object(); |
| 68 testCallFFI(ffi); |
| 69 }); |
| 70 |
| 71 |
| 72 // "fun" should be a JS function. |
| 73 assertThrows(function() { |
| 74 var ffi = new Object(); |
| 75 ffi.fun = 0; |
| 76 testCallFFI(ffi); |
| 77 }); |
OLD | NEW |