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>
This commit is contained in:
Damien George
2024-05-09 15:36:30 +10:00
parent a67e326cb9
commit fa23e4b093
4 changed files with 13 additions and 7 deletions

View File

@@ -38,6 +38,7 @@ const PROXY_KIND_MP_GENERATOR = 7;
const PROXY_KIND_MP_OBJECT = 8;
const PROXY_KIND_MP_JSPROXY = 9;
const PROXY_KIND_JS_UNDEFINED = 0;
const PROXY_KIND_JS_NULL = 1;
const PROXY_KIND_JS_BOOLEAN = 2;
const PROXY_KIND_JS_INTEGER = 3;
@@ -109,7 +110,9 @@ function proxy_call_python(target, argumentsList) {
function proxy_convert_js_to_mp_obj_jsside(js_obj, out) {
let kind;
if (js_obj === null) {
if (js_obj === undefined) {
kind = PROXY_KIND_JS_UNDEFINED;
} else if (js_obj === null) {
kind = PROXY_KIND_JS_NULL;
} else if (typeof js_obj === "boolean") {
kind = PROXY_KIND_JS_BOOLEAN;
@@ -185,7 +188,7 @@ function proxy_convert_mp_to_js_obj_jsside(value) {
}
if (kind === PROXY_KIND_MP_NONE) {
// None
obj = null;
obj = undefined;
} else if (kind === PROXY_KIND_MP_BOOL) {
// bool
obj = Module.getValue(value + 4, "i32") ? true : false;