lib/_foreign_function.js
function () {
    debug('invoking proxy function');

    if (arguments.length !== numArgs) {
      throw new TypeError('Expected ' + numArgs +
          ' arguments, got ' + arguments.length);
    }

    // storage buffers for input arguments and the return value
    const result = Buffer.alloc(resultSize);
    const argsList = Buffer.alloc(argsArraySize);

    // write arguments to storage areas
    let i;
    try {
      for (i = 0; i < numArgs; i++) {
        const argType = argTypes[i];
        const val = arguments[i];
        const valPtr = ref.alloc(argType, val);
        argsList.writePointer(valPtr, i * POINTER_SIZE);
      }
    } catch (e) {
      // counting arguments from 1 is more human readable
      i++;
      e.message = 'error setting argument ' + i + ' - ' + e.message;
      throw e;
    }

    // invoke the `ffi_call()` function
    bindings.ffi_call(cif, funcPtr, result, argsList);

    result.type = returnType;
    return result.deref();
  }
function () {
    debug('invoking proxy function');

    if (arguments.length !== numArgs) {
      throw new TypeError('Expected ' + numArgs +
          ' arguments, got ' + arguments.length);
    }

    // storage buffers for input arguments and the return value
    const result = Buffer.alloc(resultSize);
    const argsList = Buffer.alloc(argsArraySize);

    // write arguments to storage areas
    let i;
    try {
      for (i = 0; i < numArgs; i++) {
        const argType = argTypes[i];
        const val = arguments[i];
        const valPtr = ref.alloc(argType, val);
        argsList.writePointer(valPtr, i * POINTER_SIZE);
      }
    } catch (e) {
      // counting arguments from 1 is more human readable
      i++;
      e.message = 'error setting argument ' + i + ' - ' + e.message;
      throw e;
    }

    // invoke the `ffi_call()` function
    bindings.ffi_call(cif, funcPtr, result, argsList);

    result.type = returnType;
    return result.deref();
  }
function ( ) { debug ( 'invoking proxy function' ) ; if ( arguments . length !== numArgs ) { throw new TypeError ( 'Expected ' + numArgs + ' arguments, got ' + arguments . length ) ; } // storage buffers for input arguments and the return value const result = Buffer . alloc ( resultSize ) ; const argsList = Buffer . alloc ( argsArraySize ) ; // write arguments to storage areas let i ; try { for ( i = 0 ; i < numArgs ; i ++ ) { const argType = argTypes [ i ] ; const val = arguments [ i ] ; const valPtr = ref . alloc ( argType , val ) ; argsList . writePointer ( valPtr , i * POINTER_SIZE ) ; } } catch ( e ) { // counting arguments from 1 is more human readable i ++ ; e . message = 'error setting argument ' + i + ' - ' + e . message ; throw e ; } // invoke the `ffi_call()` function bindings . ffi_call ( cif , funcPtr , result , argsList ) ; result . type = returnType ; return result . deref ( ) ; }
This is the actual JS function that gets returned.
It handles marshalling input arguments into C values,
and unmarshalling the return value back into a JS value
This is the actual JS function that gets returned . It handles marshalling input arguments into C values and unmarshalling the return value back into a JS value