From 9724287597d61c8a8d6c3bdfd04f9bd1ad7e8016 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 24 Oct 2024 09:07:10 +0200 Subject: [PATCH] fix --- runtime/js/mlBytes.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/runtime/js/mlBytes.js b/runtime/js/mlBytes.js index 756916b2dd..331534570c 100644 --- a/runtime/js/mlBytes.js +++ b/runtime/js/mlBytes.js @@ -286,9 +286,14 @@ var jsoo_text_decoder = new TextDecoder(); //Provides: caml_bytes_of_utf16_jsstring //Requires: MlBytes, jsoo_text_encoder +//Requires: jsoo_is_ascii function caml_bytes_of_utf16_jsstring(s) { - var a = jsoo_text_encoder.encode(s); - return new MlBytes(4, a, a.length); + if (jsoo_is_ascii(s)) { + return new MlBytes(9, s, s.length); + } else { + var a = jsoo_text_encoder.encode(s); + return new MlBytes(4, a, a.length); + } } //Provides: MlBytes @@ -648,8 +653,10 @@ function caml_jsstring_of_string(s) { //Provides: caml_string_of_jsstring const //Requires: caml_string_of_array //Requires: jsoo_text_encoder +//Requires: jsoo_is_ascii, caml_string_of_jsbytes //If: js-string function caml_string_of_jsstring(s) { + if (jsoo_is_ascii(s)) return caml_string_of_jsbytes(s); var a = jsoo_text_encoder.encode(s); return caml_string_of_array(a); }