diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c index 00abc43bf2b3f..6c20fa850dce9 100644 --- a/ports/webassembly/proxy_c.c +++ b/ports/webassembly/proxy_c.c @@ -50,6 +50,7 @@ enum { PROXY_KIND_MP_OBJECT = 8, PROXY_KIND_MP_JSPROXY = 9, PROXY_KIND_MP_EXISTING = 10, + PROXY_KIND_MP_BYTES = 11, }; enum { @@ -61,6 +62,7 @@ enum { PROXY_KIND_JS_STRING = 5, PROXY_KIND_JS_OBJECT = 6, PROXY_KIND_JS_PYPROXY = 7, + PROXY_KIND_JS_BYTES = 8, }; MP_DEFINE_CONST_OBJ_TYPE( @@ -170,6 +172,10 @@ mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value) { mp_obj_t s = mp_obj_new_str((void *)value[2], value[1]); free((void *)value[2]); return s; + } else if (value[0] == PROXY_KIND_JS_BYTES) { + mp_obj_t s = mp_obj_new_bytes((void *)value[2], value[1]); + free((void *)value[2]); + return s; } else if (value[0] == PROXY_KIND_JS_PYPROXY) { return proxy_c_get_obj(value[1]); } else { @@ -200,6 +206,14 @@ void proxy_convert_mp_to_js_obj_cside(mp_obj_t obj, uint32_t *out) { const char *str = mp_obj_str_get_data(obj, &len); out[1] = len; out[2] = (uintptr_t)str; + } else if (mp_obj_get_type(obj) == &mp_type_bytes || mp_obj_get_type(obj) == &mp_type_bytearray) { + kind = PROXY_KIND_MP_BYTES; + mp_buffer_info_t bufinfo; + mp_get_buffer(obj, &bufinfo, MP_BUFFER_READ); + size_t len = bufinfo.len; + const uint8_t *buf = bufinfo.buf; + out[1] = len; + out[2] = (uintptr_t)buf; } else if (obj == mp_const_undefined) { kind = PROXY_KIND_MP_JSPROXY; out[1] = 1; diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js index 9e7c233e30bfc..b3264c7886aca 100644 --- a/ports/webassembly/proxy_js.js +++ b/ports/webassembly/proxy_js.js @@ -41,6 +41,7 @@ const PROXY_KIND_MP_GENERATOR = 7; const PROXY_KIND_MP_OBJECT = 8; const PROXY_KIND_MP_JSPROXY = 9; const PROXY_KIND_MP_EXISTING = 10; +const PROXY_KIND_MP_BYTES = 11; const PROXY_KIND_JS_UNDEFINED = 0; const PROXY_KIND_JS_NULL = 1; @@ -50,6 +51,7 @@ const PROXY_KIND_JS_DOUBLE = 4; const PROXY_KIND_JS_STRING = 5; const PROXY_KIND_JS_OBJECT = 6; const PROXY_KIND_JS_PYPROXY = 7; +const PROXY_KIND_JS_BYTES = 8; class PythonError extends Error { constructor(exc_type, exc_details) { @@ -143,6 +145,7 @@ function proxy_call_python(target, argumentsList) { "null", ["number", "number", "number", "pointer"], [target, argumentsList.length, args, value], + { async: true }, ); if (argumentsList.length > 0) { Module._free(args); @@ -195,6 +198,13 @@ function proxy_convert_js_to_mp_obj_jsside(js_obj, out) { Module.stringToUTF8(js_obj, buf, len + 1); Module.setValue(out + 4, len, "i32"); Module.setValue(out + 8, buf, "i32"); + } else if (js_obj instanceof Uint8Array) { + kind = PROXY_KIND_JS_BYTES; + const len = js_obj.length; + const buf = Module._malloc(len); + for (let i = 0; i < len; i++) Module.HEAPU8[buf + i] = js_obj[i]; + Module.setValue(out + 4, len, "i32"); + Module.setValue(out + 8, buf, "i32"); } else if ( js_obj instanceof PyProxy || (typeof js_obj === "function" && "_ref" in js_obj) || @@ -264,6 +274,11 @@ function proxy_convert_mp_to_js_obj_jsside(value) { const str_len = Module.getValue(value + 4, "i32"); const str_ptr = Module.getValue(value + 8, "i32"); obj = Module.UTF8ToString(str_ptr, str_len); + } else if (kind === PROXY_KIND_MP_BYTES) { + // bytes + const buf_len = Module.getValue(value + 4, "i32"); + const buf_ptr = Module.getValue(value + 8, "i32"); + obj = new Uint8Array(Module.HEAPU8.buffer, buf_ptr, buf_len); } else if (kind === PROXY_KIND_MP_JSPROXY) { // js proxy const id = Module.getValue(value + 4, "i32"); 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