Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move call and new to JsMethod #1138

Merged
merged 36 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5ac847a
Added "make debug" which sets DEBUG_F flag, fixed missing semicolon i…
Jan 10, 2021
8874676
Added ASSERTIONS=2 and PYODIDE_PACKAGES="all packages used in test-core"
Jan 11, 2021
ef9fa08
Don't clear EXTRA_CFLAGS, PYODIDE_PACKAGES+=
Jan 11, 2021
7b46a8c
Made JsBoundMethod a subclass of JsProxy (fixes #788)
Jan 11, 2021
fbcf8c8
Added tests
Jan 11, 2021
105539d
Removed tests for #768, lint
Jan 11, 2021
1c6ae60
Merge branch 'master' into subclass-jsboundmethod
Jan 11, 2021
0264f85
Fix #461
Jan 12, 2021
c2d4486
Added tests (I think these are the right ones?)
Jan 12, 2021
56a4369
Merge branch 'debug-make-recipe' into bind-imports
Jan 12, 2021
72543d7
Fix initialization order
Jan 12, 2021
709118c
Added tests
Jan 12, 2021
8c9d053
Merge branch 'subclass-jsboundmethod' into bind-imports
Jan 12, 2021
a9f4a3c
Forgot @run_in_pyodide in a test
Jan 12, 2021
1eee392
Fix tests
Jan 12, 2021
6051303
Merge branch 'master' into bind-imports
Jan 12, 2021
97b254e
Merge branch 'master' into bind-imports
dalcde Jan 14, 2021
c4b5ad1
Renamed JsBoundMethod ==> JsMethod
Jan 14, 2021
756b454
Rearranged jsproxy.c to move JsProxy_Call and calling logic to JsMethod
Jan 14, 2021
7e6f631
fixed a couple errors
Jan 14, 2021
c46b709
Merge branch 'bind-imports' of github.com:hoodmane/pyodide into call-…
Jan 14, 2021
d8ba5be
Merge branch 'master' into call-and-new-to-js-method
Jan 14, 2021
50482c5
Made new factory method "JsProxy_create" which gives JsProxy control …
Jan 15, 2021
3fa4e11
Fix compile errors
Jan 15, 2021
ca6bf61
Fix hiwire_is_error
Jan 15, 2021
5089ae7
Fix typo in hiwire
Jan 15, 2021
1e3fe74
jsnull ==> null
Jan 15, 2021
5faea48
Handle NULL `this` parameter in `hiwire_call_bound`
Jan 16, 2021
a4ce376
Update test_jsproxy_dir
Jan 16, 2021
cc1eddd
Remove xfail marks from tests I think no longer fail?
Jan 16, 2021
ed7a9a9
Fix lint
Jan 16, 2021
2188b8e
Fix tests: index error, one needs to xfail still, other works I think…
Jan 16, 2021
f75f753
Fix one last test
Jan 16, 2021
9b92d3c
Remove HAVE_VECTOR_CALL from JsProxyType.tp_flags
Jan 16, 2021
6e1a367
Lint
Jan 16, 2021
5566dd9
Merge branch 'master' into call-and-new-to-js-method
dalcde Jan 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/error_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EM_JS_NUM(errcode, log_error_obj, (JsRef obj), {
void
PyodideErr_SetJsError(JsRef err)
{
PyObject* py_err = JsProxy_new_error(err);
PyObject* py_err = JsProxy_create(err);
PyErr_SetObject((PyObject*)(py_err->ob_type), py_err);
}

Expand Down
19 changes: 16 additions & 3 deletions src/core/hiwire.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hiwire_undefined()
}

JsRef
hiwire_jsnull()
hiwire_null()
{
return Js_NULL;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ EM_JS(int, hiwire_init, (), {
};
Module.hiwire = {};
Module.hiwire.UNDEFINED = _hiwire_undefined();
Module.hiwire.JSNULL = _hiwire_jsnull();
Module.hiwire.JSNULL = _hiwire_null();
Module.hiwire.TRUE = _hiwire_true();
Module.hiwire.FALSE = _hiwire_false();

Expand Down Expand Up @@ -339,7 +339,14 @@ EM_JS_REF(JsRef,
(JsRef idfunc, JsRef idthis, JsRef idargs),
{
let func = Module.hiwire.get_value(idfunc);
let this_ = Module.hiwire.get_value(idthis);
let this_;
// clang-format off
if (idthis === 0) {
// clang-format on
this_ = null;
} else {
this_ = Module.hiwire.get_value(idthis);
}
let args = Module.hiwire.get_value(idargs);
return Module.hiwire.new_value(func.apply(this_, args));
});
Expand Down Expand Up @@ -393,6 +400,12 @@ EM_JS_NUM(bool, hiwire_is_function, (JsRef idobj), {
// clang-format on
});

EM_JS_NUM(bool, hiwire_is_error, (JsRef idobj), {
// From https://stackoverflow.com/a/45496068
let value = Module.hiwire.get_value(idobj);
return !!(value && value.stack && value.message);
});

EM_JS_NUM(bool, hiwire_function_supports_kwargs, (JsRef idfunc), {
let funcstr = Module.hiwire.get_value(idfunc).toString();
return Module.function_supports_kwargs(funcstr);
Expand Down
3 changes: 3 additions & 0 deletions src/core/hiwire.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ hiwire_is_pyproxy(JsRef idobj);
bool
hiwire_is_function(JsRef idobj);

bool
hiwire_is_error(JsRef idobj);

bool
hiwire_function_supports_kwargs(JsRef idfunc);

Expand Down
15 changes: 2 additions & 13 deletions src/core/js2python.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,14 @@ _js2python_pyproxy(PyObject* val)
PyObject*
_js2python_memoryview(JsRef id)
{
PyObject* jsproxy = JsProxy_cnew(id);
PyObject* jsproxy = JsProxy_create(id);
return PyMemoryView_FromObject(jsproxy);
}

PyObject*
_js2python_jsproxy(JsRef id)
{
return JsProxy_cnew(id);
}

PyObject*
_js2python_error(JsRef id)
{
return JsProxy_new_error(id);
return JsProxy_create(id);
}

// TODO: Add some meaningful order
Expand Down Expand Up @@ -135,9 +129,6 @@ EM_JS_REF(PyObject*, __js2python, (JsRef id), {
return result;
}

// From https://stackoverflow.com/a/45496068
function is_error(value) { return value && value.stack && value.message; }

// clang-format off
let value = Module.hiwire.get_value(id);
let type = typeof value;
Expand All @@ -155,8 +146,6 @@ EM_JS_REF(PyObject*, __js2python, (JsRef id), {
return __js2python_pyproxy(Module.PyProxy.getPtr(value));
} else if (value['byteLength'] !== undefined) {
return __js2python_memoryview(id);
} else if (is_error(value)) {
return __js2python_error(id);
} else {
return __js2python_jsproxy(id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/jsimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int
JsImport_init()
{
JsRef globalThis_ref = hiwire_get_global("globalThis");
globalThis = JsProxy_cnew(globalThis_ref);
globalThis = JsProxy_create(globalThis_ref);
hiwire_decref(globalThis_ref);

PyObject* module_dict = PyImport_GetModuleDict();
Expand Down