mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
webassembly/objjsproxy: Fix logic that determines if asyncio is active.
`cur_task` can never be `None` in the webassembly port, so test it for the top-level task to see if an asyncio Task is active or not. This fixes a bug where await'ing on a JavaScript awaitable that ends up raising an error would not be caught on the Python side. The fix here makes sure it is caught by Python, as tested by the new test. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -243,8 +243,7 @@ def get_event_loop():
|
||||
|
||||
|
||||
def current_task():
|
||||
if cur_task is None:
|
||||
raise RuntimeError("no running event loop")
|
||||
assert cur_task is not None
|
||||
return cur_task
|
||||
|
||||
|
||||
|
||||
@@ -566,7 +566,8 @@ static mp_obj_t jsproxy_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) {
|
||||
// decouples the task from the thenable and allows cancelling the task.
|
||||
if (mp_asyncio_context != MP_OBJ_NULL) {
|
||||
mp_obj_t cur_task = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task));
|
||||
if (cur_task != mp_const_none) {
|
||||
mp_obj_t top_level_task = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR__top_level_task));
|
||||
if (cur_task != top_level_task) {
|
||||
mp_obj_t thenable_event_class = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_ThenableEvent));
|
||||
mp_obj_t thenable_event = mp_call_function_1(thenable_event_class, self_in);
|
||||
mp_obj_t dest[2];
|
||||
|
||||
Reference in New Issue
Block a user