Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
include:
- emsdk_ver: "3.1.73"
python_version: "3.13"
pybind11_version: ""
pybind11_version: "<3"
steps:
- uses: actions/checkout@v2

Expand Down
2 changes: 1 addition & 1 deletion build_mkdocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [ ! -d "$WASM_ENV_PREFIX" ]; then
-c https://repo.prefix.dev/emscripten-forge-dev\
-c https://repo.prefix.dev/conda-forge \
--yes \
python=$PYTHON_VERSION "pybind11" nlohmann_json pybind11_json numpy \
python=$PYTHON_VERSION "pybind11<3" nlohmann_json pybind11_json numpy \
bzip2 sqlite zlib zstd libffi exceptiongroup\
"xeus" "xeus-lite" xeus-python "xeus-javascript" xtl "ipython" "traitlets>=5.14.2" \
openssl liblzma
Expand Down
2 changes: 1 addition & 1 deletion include/pyjs/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ namespace pyjs


em::val py_1d_buffer_to_typed_array(py::buffer buffer, bool view);
em::val bytes_to_js(char* data);
em::val bytes_to_js(char* data, std::size_t length);

}
3 changes: 2 additions & 1 deletion module/pyjs/convert_py_to_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def to_js(value, cache=None, depth=0, max_depth=None):

# # bytestring
elif isinstance(value, bytes):
return internal.bytes_to_typed_array(value).buffer
l = len(value)
return internal.bytes_to_typed_array(value, l).buffer

elif hasattr(value, "explicit_to_js"):
return value.explicit_to_js()
Expand Down
3 changes: 1 addition & 2 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ namespace pyjs
}


em::val bytes_to_js(char * binary_string)
em::val bytes_to_js(char * binary_string, std::size_t length)
{
// get the length of the string
std::size_t length = std::strlen(binary_string);
em::val mem_view = em::val(em::typed_memory_view(length, binary_string));
em::val mem_copy = em::val::global("Uint8Array").new_(mem_view);
return mem_copy;
Expand Down
2 changes: 1 addition & 1 deletion src/js_timestamp.cpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PYJS_JS_UTC_TIMESTAMP "2025-07-04 07:29:10.089112"
#define PYJS_JS_UTC_TIMESTAMP "2025-09-01 06:22:09.224255"
5 changes: 5 additions & 0 deletions tests/tests/test_pyjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ def test_to_js_dict():
assert jsmap.get(1) == "a"


def test_bytes_to_js():
pyjs.to_js(b"\x00").byteLength == 1



def test_to_js_none():

jsval = pyjs.to_js(None)
Expand Down