mirror of https://github.com/pyodide/pyodide.git
Merge pull request #265 from mdboom/kwargs
Fix #261: Support named arguments when calling a JS function
This commit is contained in:
commit
fd6e0bf422
|
@ -110,6 +110,12 @@ JsProxy_Call(PyObject* o, PyObject* args, PyObject* kwargs)
|
|||
hiwire_decref(idarg);
|
||||
}
|
||||
|
||||
if (PyDict_Size(kwargs)) {
|
||||
int idkwargs = python2js(kwargs);
|
||||
hiwire_push_array(idargs, idkwargs);
|
||||
hiwire_decref(idkwargs);
|
||||
}
|
||||
|
||||
int idresult = hiwire_call(self->js, idargs);
|
||||
hiwire_decref(idargs);
|
||||
PyObject* pyresult = js2python(idresult);
|
||||
|
|
|
@ -342,6 +342,22 @@ def test_jsproxy_implicit_iter(selenium):
|
|||
"list(Object.values(ITER))") == [1, 2, 3]
|
||||
|
||||
|
||||
def test_jsproxy_kwargs(selenium):
|
||||
selenium.run_js(
|
||||
"""
|
||||
window.kwarg_function = ({ a = 1, b = 1 }) => {
|
||||
return a / b;
|
||||
};
|
||||
"""
|
||||
)
|
||||
assert selenium.run(
|
||||
"""
|
||||
from js import kwarg_function
|
||||
kwarg_function(b = 2, a = 10)
|
||||
"""
|
||||
) == 5
|
||||
|
||||
|
||||
def test_open_url(selenium):
|
||||
assert selenium.run(
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue