@@ -94,15 +94,11 @@ function caml_sub_uint8_array_to_jsbytes(a, i, len) {
9494 for ( ; 0 < len ; i += 1024 , len -= 1024 )
9595 s += f . apply ( null , a . subarray ( i , i + Math . min ( len , 1024 ) ) ) ;
9696 return s ;
97+ }
9798
9899//Provides: caml_jsbytes_to_array
99100function caml_jsbytes_to_array ( s ) {
100- /* Assumes not ARRAY */
101- if ( globalThis . Uint8Array ) {
102- var a = new globalThis . Uint8Array ( s . length ) ;
103- } else {
104- var a = new Array ( s . length ) ;
105- }
101+ var a = new Uint8Array ( s . length ) ;
106102 var b = s ,
107103 l = b . length ,
108104 i = 0 ;
@@ -407,27 +403,29 @@ function caml_bytes_of_utf16_jsstring(s) {
407403
408404//Provides: MlBytes
409405//Requires: jsoo_is_ascii, caml_utf16_of_utf8, caml_subarray_to_jsbytes
410- function MlBytes ( a ) {
411- this . a = a ;
412- }
413- MlBytes . prototype . toString = function ( ) {
414- return caml_subarray_to_jsbytes ( this . a , 0 , this . a . length ) ;
415- } ;
416- MlBytes . prototype . toUtf16 = function ( ) {
417- var r = this . toString ( ) ;
418- return caml_utf16_of_utf8 ( r ) ;
419- } ;
420- MlBytes . prototype . slice = function ( ) {
421- var content = this . a . slice ( ) ;
422- return new MlBytes ( content ) ;
423- } ;
406+ class MlBytes {
407+ constructor ( a ) {
408+ this . a = a ;
409+ }
410+ toString ( ) {
411+ return caml_subarray_to_jsbytes ( this . a , 0 , this . a . length ) ;
412+ } ;
413+ toUtf16 ( ) {
414+ var r = this . toString ( ) ;
415+ return caml_utf16_of_utf8 ( r ) ;
416+ } ;
417+ slice ( ) {
418+ var content = this . a . slice ( ) ;
419+ return new MlBytes ( content ) ;
420+ }
421+ }
424422
425423//Provides: caml_uint8_array_of_bytes mutable
426424function caml_uint8_array_of_bytes ( s ) {
427425 return s . a ;
428426}
429427
430- //Provides: caml_uint8_array_of_string
428+ //Provides: caml_uint8_array_of_string mutable
431429//Requires: caml_ml_string_length, caml_string_unsafe_get
432430function caml_uint8_array_of_string ( s ) {
433431 var l = caml_ml_string_length ( s ) ;
@@ -442,7 +440,7 @@ function caml_uint8_array_of_string(s) {
442440//If: !js-string
443441function caml_create_string ( len ) {
444442 if ( len < 0 ) caml_invalid_argument ( "String.create" ) ;
445- return new MlBytes ( new globalThis . Uint8Array ( len ) ) ;
443+ return new MlBytes ( new Uint8Array ( len ) ) ;
446444}
447445//Provides: caml_create_string const
448446//Requires: caml_invalid_argument
@@ -455,7 +453,7 @@ function caml_create_string(len) {
455453//Requires: MlBytes,caml_invalid_argument
456454function caml_create_bytes ( len ) {
457455 if ( len < 0 ) caml_invalid_argument ( "Bytes.create" ) ;
458- return new MlBytes ( new globalThis . Uint8Array ( len ) ) ;
456+ return new MlBytes ( new Uint8Array ( len ) ) ;
459457}
460458
461459//Provides: caml_string_of_array
@@ -481,6 +479,7 @@ function caml_string_of_uint8_array(a) {
481479//Provides: caml_bytes_of_array
482480//Requires: MlBytes
483481function caml_bytes_of_array ( a ) {
482+ if ( ! ( a instanceof Uint8Array ) ) a = new Uint8Array ( a ) ;
484483 return new MlBytes ( a ) ;
485484}
486485
@@ -499,7 +498,7 @@ function caml_compare_array(a, b) {
499498//Provides: caml_bytes_of_uint8_array
500499//Requires: MlBytes
501500function caml_bytes_of_uint8_array ( a ) {
502- return new MlBytes ( 4 , a , a . length ) ;
501+ return new MlBytes ( a ) ;
503502}
504503
505504//Provides: caml_bytes_compare mutable
@@ -607,7 +606,7 @@ function caml_string_concat(a, b) {
607606//Requires: MlBytes
608607//If: !js-string
609608function caml_string_concat ( s1 , s2 ) {
610- var n = new globalThis . Uint8Array ( s1 . a . length + s2 . a . length ) ;
609+ var n = new Uint8Array ( s1 . a . length + s2 . a . length ) ;
611610 n . set ( s1 . a ) ;
612611 n . set ( s2 . a , s1 . a . length ) ;
613612 return new MlBytes ( n ) ;
0 commit comments