forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyfill.js
32 lines (31 loc) · 1.2 KB
/
polyfill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function caml_is_js(unit){
return 1;
}
//Provides: caml_blit_bytes
//Requires: caml_subarray_to_string, caml_convert_string_to_array
function caml_blit_bytes(s1, i1, s2, i2, len) {
if (len == 0) return 0;
if ((i2 == 0) &&
(len >= s2.l || (s2.t == 2 /* PARTIAL */ && len >= s2.c.length))) {
s2.c = (s1.t == 4 /* ARRAY */)?
caml_subarray_to_string(s1.c, i1, len):
(i1 == 0 && s1.c.length == len)?s1.c:s1.c.substr(i1, len);
s2.t = (s2.c.length == s2.l)?0 /* BYTES | UNKOWN */ :2; /* PARTIAL */
} else if (s2.t == 2 /* PARTIAL */ && i2 == s2.c.length) {
s2.c += (s1.t == 4 /* ARRAY */)?
caml_subarray_to_string(s1.c, i1, len):
(i1 == 0 && s1.c.length == len)?s1.c:s1.c.substr(i1, len);
s2.t = (s2.c.length == s2.l)?0 /* BYTES | UNKOWN */ :2; /* PARTIAL */
} else {
if (s2.t != 4 /* ARRAY */) caml_convert_string_to_array(s2);
var c1 = s1.c, c2 = s2.c;
if (s1.t == 4 /* ARRAY */)
for (var i = 0; i < len; i++) c2 [i2 + i] = c1 [i1 + i];
else {
var l = Math.min (len, c1.length - i1);
for (var i = 0; i < l; i++) c2 [i2 + i] = c1.charCodeAt(i1 + i);
for (; i < len; i++) c2 [i2 + i] = 0;
}
}
return 0;
}