From 528c0f29615466847e3fef6d113c5b7a396688f8 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 28 Nov 2018 12:25:04 -0500 Subject: [PATCH] Fix #261: Support named arguments when calling a JS function --- src/jsproxy.c | 6 ++++++ test/test_python.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/jsproxy.c b/src/jsproxy.c index 70def0bea..621d86e9f 100644 --- a/src/jsproxy.c +++ b/src/jsproxy.c @@ -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); diff --git a/test/test_python.py b/test/test_python.py index 763dd08fc..5a5bd2e68 100644 --- a/test/test_python.py +++ b/test/test_python.py @@ -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( """