From 272bd754f6164c2a5a1955df751b5bae34d3c8d4 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Fri, 11 Oct 2024 13:47:17 +0200 Subject: [PATCH] Runtime: don't change the shape of bytes when converting to string --- runtime/mlBytes.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/mlBytes.js b/runtime/mlBytes.js index fe7e7f9c3d..f3b90457d9 100644 --- a/runtime/mlBytes.js +++ b/runtime/mlBytes.js @@ -752,10 +752,18 @@ function caml_string_lessthan(s1, s2) { //Provides: caml_string_of_bytes //Requires: caml_convert_string_to_bytes, caml_string_of_jsbytes +//Requires: caml_subarray_to_jsbytes //If: js-string function caml_string_of_bytes(s) { - s.t & 6 && caml_convert_string_to_bytes(s); - return caml_string_of_jsbytes(s.c); + switch (s.t & 6) { + case 0 /* BYTES */: + return caml_string_of_jsbytes(s.c); + case 2 /* PARTIAL */: + caml_convert_string_to_bytes(s); + return caml_string_of_jsbytes(s.c); + case 4 /* ARRAY */: + return caml_subarray_to_jsbytes(s.c, 0, s.c.length); + } } //Provides: caml_bytes_of_string const