This changes the calling convention for calling a Javascript function from Python so that any proxied arguments are automatically destroyed at the end of the function call. This is a breaking change. It should make it much more convenient to use the foreign function interface. 

The docs need to be updated to explain the new calling convention before this can be merged. We should put a link to the appropriate section in the docs into the error message emitted when a borrowed proxy is used after it is free so that people have an easy time learning the model by trial and error.
ENH Destroy proxies created in JsProxy.__call__ when done with call. This changes the calling convention for calling a Javascript function from Python so that any proxied arguments are automatically destroyed at the end of the function call. This is a breaking change. It should make it much more convenient to use the foreign function interface. 

The docs need to be updated to explain the new calling convention before this can be merged. We should put a link to the appropriate section in the docs into the error message emitted when a borrowed proxy is used after it is free so that people have an easy time learning the model by trial and error.
#ifndef PYTHON2JS_H
#define PYTHON2JS_H

/** Translate Python objects to Javascript.
 */
// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include "hiwire.h"

/**
 * Do a shallow conversion from python to Javascript. Convert immutable types
 * with equivalent Javascript immutable types, but all other types are proxied.
 */
JsRef
python2js(PyObject* x);

/**
 * Like python2js except in the handling of PyProxy creation.
 *
 * If proxies is NULL, will throw an error instead of creating a PyProxy.
 * Otherwise, proxies should be an Array and python2js_track_proxies will add
 * all proxies created to the proxies array.
 */
JsRef
python2js_track_proxies(PyObject* x, JsRef proxies);

/**
 * Convert a Python object to a Javascript object, copying standard collections
 * into javascript down to specified depth
 * \param x The Python object
 * \param depth The maximum depth to copy
 * \param proxies If this is Null, will raise an error if we have no Javascript
 *        conversion for a Python object. If not NULL, should be a Javascript
 *        list. We will add all PyProxies created to the list.
 * \return The Javascript object -- might be an Error object in the case of an
 *         exception.
 */
JsRef
python2js_with_depth(PyObject* x, int depth, JsRef proxies);

int
python2js_init(PyObject* core);

#endif /* PYTHON2JS_H */

#ifndef PYTHON2JS_H
#define PYTHON2JS_H

/** Translate Python objects to Javascript.
 */
// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include "hiwire.h"

/**
 * Do a shallow conversion from python to Javascript. Convert immutable types
 * with equivalent Javascript immutable types, but all other types are proxied.
 */
JsRef
python2js(PyObject* x);

/**
 * Like python2js except in the handling of PyProxy creation.
 *
 * If proxies is NULL, will throw an error instead of creating a PyProxy.
 * Otherwise, proxies should be an Array and python2js_track_proxies will add
 * the proxy to the array if one is created.
 */
JsRef
python2js_track_proxies(PyObject* x, JsRef proxies);

/**
 * Convert a Python object to a Javascript object, copying standard collections
 * into javascript down to specified depth
 * \param x The Python object
 * \param depth The maximum depth to copy
 * \param proxies If this is Null, will raise an error if we have no Javascript
 *        conversion for a Python object. If not NULL, should be a Javascript
 *        list. We will add all PyProxies created to the list.
 * \return The Javascript object -- might be an Error object in the case of an
 *         exception.
 */
JsRef
python2js_with_depth(PyObject* x, int depth, JsRef proxies);

int
python2js_init(PyObject* core);

#endif /* PYTHON2JS_H */
