diff --git a/src/js2python.cpp b/src/js2python.cpp index 3fcff5ead..45b0c51e5 100644 --- a/src/js2python.cpp +++ b/src/js2python.cpp @@ -32,13 +32,11 @@ PyObject *jsToPython(val x) { PyObject *pypy_x = py_x.x; Py_INCREF(pypy_x); return pypy_x; + } else if (!x["byteLength"].isUndefined()) { + std::string x_str = x.as(); + return PyBytes_FromStringAndSize(x_str.c_str(), x_str.size()); } else { - try { - std::string x_str = x.as(); - return PyBytes_FromStringAndSize(x_str.c_str(), x_str.size()); - } catch (...) { - return JsProxy_cnew(x); - } + return JsProxy_cnew(x); } } diff --git a/test/test_python.py b/test/test_python.py index e80200ebd..5f5e01f67 100644 --- a/test/test_python.py +++ b/test/test_python.py @@ -20,6 +20,12 @@ def test_print(selenium): assert 'This should be logged' in selenium.logs +def test_import_js(selenium): + result = selenium.run( + "from js import window\nwindow.title = 'Foo'\nwindow.title") + assert result == 'Foo' + + def test_run_core_python_test(python_test, selenium): selenium.run( "import sys\n"