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.
from pyodide_build.testing import run_in_pyodide


@run_in_pyodide(packages=["cloudpickle"])
def test_cloudpickle():
    import cloudpickle

    squared = lambda x: x ** 2
    pickled_lambda = cloudpickle.dumps(squared)

    import pickle

    new_squared = pickle.loads(pickled_lambda)
    assert new_squared(2) == 4

    CONSTANT = 42

    def my_function(data: int) -> int:
        return data + CONSTANT

    pickled_function = cloudpickle.dumps(my_function)
    depickled_function = pickle.loads(pickled_function)
    assert depickled_function(43) == 85

from pyodide_build.testing import run_in_pyodide


@run_in_pyodide(packages=["cloudpickle"])
def test_cloudpickle():
    import cloudpickle

    squared = lambda x: x ** 2
    pickled_lambda = cloudpickle.dumps(squared)

    import pickle

    new_squared = pickle.loads(pickled_lambda)
    assert new_squared(2) == 4

    CONSTANT = 42

    def my_function(data: int) -> int:
        return data + CONSTANT

    pickled_function = cloudpickle.dumps(my_function)
    depickled_function = pickle.loads(pickled_function)
    assert depickled_function(43) == 85
