Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
39975321
Commit
39975321
authored
Mar 29, 2024
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webassembly/proxy_c: Ensure return value of async fun is passed to JS.
Signed-off-by:
Damien George
<
damien@micropython.org
>
parent
87d821ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
3 deletions
+53
-3
ports/webassembly/proxy_c.c
ports/webassembly/proxy_c.c
+6
-3
tests/ports/webassembly/await_js_async_py.mjs
tests/ports/webassembly/await_js_async_py.mjs
+35
-0
tests/ports/webassembly/await_js_async_py.mjs.exp
tests/ports/webassembly/await_js_async_py.mjs.exp
+12
-0
No files found.
ports/webassembly/proxy_c.c
View file @
39975321
...
...
@@ -289,10 +289,11 @@ void proxy_c_to_js_get_dict(uint32_t c_ref, uint32_t *out) {
static
const
mp_obj_fun_builtin_var_t
resume_obj
;
EM_JS
(
void
,
js_then_resolve
,
(
uint32_t
*
resolve
,
uint32_t
*
reject
),
{
EM_JS
(
void
,
js_then_resolve
,
(
uint32_t
*
ret_value
,
uint32_t
*
resolve
,
uint32_t
*
reject
),
{
const
ret_value_js
=
proxy_convert_mp_to_js_obj_jsside
(
ret_value
);
const
resolve_js
=
proxy_convert_mp_to_js_obj_jsside
(
resolve
);
const
reject_js
=
proxy_convert_mp_to_js_obj_jsside
(
reject
);
resolve_js
(
null
);
resolve_js
(
ret_value_js
);
});
EM_JS
(
void
,
js_then_reject
,
(
uint32_t
*
resolve
,
uint32_t
*
reject
),
{
...
...
@@ -321,7 +322,9 @@ static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t value, mp_obj_t
proxy_convert_mp_to_js_obj_cside
(
reject
,
out_reject
);
if
(
ret_kind
==
MP_VM_RETURN_NORMAL
)
{
js_then_resolve
(
out_resolve
,
out_reject
);
uint32_t
out_ret_value
[
PVN
];
proxy_convert_mp_to_js_obj_cside
(
ret_value
,
out_ret_value
);
js_then_resolve
(
out_ret_value
,
out_resolve
,
out_reject
);
return
mp_const_none
;
}
else
if
(
ret_kind
==
MP_VM_RETURN_YIELD
)
{
// ret_value should be a JS thenable
...
...
tests/ports/webassembly/await_js_async_py.mjs
0 → 100644
View file @
39975321
// Test JavaScript await'ing on Python async functions.
const
mp
=
await
(
await
import
(
process
.
argv
[
2
])).
loadMicroPython
();
globalThis
.
asyncTimeout
=
(
ms
)
=>
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
ms
));
mp
.
runPython
(
`
import js
def f0():
print("f0 run")
return 1
async def f1():
print("f1 run")
return 2
async def f2():
print("f2 start")
await js.asyncTimeout(0)
print("f2 end")
return 3
async def f3():
print("f3 start")
ret = await f2()
print("f3 end")
return ret + 1
`
);
console
.
log
(
"
f0 return:
"
,
await
mp
.
globals
.
get
(
"
f0
"
)());
console
.
log
(
"
f1 return:
"
,
await
mp
.
globals
.
get
(
"
f1
"
)());
console
.
log
(
"
f2 return:
"
,
await
mp
.
globals
.
get
(
"
f2
"
)());
console
.
log
(
"
f3 return:
"
,
await
mp
.
globals
.
get
(
"
f3
"
)());
tests/ports/webassembly/await_js_async_py.mjs.exp
0 → 100644
View file @
39975321
f0 run
f0 return: 1
f1 run
f1 return: 2
f2 start
f2 end
f2 return: 3
f3 start
f2 start
f2 end
f3 end
f3 return: 4
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment