* Represents a foreign function in another library. Manages all of the aspects * of function execution, including marshalling the data parameters for the * function into native types and also unmarshalling the return from function * execution.
(funcPtr, returnType, argTypes, abi)
| 17 | */ |
| 18 | |
| 19 | function ForeignFunction (funcPtr, returnType, argTypes, abi) { |
| 20 | debug('creating new ForeignFunction', funcPtr) |
| 21 | |
| 22 | // check args |
| 23 | assert(Buffer.isBuffer(funcPtr), 'expected Buffer as first argument') |
| 24 | assert(!!returnType, 'expected a return "type" object as the second argument') |
| 25 | assert(Array.isArray(argTypes), 'expected Array of arg "type" objects as the third argument') |
| 26 | |
| 27 | // normalize the "types" (they could be strings, |
| 28 | // so turn into real type instances) |
| 29 | returnType = ref.coerceType(returnType) |
| 30 | argTypes = argTypes.map(ref.coerceType) |
| 31 | |
| 32 | // create the `ffi_cif *` instance |
| 33 | var cif = CIF(returnType, argTypes, abi) |
| 34 | |
| 35 | // create and return the JS proxy function |
| 36 | return _ForeignFunction(cif, funcPtr, returnType, argTypes) |
| 37 | } |
| 38 | module.exports = ForeignFunction |
no test coverage detected