diff --git a/CHANGES.md b/CHANGES.md index 83b2dab691..59ff00980e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,7 @@ requested at compile time (--enable with-js-error) or at startup (OCAMLRUNPARAM=b=1) * Runtime: allow dynlink of precompiled js with separate compilation (#1676) * Runtime: reimplement the runtime of weak and ephemeron (#1707) +* Runtime: don't change the shape of mlbytes when converting to string * Lib: Modify Typed_array API for compatibility with WebAssembly * Lib: add details element and toggle event (#1728) * Toplevel: no longer set globals for toplevel initialization diff --git a/runtime/js/mlBytes.js b/runtime/js/mlBytes.js index 8566487548..2771ae23bd 100644 --- a/runtime/js/mlBytes.js +++ b/runtime/js/mlBytes.js @@ -703,10 +703,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