Skip to content

Commit fa23e4b

Browse files
committed
webassembly/proxy_js: Convert JS undefined and JS null to Py None.
And change Py None conversion so it converts to JS undefined. The semantics for conversion of these objects are then: - Python None -> JavaScript undefined - JavaScript undefined -> Python None - JavaScript null -> Python None This follows Pyodide: https://pyodide.org/en/stable/usage/type-conversions.html Signed-off-by: Damien George <damien@micropython.org>
1 parent a67e326 commit fa23e4b

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

ports/webassembly/proxy_c.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum {
4949
};
5050

5151
enum {
52+
PROXY_KIND_JS_UNDEFINED = 0,
5253
PROXY_KIND_JS_NULL = 1,
5354
PROXY_KIND_JS_BOOLEAN = 2,
5455
PROXY_KIND_JS_INTEGER = 3,
@@ -78,7 +79,9 @@ static inline mp_obj_t proxy_c_get_obj(uint32_t c_ref) {
7879
}
7980

8081
mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value) {
81-
if (value[0] == PROXY_KIND_JS_NULL) {
82+
if (value[0] == PROXY_KIND_JS_UNDEFINED) {
83+
return mp_const_none;
84+
} else if (value[0] == PROXY_KIND_JS_NULL) {
8285
return mp_const_none;
8386
} else if (value[0] == PROXY_KIND_JS_BOOLEAN) {
8487
return mp_obj_new_bool(value[1]);

ports/webassembly/proxy_js.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const PROXY_KIND_MP_GENERATOR = 7;
3838
const PROXY_KIND_MP_OBJECT = 8;
3939
const PROXY_KIND_MP_JSPROXY = 9;
4040

41+
const PROXY_KIND_JS_UNDEFINED = 0;
4142
const PROXY_KIND_JS_NULL = 1;
4243
const PROXY_KIND_JS_BOOLEAN = 2;
4344
const PROXY_KIND_JS_INTEGER = 3;
@@ -109,7 +110,9 @@ function proxy_call_python(target, argumentsList) {
109110

110111
function proxy_convert_js_to_mp_obj_jsside(js_obj, out) {
111112
let kind;
112-
if (js_obj === null) {
113+
if (js_obj === undefined) {
114+
kind = PROXY_KIND_JS_UNDEFINED;
115+
} else if (js_obj === null) {
113116
kind = PROXY_KIND_JS_NULL;
114117
} else if (typeof js_obj === "boolean") {
115118
kind = PROXY_KIND_JS_BOOLEAN;
@@ -185,7 +188,7 @@ function proxy_convert_mp_to_js_obj_jsside(value) {
185188
}
186189
if (kind === PROXY_KIND_MP_NONE) {
187190
// None
188-
obj = null;
191+
obj = undefined;
189192
} else if (kind === PROXY_KIND_MP_BOOL) {
190193
// bool
191194
obj = Module.getValue(value + 4, "i32") ? true : false;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
false 1
22
true [ 1, 2, 3 ]
3-
true [ null, true, 1.2 ]
4-
true { tuple: [ 1, 2, 3 ], one: 1, list: [ null, true, 1.2 ] }
3+
true [ undefined, true, 1.2 ]
4+
true { tuple: [ 1, 2, 3 ], one: 1, list: [ undefined, true, 1.2 ] }

tests/ports/webassembly/run_python_async.mjs.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ py 1
2323
setTimeout resolved
2424
resolved value: 123
2525
py 2
26-
2 null
26+
2 undefined
2727
= TEST 4 ==========
2828
1
2929
py 1
@@ -35,4 +35,4 @@ py 3
3535
setTimeout B resolved
3636
resolved value: 456
3737
py 4
38-
2 null
38+
2 undefined

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy