Fix "from js import foo"

This commit is contained in:
Michael Droettboom 2018-04-26 11:43:48 -04:00
parent 0e8963a480
commit f1e0cc9085
2 changed files with 10 additions and 6 deletions

View File

@ -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<std::string>();
return PyBytes_FromStringAndSize(x_str.c_str(), x_str.size());
} else {
try {
std::string x_str = x.as<std::string>();
return PyBytes_FromStringAndSize(x_str.c_str(), x_str.size());
} catch (...) {
return JsProxy_cnew(x);
}
return JsProxy_cnew(x);
}
}

View File

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