xml2js
Version:
Simple XML to JavaScript object converter.
1,604 lines (1,602 loc) • 3.39 MB
JavaScript
//# 1 ".xml2js.eobjs/jsoo/xml2js.bc.runtime.js"
// Generated by js_of_ocaml
//# buildInfo:effects=false, kind=unknown, use-js-string=true, version=5.2.0+git-0e29f0e-dirty
//# 3 ".xml2js.eobjs/jsoo/xml2js.bc.runtime.js"
//# 7 ".xml2js.eobjs/jsoo/xml2js.bc.runtime.js"
(function
(Object){
typeof globalThis !== "object"
&&
(this
? get()
: (Object.defineProperty
(Object.prototype, "_T_", {configurable: true, get: get}),
_T_));
function get(){
var global = this || self;
global.globalThis = global;
delete Object.prototype._T_;
}
}
(Object));
(function(globalThis){
"use strict";
function caml_int64_is_zero(x){return + x.isZero();}
function caml_str_repeat(n, s){
if(n == 0) return "";
if(s.repeat) return s.repeat(n);
var r = "", l = 0;
for(;;){
if(n & 1) r += s;
n >>= 1;
if(n == 0) return r;
s += s;
l++;
if(l == 9) s.slice(0, 1);
}
}
var caml_int64_offset = Math.pow(2, - 24);
function caml_raise_constant(tag){throw tag;}
var caml_global_data = [0];
function caml_raise_zero_divide(){
caml_raise_constant(caml_global_data.Division_by_zero);
}
function MlInt64(lo, mi, hi){
this.lo = lo & 0xffffff;
this.mi = mi & 0xffffff;
this.hi = hi & 0xffff;
}
MlInt64.prototype.caml_custom = "_j";
MlInt64.prototype.copy =
function(){return new MlInt64(this.lo, this.mi, this.hi);};
MlInt64.prototype.ucompare =
function(x){
if(this.hi > x.hi) return 1;
if(this.hi < x.hi) return - 1;
if(this.mi > x.mi) return 1;
if(this.mi < x.mi) return - 1;
if(this.lo > x.lo) return 1;
if(this.lo < x.lo) return - 1;
return 0;
};
MlInt64.prototype.compare =
function(x){
var hi = this.hi << 16, xhi = x.hi << 16;
if(hi > xhi) return 1;
if(hi < xhi) return - 1;
if(this.mi > x.mi) return 1;
if(this.mi < x.mi) return - 1;
if(this.lo > x.lo) return 1;
if(this.lo < x.lo) return - 1;
return 0;
};
MlInt64.prototype.neg =
function(){
var
lo = - this.lo,
mi = - this.mi + (lo >> 24),
hi = - this.hi + (mi >> 24);
return new MlInt64(lo, mi, hi);
};
MlInt64.prototype.add =
function(x){
var
lo = this.lo + x.lo,
mi = this.mi + x.mi + (lo >> 24),
hi = this.hi + x.hi + (mi >> 24);
return new MlInt64(lo, mi, hi);
};
MlInt64.prototype.sub =
function(x){
var
lo = this.lo - x.lo,
mi = this.mi - x.mi + (lo >> 24),
hi = this.hi - x.hi + (mi >> 24);
return new MlInt64(lo, mi, hi);
};
MlInt64.prototype.mul =
function(x){
var
lo = this.lo * x.lo,
mi = (lo * caml_int64_offset | 0) + this.mi * x.lo + this.lo * x.mi,
hi =
(mi * caml_int64_offset | 0) + this.hi * x.lo + this.mi * x.mi
+ this.lo * x.hi;
return new MlInt64(lo, mi, hi);
};
MlInt64.prototype.isZero =
function(){return (this.lo | this.mi | this.hi) == 0;};
MlInt64.prototype.isNeg = function(){return this.hi << 16 < 0;};
MlInt64.prototype.and =
function(x){
return new MlInt64(this.lo & x.lo, this.mi & x.mi, this.hi & x.hi);
};
MlInt64.prototype.or =
function(x){
return new MlInt64(this.lo | x.lo, this.mi | x.mi, this.hi | x.hi);
};
MlInt64.prototype.xor =
function(x){
return new MlInt64(this.lo ^ x.lo, this.mi ^ x.mi, this.hi ^ x.hi);
};
MlInt64.prototype.shift_left =
function(s){
s = s & 63;
if(s == 0) return this;
if(s < 24)
return new
MlInt64
(this.lo << s,
this.mi << s | this.lo >> 24 - s,
this.hi << s | this.mi >> 24 - s);
if(s < 48)
return new
MlInt64
(0, this.lo << s - 24, this.mi << s - 24 | this.lo >> 48 - s);
return new MlInt64(0, 0, this.lo << s - 48);
};
MlInt64.prototype.shift_right_unsigned =
function(s){
s = s & 63;
if(s == 0) return this;
if(s < 24)
return new
MlInt64
(this.lo >> s | this.mi << 24 - s,
this.mi >> s | this.hi << 24 - s,
this.hi >> s);
if(s < 48)
return new
MlInt64
(this.mi >> s - 24 | this.hi << 48 - s, this.hi >> s - 24, 0);
return new MlInt64(this.hi >> s - 48, 0, 0);
};
MlInt64.prototype.shift_right =
function(s){
s = s & 63;
if(s == 0) return this;
var h = this.hi << 16 >> 16;
if(s < 24)
return new
MlInt64
(this.lo >> s | this.mi << 24 - s,
this.mi >> s | h << 24 - s,
this.hi << 16 >> s >>> 16);
var sign = this.hi << 16 >> 31;
if(s < 48)
return new
MlInt64
(this.mi >> s - 24 | this.hi << 48 - s,
this.hi << 16 >> s - 24 >> 16,
sign & 0xffff);
return new MlInt64(this.hi << 16 >> s - 32, sign, sign);
};
MlInt64.prototype.lsl1 =
function(){
this.hi = this.hi << 1 | this.mi >> 23;
this.mi = (this.mi << 1 | this.lo >> 23) & 0xffffff;
this.lo = this.lo << 1 & 0xffffff;
};
MlInt64.prototype.lsr1 =
function(){
this.lo = (this.lo >>> 1 | this.mi << 23) & 0xffffff;
this.mi = (this.mi >>> 1 | this.hi << 23) & 0xffffff;
this.hi = this.hi >>> 1;
};
MlInt64.prototype.udivmod =
function(x){
var
offset = 0,
modulus = this.copy(),
divisor = x.copy(),
quotient = new MlInt64(0, 0, 0);
while(modulus.ucompare(divisor) > 0){offset++; divisor.lsl1();}
while(offset >= 0){
offset--;
quotient.lsl1();
if(modulus.ucompare(divisor) >= 0){
quotient.lo++;
modulus = modulus.sub(divisor);
}
divisor.lsr1();
}
return {quotient: quotient, modulus: modulus};
};
MlInt64.prototype.div =
function(y){
var x = this;
if(y.isZero()) caml_raise_zero_divide();
var sign = x.hi ^ y.hi;
if(x.hi & 0x8000) x = x.neg();
if(y.hi & 0x8000) y = y.neg();
var q = x.udivmod(y).quotient;
if(sign & 0x8000) q = q.neg();
return q;
};
MlInt64.prototype.mod =
function(y){
var x = this;
if(y.isZero()) caml_raise_zero_divide();
var sign = x.hi;
if(x.hi & 0x8000) x = x.neg();
if(y.hi & 0x8000) y = y.neg();
var r = x.udivmod(y).modulus;
if(sign & 0x8000) r = r.neg();
return r;
};
MlInt64.prototype.toInt = function(){return this.lo | this.mi << 24;};
MlInt64.prototype.toFloat =
function(){
return (this.hi << 16) * Math.pow(2, 32) + this.mi * Math.pow(2, 24)
+ this.lo;
};
MlInt64.prototype.toArray =
function(){
return [this.hi >> 8,
this.hi & 0xff,
this.mi >> 16,
this.mi >> 8 & 0xff,
this.mi & 0xff,
this.lo >> 16,
this.lo >> 8 & 0xff,
this.lo & 0xff];
};
MlInt64.prototype.lo32 =
function(){return this.lo | (this.mi & 0xff) << 24;};
MlInt64.prototype.hi32 =
function(){return this.mi >>> 8 & 0xffff | this.hi << 16;};
function caml_int64_of_int32(x){
return new MlInt64(x & 0xffffff, x >> 24 & 0xffffff, x >> 31 & 0xffff);
}
function caml_int64_to_int32(x){return x.toInt();}
function caml_int64_is_negative(x){return + x.isNeg();}
function caml_int64_neg(x){return x.neg();}
function caml_jsbytes_of_string(x){return x;}
function jsoo_sys_getenv(n){
var process = globalThis.process;
if(process && process.env && process.env[n] != undefined)
return process.env[n];
if(globalThis.jsoo_static_env && globalThis.jsoo_static_env[n])
return globalThis.jsoo_static_env[n];
}
var caml_record_backtrace_flag = 0;
(function(){
var r = jsoo_sys_getenv("OCAMLRUNPARAM");
if(r !== undefined){
var l = r.split(",");
for(var i = 0; i < l.length; i++)
if(l[i] == "b"){
caml_record_backtrace_flag = 1;
break;
}
else if(l[i].startsWith("b="))
caml_record_backtrace_flag = + l[i].slice(2);
else
continue;
}
}
());
function caml_exn_with_js_backtrace(exn, force){
if(! exn.js_error || force || exn[0] == 248)
exn.js_error = new globalThis.Error("Js exception containing backtrace");
return exn;
}
function caml_maybe_attach_backtrace(exn, force){
return caml_record_backtrace_flag
? caml_exn_with_js_backtrace(exn, force)
: exn;
}
function caml_raise_with_arg(tag, arg){
throw caml_maybe_attach_backtrace([0, tag, arg]);
}
function caml_string_of_jsbytes(x){return x;}
function caml_raise_with_string(tag, msg){
caml_raise_with_arg(tag, caml_string_of_jsbytes(msg));
}
function caml_invalid_argument(msg){
caml_raise_with_string(caml_global_data.Invalid_argument, msg);
}
function caml_parse_format(fmt){
fmt = caml_jsbytes_of_string(fmt);
var len = fmt.length;
if(len > 31) caml_invalid_argument("format_int: format too long");
var
f =
{justify: "+",
signstyle: "-",
filler: " ",
alternate: false,
base: 0,
signedconv: false,
width: 0,
uppercase: false,
sign: 1,
prec: - 1,
conv: "f"};
for(var i = 0; i < len; i++){
var c = fmt.charAt(i);
switch(c){
case "-":
f.justify = "-"; break;
case "+":
case " ":
f.signstyle = c; break;
case "0":
f.filler = "0"; break;
case "#":
f.alternate = true; break;
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
f.width = 0;
while(c = fmt.charCodeAt(i) - 48, c >= 0 && c <= 9){f.width = f.width * 10 + c; i++;}
i--;
break;
case ".":
f.prec = 0;
i++;
while(c = fmt.charCodeAt(i) - 48, c >= 0 && c <= 9){f.prec = f.prec * 10 + c; i++;}
i--;
case "d":
case "i":
f.signedconv = true;
case "u":
f.base = 10; break;
case "x":
f.base = 16; break;
case "X":
f.base = 16; f.uppercase = true; break;
case "o":
f.base = 8; break;
case "e":
case "f":
case "g":
f.signedconv = true; f.conv = c; break;
case "E":
case "F":
case "G":
f.signedconv = true;
f.uppercase = true;
f.conv = c.toLowerCase();
break;
}
}
return f;
}
function caml_finish_formatting(f, rawbuffer){
if(f.uppercase) rawbuffer = rawbuffer.toUpperCase();
var len = rawbuffer.length;
if(f.signedconv && (f.sign < 0 || f.signstyle != "-")) len++;
if(f.alternate){if(f.base == 8) len += 1; if(f.base == 16) len += 2;}
var buffer = "";
if(f.justify == "+" && f.filler == " ")
for(var i = len; i < f.width; i++) buffer += " ";
if(f.signedconv)
if(f.sign < 0)
buffer += "-";
else if(f.signstyle != "-") buffer += f.signstyle;
if(f.alternate && f.base == 8) buffer += "0";
if(f.alternate && f.base == 16) buffer += f.uppercase ? "0X" : "0x";
if(f.justify == "+" && f.filler == "0")
for(var i = len; i < f.width; i++) buffer += "0";
buffer += rawbuffer;
if(f.justify == "-") for(var i = len; i < f.width; i++) buffer += " ";
return caml_string_of_jsbytes(buffer);
}
function caml_int64_format(fmt, x){
var f = caml_parse_format(fmt);
if(f.signedconv && caml_int64_is_negative(x)){f.sign = - 1; x = caml_int64_neg(x);}
var
buffer = "",
wbase = caml_int64_of_int32(f.base),
cvtbl = "0123456789abcdef";
do{
var p = x.udivmod(wbase);
x = p.quotient;
buffer = cvtbl.charAt(caml_int64_to_int32(p.modulus)) + buffer;
}
while
(! caml_int64_is_zero(x));
if(f.prec >= 0){
f.filler = " ";
var n = f.prec - buffer.length;
if(n > 0) buffer = caml_str_repeat(n, "0") + buffer;
}
return caml_finish_formatting(f, buffer);
}
function caml_expm1_float(x){return Math.expm1(x);}
function caml_ml_condition_broadcast(t){return 0;}
function jsoo_is_ascii(s){
if(s.length < 24){
for(var i = 0; i < s.length; i++) if(s.charCodeAt(i) > 127) return false;
return true;
}
else
return ! /[^\x00-\x7f]/.test(s);
}
function caml_utf16_of_utf8(s){
for(var b = "", t = "", c, c1, c2, v, i = 0, l = s.length; i < l; i++){
c1 = s.charCodeAt(i);
if(c1 < 0x80){
for(var j = i + 1; j < l && (c1 = s.charCodeAt(j)) < 0x80; j++) ;
if(j - i > 512){
t.substr(0, 1);
b += t;
t = "";
b += s.slice(i, j);
}
else
t += s.slice(i, j);
if(j == l) break;
i = j;
}
v = 1;
if(++i < l && ((c2 = s.charCodeAt(i)) & - 64) == 128){
c = c2 + (c1 << 6);
if(c1 < 0xe0){
v = c - 0x3080;
if(v < 0x80) v = 1;
}
else{
v = 2;
if(++i < l && ((c2 = s.charCodeAt(i)) & - 64) == 128){
c = c2 + (c << 6);
if(c1 < 0xf0){
v = c - 0xe2080;
if(v < 0x800 || v >= 0xd7ff && v < 0xe000) v = 2;
}
else{
v = 3;
if(++i < l && ((c2 = s.charCodeAt(i)) & - 64) == 128 && c1 < 0xf5){
v = c2 - 0x3c82080 + (c << 6);
if(v < 0x10000 || v > 0x10ffff) v = 3;
}
}
}
}
}
if(v < 4){
i -= v;
t += "\ufffd";
}
else if(v > 0xffff)
t += String.fromCharCode(0xd7c0 + (v >> 10), 0xdc00 + (v & 0x3FF));
else
t += String.fromCharCode(v);
if(t.length > 1024){t.substr(0, 1); b += t; t = "";}
}
return b + t;
}
function caml_jsstring_of_string(s){
if(jsoo_is_ascii(s)) return s;
return caml_utf16_of_utf8(s);
}
function fs_node_supported(){
return typeof globalThis.process !== "undefined"
&& typeof globalThis.process.versions !== "undefined"
&& typeof globalThis.process.versions.node !== "undefined";
}
function make_path_is_absolute(){
function posix(path){
if(path.charAt(0) === "/") return ["", path.substring(1)];
return;
}
function win32(path){
var
splitDeviceRe =
/^([a-zA-Z]:|[\\/]{2}[^\\/]+[\\/]+[^\\/]+)?([\\/])?([\s\S]*?)$/,
result = splitDeviceRe.exec(path),
device = result[1] || "",
isUnc = Boolean(device && device.charAt(1) !== ":");
if(Boolean(result[2] || isUnc)){
var root = result[1] || "", sep = result[2] || "";
return [root, path.substring(root.length + sep.length)];
}
return;
}
return fs_node_supported() && globalThis.process
&& globalThis.process.platform
? globalThis.process.platform === "win32" ? win32 : posix
: posix;
}
var path_is_absolute = make_path_is_absolute();
function caml_trailing_slash(name){
return name.slice(- 1) !== "/" ? name + "/" : name;
}
if(fs_node_supported() && globalThis.process && globalThis.process.cwd)
var caml_current_dir = globalThis.process.cwd().replace(/\\/g, "/");
else
var caml_current_dir = "/static";
caml_current_dir = caml_trailing_slash(caml_current_dir);
function caml_make_path(name){
name = caml_jsstring_of_string(name);
if(! path_is_absolute(name)) name = caml_current_dir + name;
var
comp0 = path_is_absolute(name),
comp = comp0[1].split("/"),
ncomp = [];
for(var i = 0; i < comp.length; i++)
switch(comp[i]){
case "..":
if(ncomp.length > 1) ncomp.pop(); break;
case ".": break;
case "": break;
default: ncomp.push(comp[i]); break;
}
ncomp.unshift(comp0[0]);
ncomp.orig = name;
return ncomp;
}
function caml_utf8_of_utf16(s){
for(var b = "", t = b, c, d, i = 0, l = s.length; i < l; i++){
c = s.charCodeAt(i);
if(c < 0x80){
for(var j = i + 1; j < l && (c = s.charCodeAt(j)) < 0x80; j++) ;
if(j - i > 512){
t.substr(0, 1);
b += t;
t = "";
b += s.slice(i, j);
}
else
t += s.slice(i, j);
if(j == l) break;
i = j;
}
if(c < 0x800){
t += String.fromCharCode(0xc0 | c >> 6);
t += String.fromCharCode(0x80 | c & 0x3f);
}
else if(c < 0xd800 || c >= 0xdfff)
t +=
String.fromCharCode
(0xe0 | c >> 12, 0x80 | c >> 6 & 0x3f, 0x80 | c & 0x3f);
else if
(c >= 0xdbff || i + 1 == l || (d = s.charCodeAt(i + 1)) < 0xdc00
|| d > 0xdfff)
t += "\xef\xbf\xbd";
else{
i++;
c = (c << 10) + d - 0x35fdc00;
t +=
String.fromCharCode
(0xf0 | c >> 18,
0x80 | c >> 12 & 0x3f,
0x80 | c >> 6 & 0x3f,
0x80 | c & 0x3f);
}
if(t.length > 1024){t.substr(0, 1); b += t; t = "";}
}
return b + t;
}
function caml_string_of_jsstring(s){
return jsoo_is_ascii(s)
? caml_string_of_jsbytes(s)
: caml_string_of_jsbytes(caml_utf8_of_utf16(s));
}
var
unix_error =
["E2BIG",
"EACCES",
"EAGAIN",
"EBADF",
"EBUSY",
"ECHILD",
"EDEADLK",
"EDOM",
"EEXIST",
"EFAULT",
"EFBIG",
"EINTR",
"EINVAL",
"EIO",
"EISDIR",
"EMFILE",
"EMLINK",
"ENAMETOOLONG",
"ENFILE",
"ENODEV",
"ENOENT",
"ENOEXEC",
"ENOLCK",
"ENOMEM",
"ENOSPC",
"ENOSYS",
"ENOTDIR",
"ENOTEMPTY",
"ENOTTY",
"ENXIO",
"EPERM",
"EPIPE",
"ERANGE",
"EROFS",
"ESPIPE",
"ESRCH",
"EXDEV",
"EWOULDBLOCK",
"EINPROGRESS",
"EALREADY",
"ENOTSOCK",
"EDESTADDRREQ",
"EMSGSIZE",
"EPROTOTYPE",
"ENOPROTOOPT",
"EPROTONOSUPPORT",
"ESOCKTNOSUPPORT",
"EOPNOTSUPP",
"EPFNOSUPPORT",
"EAFNOSUPPORT",
"EADDRINUSE",
"EADDRNOTAVAIL",
"ENETDOWN",
"ENETUNREACH",
"ENETRESET",
"ECONNABORTED",
"ECONNRESET",
"ENOBUFS",
"EISCONN",
"ENOTCONN",
"ESHUTDOWN",
"ETOOMANYREFS",
"ETIMEDOUT",
"ECONNREFUSED",
"EHOSTDOWN",
"EHOSTUNREACH",
"ELOOP",
"EOVERFLOW"];
function make_unix_err_args(code, syscall, path, errno){
var variant = unix_error.indexOf(code);
if(variant < 0){if(errno == null) errno = - 9999; variant = [0, errno];}
var
args =
[variant,
caml_string_of_jsstring(syscall || ""),
caml_string_of_jsstring(path || "")];
return args;
}
var caml_named_values = {};
function caml_named_value(nm){return caml_named_values[nm];}
function caml_raise_with_args(tag, args){
throw caml_maybe_attach_backtrace([0, tag].concat(args));
}
function caml_subarray_to_jsbytes(a, i, len){
var f = String.fromCharCode;
if(i == 0 && len <= 4096 && len == a.length) return f.apply(null, a);
var s = "";
for(; 0 < len; i += 1024, len -= 1024)
s += f.apply(null, a.slice(i, i + Math.min(len, 1024)));
return s;
}
function caml_convert_string_to_bytes(s){
if(s.t == 2)
s.c += caml_str_repeat(s.l - s.c.length, "\0");
else
s.c = caml_subarray_to_jsbytes(s.c, 0, s.c.length);
s.t = 0;
}
function MlBytes(tag, contents, length){
this.t = tag;
this.c = contents;
this.l = length;
}
MlBytes.prototype.toString =
function(){
switch(this.t){
case 9:
return this.c;
default: caml_convert_string_to_bytes(this);
case 0:
if(jsoo_is_ascii(this.c)){this.t = 9; return this.c;} this.t = 8;
case 8:
return this.c;
}
};
MlBytes.prototype.toUtf16 =
function(){
var r = this.toString();
if(this.t == 9) return r;
return caml_utf16_of_utf8(r);
};
MlBytes.prototype.slice =
function(){
var content = this.t == 4 ? this.c.slice() : this.c;
return new MlBytes(this.t, content, this.l);
};
function caml_is_ml_bytes(s){return s instanceof MlBytes;}
function caml_is_ml_string(s){
return typeof s === "string" && ! /[^\x00-\xff]/.test(s);
}
function caml_bytes_of_array(a){
if(! (a instanceof Uint8Array)) a = new Uint8Array(a);
return new MlBytes(4, a, a.length);
}
function caml_bytes_of_jsbytes(s){return new MlBytes(0, s, s.length);}
function caml_bytes_of_string(s){
return caml_bytes_of_jsbytes(caml_jsbytes_of_string(s));
}
function caml_raise_sys_error(msg){
caml_raise_with_string(caml_global_data.Sys_error, msg);
}
function caml_raise_no_such_file(name){
caml_raise_sys_error(name + ": No such file or directory");
}
function caml_convert_bytes_to_array(s){
var a = new Uint8Array(s.l), b = s.c, l = b.length, i = 0;
for(; i < l; i++) a[i] = b.charCodeAt(i);
for(l = s.l; i < l; i++) a[i] = 0;
s.c = a;
s.t = 4;
return a;
}
function caml_uint8_array_of_bytes(s){
if(s.t != 4) caml_convert_bytes_to_array(s);
return s.c;
}
function caml_create_bytes(len){
if(len < 0) caml_invalid_argument("Bytes.create");
return new MlBytes(len ? 2 : 9, "", len);
}
function caml_ml_bytes_length(s){return s.l;}
function caml_blit_bytes(s1, i1, s2, i2, len){
if(len == 0) return 0;
if(i2 == 0 && (len >= s2.l || s2.t == 2 && len >= s2.c.length)){
s2.c =
s1.t == 4
? caml_subarray_to_jsbytes(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 : 2;
}
else if(s2.t == 2 && i2 == s2.c.length){
s2.c +=
s1.t == 4
? caml_subarray_to_jsbytes(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 : 2;
}
else{
if(s2.t != 4) caml_convert_bytes_to_array(s2);
var c1 = s1.c, c2 = s2.c;
if(s1.t == 4)
if(i2 <= i1)
for(var i = 0; i < len; i++) c2[i2 + i] = c1[i1 + i];
else
for(var i = len - 1; i >= 0; 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;
}
function MlFile(){}
function MlFakeFile(content){this.data = content;}
MlFakeFile.prototype = new MlFile();
MlFakeFile.prototype.constructor = MlFakeFile;
MlFakeFile.prototype.truncate =
function(len){
var old = this.data;
this.data = caml_create_bytes(len | 0);
caml_blit_bytes(old, 0, this.data, 0, len);
};
MlFakeFile.prototype.length =
function(){return caml_ml_bytes_length(this.data);};
MlFakeFile.prototype.write =
function(offset, buf, pos, len){
var clen = this.length();
if(offset + len >= clen){
var new_str = caml_create_bytes(offset + len), old_data = this.data;
this.data = new_str;
caml_blit_bytes(old_data, 0, this.data, 0, clen);
}
caml_blit_bytes(caml_bytes_of_array(buf), pos, this.data, offset, len);
return 0;
};
MlFakeFile.prototype.read =
function(offset, buf, pos, len){
var clen = this.length();
if(offset + len >= clen) len = clen - offset;
if(len){
var data = caml_create_bytes(len | 0);
caml_blit_bytes(this.data, offset, data, 0, len);
buf.set(caml_uint8_array_of_bytes(data), pos);
}
return len;
};
function MlFakeFd(name, file, flags){
this.file = file;
this.name = name;
this.flags = flags;
}
MlFakeFd.prototype.err_closed =
function(){
caml_raise_sys_error(this.name + ": file descriptor already closed");
};
MlFakeFd.prototype.length =
function(){if(this.file) return this.file.length(); this.err_closed();};
MlFakeFd.prototype.write =
function(offset, buf, pos, len){
if(this.file) return this.file.write(offset, buf, pos, len);
this.err_closed();
};
MlFakeFd.prototype.read =
function(offset, buf, pos, len){
if(this.file) return this.file.read(offset, buf, pos, len);
this.err_closed();
};
MlFakeFd.prototype.close = function(){this.file = undefined;};
function MlFakeDevice(root, f){
this.content = {};
this.root = root;
this.lookupFun = f;
}
MlFakeDevice.prototype.nm = function(name){return this.root + name;};
MlFakeDevice.prototype.create_dir_if_needed =
function(name){
var comp = name.split("/"), res = "";
for(var i = 0; i < comp.length - 1; i++){
res += comp[i] + "/";
if(this.content[res]) continue;
this.content[res] = Symbol("directory");
}
};
MlFakeDevice.prototype.slash =
function(name){return /\/$/.test(name) ? name : name + "/";};
MlFakeDevice.prototype.lookup =
function(name){
if(! this.content[name] && this.lookupFun){
var
res =
this.lookupFun
(caml_string_of_jsbytes(this.root), caml_string_of_jsbytes(name));
if(res !== 0){
this.create_dir_if_needed(name);
this.content[name] = new MlFakeFile(caml_bytes_of_string(res[1]));
}
}
};
MlFakeDevice.prototype.exists =
function(name){
if(name == "") return 1;
var name_slash = this.slash(name);
if(this.content[name_slash]) return 1;
this.lookup(name);
return this.content[name] ? 1 : 0;
};
MlFakeDevice.prototype.isFile =
function(name){return this.exists(name) && ! this.is_dir(name) ? 1 : 0;};
MlFakeDevice.prototype.mkdir =
function(name, mode, raise_unix){
var unix_error = raise_unix && caml_named_value("Unix.Unix_error");
if(this.exists(name))
if(unix_error)
caml_raise_with_args
(unix_error, make_unix_err_args("EEXIST", "mkdir", this.nm(name)));
else
caml_raise_sys_error(name + ": File exists");
var parent = /^(.*)\/[^/]+/.exec(name);
parent = parent && parent[1] || "";
if(! this.exists(parent))
if(unix_error)
caml_raise_with_args
(unix_error, make_unix_err_args("ENOENT", "mkdir", this.nm(parent)));
else
caml_raise_sys_error(parent + ": No such file or directory");
if(! this.is_dir(parent))
if(unix_error)
caml_raise_with_args
(unix_error, make_unix_err_args("ENOTDIR", "mkdir", this.nm(parent)));
else
caml_raise_sys_error(parent + ": Not a directory");
this.create_dir_if_needed(this.slash(name));
};
MlFakeDevice.prototype.rmdir =
function(name, raise_unix){
var
unix_error = raise_unix && caml_named_value("Unix.Unix_error"),
name_slash = name == "" ? "" : this.slash(name),
r = new RegExp("^" + name_slash + "([^/]+)");
if(! this.exists(name))
if(unix_error)
caml_raise_with_args
(unix_error, make_unix_err_args("ENOENT", "rmdir", this.nm(name)));
else
caml_raise_sys_error(name + ": No such file or directory");
if(! this.is_dir(name))
if(unix_error)
caml_raise_with_args
(unix_error, make_unix_err_args("ENOTDIR", "rmdir", this.nm(name)));
else
caml_raise_sys_error(name + ": Not a directory");
for(var n in this.content)
if(n.match(r))
if(unix_error)
caml_raise_with_args
(unix_error, make_unix_err_args("ENOTEMPTY", "rmdir", this.nm(name)));
else
caml_raise_sys_error(this.nm(name) + ": Directory not empty");
delete this.content[name_slash];
};
MlFakeDevice.prototype.readdir =
function(name){
var name_slash = name == "" ? "" : this.slash(name);
if(! this.exists(name))
caml_raise_sys_error(name + ": No such file or directory");
if(! this.is_dir(name)) caml_raise_sys_error(name + ": Not a directory");
var r = new RegExp("^" + name_slash + "([^/]+)"), seen = {}, a = [];
for(var n in this.content){
var m = n.match(r);
if(m && ! seen[m[1]]){seen[m[1]] = true; a.push(m[1]);}
}
return a;
};
MlFakeDevice.prototype.opendir =
function(name, raise_unix){
var
unix_error = raise_unix && caml_named_value("Unix.Unix_error"),
a = this.readdir(name),
c = false,
i = 0;
return {readSync:
function(){
if(c)
if(unix_error)
caml_raise_with_args
(unix_error,
make_unix_err_args("EBADF", "closedir", this.nm(name)));
else
caml_raise_sys_error(name + ": closedir failed");
if(i == a.length) return null;
var entry = a[i];
i++;
return {name: entry};
},
closeSync:
function(){
if(c)
if(unix_error)
caml_raise_with_args
(unix_error,
make_unix_err_args("EBADF", "closedir", this.nm(name)));
else
caml_raise_sys_error(name + ": closedir failed");
c = true;
a = [];
}};
};
MlFakeDevice.prototype.is_dir =
function(name){
if(name == "") return true;
var name_slash = this.slash(name);
return this.content[name_slash] ? 1 : 0;
};
MlFakeDevice.prototype.unlink =
function(name){
var ok = this.content[name] ? true : false;
delete this.content[name];
return ok;
};
MlFakeDevice.prototype.open =
function(name, f){
var file;
if(f.rdonly && f.wronly)
caml_raise_sys_error
(this.nm(name)
+ " : flags Open_rdonly and Open_wronly are not compatible");
if(f.text && f.binary)
caml_raise_sys_error
(this.nm(name)
+ " : flags Open_text and Open_binary are not compatible");
this.lookup(name);
if(this.content[name]){
if(this.is_dir(name))
caml_raise_sys_error(this.nm(name) + " : is a directory");
if(f.create && f.excl)
caml_raise_sys_error(this.nm(name) + " : file already exists");
file = this.content[name];
if(f.truncate) file.truncate();
}
else if(f.create){
this.create_dir_if_needed(name);
this.content[name] = new MlFakeFile(caml_create_bytes(0));
file = this.content[name];
}
else
caml_raise_no_such_file(this.nm(name));
return new MlFakeFd(this.nm(name), file, f);
};
MlFakeDevice.prototype.open =
function(name, f){
var file;
if(f.rdonly && f.wronly)
caml_raise_sys_error
(this.nm(name)
+ " : flags Open_rdonly and Open_wronly are not compatible");
if(f.text && f.binary)
caml_raise_sys_error
(this.nm(name)
+ " : flags Open_text and Open_binary are not compatible");
this.lookup(name);
if(this.content[name]){
if(this.is_dir(name))
caml_raise_sys_error(this.nm(name) + " : is a directory");
if(f.create && f.excl)
caml_raise_sys_error(this.nm(name) + " : file already exists");
file = this.content[name];
if(f.truncate) file.truncate();
}
else if(f.create){
this.create_dir_if_needed(name);
this.content[name] = new MlFakeFile(caml_create_bytes(0));
file = this.content[name];
}
else
caml_raise_no_such_file(this.nm(name));
return new MlFakeFd(this.nm(name), file, f);
};
MlFakeDevice.prototype.register =
function(name, content){
var file;
if(this.content[name])
caml_raise_sys_error(this.nm(name) + " : file already exists");
if(caml_is_ml_bytes(content)) file = new MlFakeFile(content);
if(caml_is_ml_string(content))
file = new MlFakeFile(caml_bytes_of_string(content));
else if(content instanceof Array)
file = new MlFakeFile(caml_bytes_of_array(content));
else if(typeof content === "string")
file = new MlFakeFile(caml_bytes_of_jsbytes(content));
else if(content.toString){
var
bytes =
caml_bytes_of_string(caml_string_of_jsstring(content.toString()));
file = new MlFakeFile(bytes);
}
if(file){
this.create_dir_if_needed(name);
this.content[name] = file;
}
else
caml_raise_sys_error
(this.nm(name) + " : registering file with invalid content type");
};
MlFakeDevice.prototype.constructor = MlFakeDevice;
function caml_ml_string_length(s){return s.length;}
function caml_string_unsafe_get(s, i){return s.charCodeAt(i);}
function caml_uint8_array_of_string(s){
var l = caml_ml_string_length(s), a = new Array(l), i = 0;
for(; i < l; i++) a[i] = caml_string_unsafe_get(s, i);
return a;
}
function caml_bytes_bound_error(){
caml_invalid_argument("index out of bounds");
}
function caml_bytes_unsafe_set(s, i, c){
c &= 0xff;
if(s.t != 4){
if(i == s.c.length){
s.c += String.fromCharCode(c);
if(i + 1 == s.l) s.t = 0;
return 0;
}
caml_convert_bytes_to_array(s);
}
s.c[i] = c;
return 0;
}
function caml_bytes_set(s, i, c){
if(i >>> 0 >= s.l) caml_bytes_bound_error();
return caml_bytes_unsafe_set(s, i, c);
}
function MlNodeFd(fd, flags){
this.fs = require("fs");
this.fd = fd;
this.flags = flags;
}
MlNodeFd.prototype = new MlFile();
MlNodeFd.prototype.constructor = MlNodeFd;
MlNodeFd.prototype.truncate =
function(len){
try{this.fs.ftruncateSync(this.fd, len | 0);}
catch(err){caml_raise_sys_error(err.toString());}
};
MlNodeFd.prototype.length =
function(){
try{return this.fs.fstatSync(this.fd).size;}
catch(err){caml_raise_sys_error(err.toString());}
};
MlNodeFd.prototype.write =
function(offset, buf, buf_offset, len){
try{
if(this.flags.isCharacterDevice)
this.fs.writeSync(this.fd, buf, buf_offset, len);
else
this.fs.writeSync(this.fd, buf, buf_offset, len, offset);
}
catch(err){caml_raise_sys_error(err.toString());}
return 0;
};
MlNodeFd.prototype.read =
function(offset, a, buf_offset, len){
try{
if(this.flags.isCharacterDevice)
var read = this.fs.readSync(this.fd, a, buf_offset, len);
else
var read = this.fs.readSync(this.fd, a, buf_offset, len, offset);
return read;
}
catch(err){caml_raise_sys_error(err.toString());}
};
MlNodeFd.prototype.close =
function(){
try{this.fs.closeSync(this.fd); return 0;}
catch(err){caml_raise_sys_error(err.toString());}
};
function MlNodeDevice(root){this.fs = require("fs"); this.root = root;}
MlNodeDevice.prototype.nm = function(name){return this.root + name;};
MlNodeDevice.prototype.exists =
function(name){
try{return this.fs.existsSync(this.nm(name)) ? 1 : 0;}
catch(err){return 0;}
};
MlNodeDevice.prototype.isFile =
function(name){
try{return this.fs.statSync(this.nm(name)).isFile() ? 1 : 0;}
catch(err){caml_raise_sys_error(err.toString());}
};
MlNodeDevice.prototype.mkdir =
function(name, mode, raise_unix){
try{this.fs.mkdirSync(this.nm(name), {mode: mode}); return 0;}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.rmdir =
function(name, raise_unix){
try{this.fs.rmdirSync(this.nm(name)); return 0;}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.readdir =
function(name, raise_unix){
try{return this.fs.readdirSync(this.nm(name));}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.is_dir =
function(name){
try{return this.fs.statSync(this.nm(name)).isDirectory() ? 1 : 0;}
catch(err){caml_raise_sys_error(err.toString());}
};
MlNodeDevice.prototype.unlink =
function(name, raise_unix){
try{
var b = this.fs.existsSync(this.nm(name)) ? 1 : 0;
this.fs.unlinkSync(this.nm(name));
return b;
}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.open =
function(name, f, raise_unix){
var consts = require("constants"), res = 0;
for(var key in f)
switch(key){
case "rdonly":
res |= consts.O_RDONLY; break;
case "wronly":
res |= consts.O_WRONLY; break;
case "append":
res |= consts.O_WRONLY | consts.O_APPEND; break;
case "create":
res |= consts.O_CREAT; break;
case "truncate":
res |= consts.O_TRUNC; break;
case "excl":
res |= consts.O_EXCL; break;
case "binary":
res |= consts.O_BINARY; break;
case "text":
res |= consts.O_TEXT; break;
case "nonblock":
res |= consts.O_NONBLOCK; break;
}
try{
var
fd = this.fs.openSync(this.nm(name), res),
isCharacterDevice =
this.fs.lstatSync(this.nm(name)).isCharacterDevice();
f.isCharacterDevice = isCharacterDevice;
return new MlNodeFd(fd, f);
}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.rename =
function(o, n, raise_unix){
try{this.fs.renameSync(this.nm(o), this.nm(n));}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.stat =
function(name, raise_unix){
try{
var js_stats = this.fs.statSync(this.nm(name));
return this.stats_from_js(js_stats);
}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.lstat =
function(name, raise_unix){
try{
var js_stats = this.fs.lstatSync(this.nm(name));
return this.stats_from_js(js_stats);
}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.symlink =
function(to_dir, target, path, raise_unix){
try{
this.fs.symlinkSync
(this.nm(target), this.nm(path), to_dir ? "dir" : "file");
return 0;
}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.readlink =
function(name, raise_unix){
try{
var link = this.fs.readlinkSync(this.nm(name), "utf8");
return caml_string_of_jsstring(link);
}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.opendir =
function(name, raise_unix){
try{return this.fs.opendirSync(this.nm(name));}
catch(err){this.raise_nodejs_error(err, raise_unix);}
};
MlNodeDevice.prototype.raise_nodejs_error =
function(err, raise_unix){
var unix_error = caml_named_value("Unix.Unix_error");
if(raise_unix && unix_error){
var
args = make_unix_err_args(err.code, err.syscall, err.path, err.errno);
caml_raise_with_args(unix_error, args);
}
else
caml_raise_sys_error(err.toString());
};
MlNodeDevice.prototype.stats_from_js =
function(js_stats){
var file_kind;
if(js_stats.isFile())
file_kind = 0;
else if(js_stats.isDirectory())
file_kind = 1;
else if(js_stats.isCharacterDevice())
file_kind = 2;
else if(js_stats.isBlockDevice())
file_kind = 3;
else if(js_stats.isSymbolicLink())
file_kind = 4;
else if(js_stats.isFIFO())
file_kind = 5;
else if(js_stats.isSocket()) file_kind = 6;
return [0,
js_stats.dev,
js_stats.ino,
file_kind,
js_stats.mode,
js_stats.nlink,
js_stats.uid,
js_stats.gid,
js_stats.rdev,
js_stats.size,
js_stats.atimeMs,
js_stats.mtimeMs,
js_stats.ctimeMs];
};
MlNodeDevice.prototype.constructor = MlNodeDevice;
function caml_get_root(path){
var x = path_is_absolute(path);
if(! x) return;
return x[0] + "/";
}
function caml_failwith(msg){
if(! caml_global_data.Failure)
caml_global_data.Failure = [248, caml_string_of_jsbytes("Failure"), - 3];
caml_raise_with_string(caml_global_data.Failure, msg);
}
var
caml_root =
caml_get_root(caml_current_dir)
|| caml_failwith("unable to compute caml_root"),
jsoo_mount_point = [];
if(fs_node_supported())
jsoo_mount_point.push
({path: caml_root, device: new MlNodeDevice(caml_root)});
else
jsoo_mount_point.push
({path: caml_root, device: new MlFakeDevice(caml_root)});
jsoo_mount_point.push
({path: "/static/", device: new MlFakeDevice("/static/")});
function resolve_fs_device(name){
var
path = caml_make_path(name),
name = path.join("/"),
name_slash = caml_trailing_slash(name),
res;
for(var i = 0; i < jsoo_mount_point.length; i++){
var m = jsoo_mount_point[i];
if
(name_slash.search(m.path) == 0
&& (! res || res.path.length < m.path.length))
res =
{path: m.path,
device: m.device,
rest: name.substring(m.path.length, name.length)};
}
if(! res && fs_node_supported()){
var root = caml_get_root(name);
if(root && root.match(/^[a-zA-Z]:\/$/)){
var m = {path: root, device: new MlNodeDevice(root)};
jsoo_mount_point.push(m);
res =
{path: m.path,
device: m.device,
rest: name.substring(m.path.length, name.length)};
}
}
if(res) return res;
caml_raise_sys_error("no device found for " + name_slash);
}
function caml_sys_is_directory(name){
var root = resolve_fs_device(name), a = root.device.is_dir(root.rest);
return a ? 1 : 0;
}
function caml_raise_not_found(){
caml_raise_constant(caml_global_data.Not_found);
}
function caml_sys_getenv(name){
var r = jsoo_sys_getenv(caml_jsstring_of_string(name));
if(r === undefined) caml_raise_not_found();
return caml_string_of_jsstring(r);
}
function shift_right_nat(nat1, ofs1, len1, nat2, ofs2, nbits){
if(nbits == 0){nat2.data[ofs2] = 0; return 0;}
var wrap = 0;
for(var i = len1 - 1; i >= 0; i--){
var a = nat1.data[ofs1 + i] >>> 0;
nat1.data[ofs1 + i] = a >>> nbits | wrap;
wrap = a << 32 - nbits;
}
nat2.data[ofs2] = wrap;
return 0;
}
var caml_gr_state;
function caml_gr_state_get(){
if(caml_gr_state) return caml_gr_state;
throw caml_maybe_attach_backtrace
([0,
caml_named_value("Graphics.Graphic_failure"),
caml_string_of_jsbytes("Not initialized")]);
}
function caml_gr_point_color(x, y){
var
s = caml_gr_state_get(),
im = s.context.getImageData(x, s.height - y, 1, 1),
d = im.data;
return (d[0] << 16) + (d[1] << 8) + d[2];
}
function caml_runtime_events_user_resolve(){return 0;}
var MlObjectTable;
if(typeof globalThis.Map === "undefined")
MlObjectTable =
function(){
function NaiveLookup(objs){this.objs = objs;}
NaiveLookup.prototype.get =
function(v){
for(var i = 0; i < this.objs.length; i++)
if(this.objs[i] === v) return i;
};
NaiveLookup.prototype.set = function(){};
return function(){
this.objs = [];
this.lookup = new NaiveLookup(this.objs);};
}
();
else
MlObjectTable =
function(){this.objs = []; this.lookup = new globalThis.Map();};
MlObjectTable.prototype.store =
function(v){this.lookup.set(v, this.objs.length); this.objs.push(v);};
MlObjectTable.prototype.recall =
function(v){
var i = this.lookup.get(v);
return i === undefined ? undefined : this.objs.length - i;
};
function caml_sys_rename(o, n){
var o_root = resolve_fs_device(o), n_root = resolve_fs_device(n);
if(o_root.device != n_root.device)
caml_failwith("caml_sys_rename: cannot move file between two filesystem");
if(! o_root.device.rename)
caml_failwith("caml_sys_rename: no implemented");
o_root.device.rename(o_root.rest, n_root.rest);
}
function caml_log10_float(x){return Math.log10(x);}
var caml_runtime_warnings = 0;
function caml_ml_enable_runtime_warnings(bool){caml_runtime_warnings = bool; return 0;
}
function caml_classify_float(x){
if(isFinite(x)){
if(Math.abs(x) >= 2.2250738585072014e-308) return 0;
if(x != 0) return 1;
return 2;
}
return isNaN(x) ? 4 : 3;
}
var caml_ml_channels = new Array();
function caml_refill(chan){
if(chan.refill != null){
var str = chan.refill(), str_a = caml_uint8_array_of_string(str);
if(str_a.length == 0)
chan.refill = null;
else{
if(chan.buffer.length < chan.buffer_max + str_a.length){
var b = new Uint8Array(chan.buffer_max + str_a.length);
b.set(chan.buffer);
chan.buffer = b;
}
chan.buffer.set(str_a, chan.buffer_max);
chan.offset += str_a.length;
chan.buffer_max += str_a.length;
}
}
else{
var
nread =
chan.file.read
(chan.offset,
chan.buffer,
chan.buffer_max,
chan.buffer.length - chan.buffer_max);
chan.offset += nread;
chan.buffer_max += nread;
}
}
function caml_array_bound_error(){
caml_invalid_argument("index out of bounds");
}
function caml_ml_input_scan_line(chanid){
var chan = caml_ml_channels[chanid], p = chan.buffer_curr;
do
if(p >= chan.buffer_max){
if(chan.buffer_curr > 0){
chan.buffer.set(chan.buffer.subarray(chan.buffer_curr), 0);
p -= chan.buffer_curr;
chan.buffer_max -= chan.buffer_curr;
chan.buffer_curr = 0;
}
if(chan.buffer_max >= chan.buffer.length) return - chan.buffer_max | 0;
var prev_max = chan.buffer_max;
caml_refill(chan);
if(prev_max == chan.buffer_max) return - chan.buffer_max | 0;
}
while
(chan.buffer[p++] != 10);
return p - chan.buffer_curr | 0;
}
function caml_gc_minor(unit){
if(typeof globalThis.gc == "function") globalThis.gc(true);
return 0;
}
function caml_ml_condition_new(unit){return {condition: 1};}
function caml_int64_of_bytes(a){
return new
MlInt64
(a[7] << 0 | a[6] << 8 | a[5] << 16,
a[4] << 0 | a[3] << 8 | a[2] << 16,
a[1] << 0 | a[0] << 8);
}
function caml_ba_uint8_get64(ba, i0){
var ofs = ba.offset(i0);
if(ofs + 7 >= ba.data.length) caml_array_bound_error();
var
b1 = ba.get(ofs + 0),
b2 = ba.get(ofs + 1),
b3 = ba.get(ofs + 2),
b4 = ba.get(ofs + 3),
b5 = ba.get(ofs + 4),
b6 = ba.get(ofs + 5),
b7 = ba.get(ofs + 6),
b8 = ba.get(ofs + 7);
return caml_int64_of_bytes([b8, b7, b6, b5, b4, b3, b2, b1]);
}
function caml_int64_to_bytes(x){return x.toArray();}
function caml_int64_marshal(writer, v, sizes){
var b = caml_int64_to_bytes(v);
for(var i = 0; i < 8; i++) writer.write(8, b[i]);
sizes[0] = 8;
sizes[1] = 8;
}
function caml_ba_num_dims(ba){return ba.dims.length;}
function caml_wrap_exception(e){
{
if(e instanceof Array) return e;
var exn;
if
(globalThis.RangeError && e instanceof globalThis.RangeError
&& e.message
&& e.message.match(/maximum call stack/i))
exn = caml_global_data.Stack_overflow;
else if
(globalThis.InternalError && e instanceof globalThis.InternalError
&& e.message
&& e.message.match(/too much recursion/i))
exn = caml_global_data.Stack_overflow;
else if(e instanceof globalThis.Error && caml_named_value("jsError"))
exn = [0, caml_named_value("jsError"), e];
else
exn = [0, caml_global_data.Failure, caml_string_of_jsstring(String(e))];
if(e instanceof globalThis.Error) exn.js_error = e;
return exn;
}
}
function caml_create_file(name, content){
var root = resolve_fs_device(name);
if(! root.device.register) caml_failwith("cannot register file");
root.device.register(root.rest, content);
return 0;
}
function jsoo_create_file(name, content){
var
name = caml_string_of_jsbytes(name),
content = caml_string_of_jsbytes(content);
return caml_create_file(name, content);
}
function caml_fs_init(){
var tmp = globalThis.caml_fs_tmp;
if(tmp)
for(var i = 0; i < tmp.length; i++)
jsoo_create_file(tmp[i].name, tmp[i].content);
globalThis.jsoo_create_file = jsoo_create_file;
globalThis.caml_fs_tmp = [];
return 0;
}
function caml_get_continuation_callstack(){return [0];}
var caml_parser_trace = 0;
function caml_set_parser_trace(bool){
var oldflag = caml_parser_trace;
caml_parser_trace = bool;
return oldflag;
}
function caml_list_of_js_array(a){
var l = 0;
for(var i = a.length - 1; i >= 0; i--){var e = a[i]; l = [0, e, l];}
return l;
}
function caml_mul(a, b){return Math.imul(a, b);}
function caml_hash_mix_int(h, d){
d = caml_mul(d, 0xcc9e2d51 | 0);
d = d << 15 | d >>> 32 - 15;
d = caml_mul(d, 0x1b873593);
h ^= d;
h = h << 13 | h >>> 32 - 13;
return (h + (h << 2) | 0) + (0xe6546b64 | 0) | 0;
}
function num_digits_nat(nat, ofs, len){
for(var i = len - 1; i >= 0; i--) if(nat.data[ofs + i] != 0) return i + 1;
return 1;
}
function caml_hash_nat(x){
var len = num_digits_nat(x, 0, x.data.length), h = 0;
for(var i = 0; i < len; i++) h = caml_hash_mix_int(h, x.data[i]);
return h;
}
function caml_call_gen(f, args){
var
n = f.l >= 0 ? f.l : f.l = f.length,
argsLen = args.length,
d = n - argsLen;
if(d == 0)