Merge pull request #265 from mdboom/kwargs

Fix #261: Support named arguments when calling a JS function
This commit is contained in:
Roman Yurchak 2018-12-04 12:42:38 +01:00 committed by GitHub
commit fd6e0bf422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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);

View File

@ -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(
"""