Content-Length: 403191 | pFad | http://github.com/micropython/micropython/commit/fa23e4b093f81f03a24187c7ea0c928a9b4a661b

DB webassembly/proxy_js: Convert JS undefined and JS null to Py None. · micropython/micropython@fa23e4b · GitHub
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

Diff for: ports/webassembly/proxy_c.c

+4-1
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]);

Diff for: ports/webassembly/proxy_js.js

+5-2
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;

Diff for: tests/ports/webassembly/py_proxy_to_js.mjs.exp

+2-2
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 ] }

Diff for: tests/ports/webassembly/run_python_async.mjs.exp

+2-2
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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/micropython/micropython/commit/fa23e4b093f81f03a24187c7ea0c928a9b4a661b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy