123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848(* Js_of_ocaml library
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2010 Jérôme Vouillon
* Laboratoire PPS - CNRS Université Paris Diderot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)open!Import(* This local module [Js] is needed so that the ppx_js extension work within that file. *)moduleJs=structtype+'attype(-'a,+'b)meth_callbackmoduleUnsafe=structtypetoptypeany=topttypeany_js_array=anyexternalinject:'a->any="%identity"externalcoerce:_t->_t="%identity"externalget:'a->'b->'c="caml_js_get"externalset:'a->'b->'c->unit="caml_js_set"externaldelete:'a->'b->unit="caml_js_delete"externalcall:'a->'b->anyarray->'c="caml_js_call"externalfun_call:'a->anyarray->'b="caml_js_fun_call"externalmeth_call:'a->string->anyarray->'b="caml_js_meth_call"externalnew_obj:'a->anyarray->'b="caml_js_new"externalnew_obj_arr:'a->any_js_array->'b="caml_ojs_new_arr"externalobj:(string*any)array->'a="caml_js_object"externalequals:'a->'b->bool="caml_js_equals"externalstrict_equals:'a->'b->bool="caml_js_strict_equals"externalpure_expr:(unit->'a)->'a="caml_js_pure_expr"externaleval_string:string->'a="caml_js_eval_string"externaljs_expr:string->'a="caml_js_expr"externalpure_js_expr:string->'a="caml_pure_js_expr"letglobal=pure_js_expr"globalThis"externalcallback:('a->'b)->('c,'a->'b)meth_callback="caml_js_wrap_callback_unsafe"externalcallback_with_arguments:(any_js_array->'b)->('c,any_js_array->'b)meth_callback="caml_js_wrap_callback_arguments"externalcallback_with_arity:int->('a->'b)->('c,'a->'b)meth_callback="caml_js_wrap_callback_strict"externalmeth_callback:('b->'a)->('b,'a)meth_callback="caml_js_wrap_meth_callback_unsafe"externalmeth_callback_with_arity:int->('b->'a)->('b,'a)meth_callback="caml_js_wrap_meth_callback_strict"externalmeth_callback_with_arguments:('b->any_js_array->'a)->('b,any_js_array->'a)meth_callback="caml_js_wrap_meth_callback_arguments"(* DEPRECATED *)externalvariable:string->'a="caml_js_var"end(****)type'aopt='atype'aoptdef='aexternaldebugger:unit->unit="debugger"letnull:'aopt=Unsafe.pure_js_expr"null"externalsome:'a->'aopt="%identity"letundefined:'aoptdef=Unsafe.pure_js_expr"undefined"externaldef:'a->'aoptdef="%identity"moduletypeOPT=sigtype'atvalempty:'atvalreturn:'a->'atvalmap:'at->('a->'b)->'btvalbind:'at->('a->'bt)->'btvaltest:'at->boolvaliter:'at->('a->unit)->unitvalcase:'at->(unit->'b)->('a->'b)->'bvalget:'at->(unit->'a)->'avaloption:'aoption->'atvalto_option:'at->'aoptionexternalequals:_t->_t->bool="caml_js_equals"externalstrict_equals:_t->_t->bool="caml_js_strict_equals"endmoduleOpt:OPTwithtype'at='aopt=structtype'at='aoptletempty=nullletreturn=someexternalequals:_t->_t->bool="caml_js_equals"externalstrict_equals:_t->_t->bool="caml_js_strict_equals"letmapxf=ifequalsxnullthennullelsereturn(fx)letbindxf=ifequalsxnullthennullelsefxlettestx=not(equalsxnull)letiterxf=ifnot(equalsxnull)thenfxletcasexfg=ifequalsxnullthenf()elsegxletgetxf=ifequalsxnullthenf()elsexletoptionx=matchxwith|None->empty|Somex->returnxletto_optionx=casex(fun()->None)(funx->Somex)endmoduleOptdef:OPTwithtype'at='aoptdef=structtype'at='aoptdefletempty=undefinedletreturn=defexternalequals:_t->_t->bool="caml_js_equals"externalstrict_equals:_t->_t->bool="caml_js_strict_equals"letmapxf=ifstrict_equalsxundefinedthenundefinedelsereturn(fx)letbindxf=ifstrict_equalsxundefinedthenundefinedelsefxlettestx=not(strict_equalsxundefined)letiterxf=ifnot(strict_equalsxundefined)thenfxletcasexfg=ifstrict_equalsxundefinedthenf()elsegxletgetxf=ifstrict_equalsxundefinedthenf()elsexletoptionx=matchxwith|None->empty|Somex->returnxletto_optionx=casex(fun()->None)(funx->Somex)end(****)letcoercexfg=Opt.get(fx)(fun()->gx)letcoerce_optxfg=Opt.get(Opt.bindxf)(fun()->gx)(****)type+'amethtype+'agen_proptype'areadonly_prop=<get:'a>gen_proptype'awriteonly_prop=<set:'a->unit>gen_proptype'aprop=<get:'a;set:'a->unit>gen_proptype'aoptdef_prop=<get:'aoptdef;set:'a->unit>gen_proptype+'aconstr(****)type'acallback=(unit,'a)meth_callbackexternalwrap_callback:('a->'b)->('c,'a->'b)meth_callback="caml_js_wrap_callback"externalwrap_meth_callback:('a->'b)->('a,'b)meth_callback="caml_js_wrap_meth_callback"(****)externalequals:_t->_t->bool="caml_js_equals"externalstrict_equals:_t->_t->bool="caml_js_strict_equals"(****)let_true=Unsafe.pure_js_expr"true"let_false=Unsafe.pure_js_expr"false"typematch_result_handletypestring_arrayclasstypenumber=objectmethodtoString:js_stringtmethmethodtoString_radix:int->js_stringtmethmethodtoLocaleString:js_stringtmethmethodtoFixed:int->js_stringtmethmethodtoExponential:js_stringtmethmethodtoExponential_digits:int->js_stringtmethmethodtoPrecision:int->js_stringtmethendandjs_string=objectmethodtoString:js_stringtmethmethodvalueOf:js_stringtmethmethodcharAt:int->js_stringtmethmethodcharCodeAt:int->numbertmeth(* This may return NaN... *)methodconcat:js_stringt->js_stringtmethmethodconcat_2:js_stringt->js_stringt->js_stringtmethmethodconcat_3:js_stringt->js_stringt->js_stringt->js_stringtmethmethodconcat_4:js_stringt->js_stringt->js_stringt->js_stringt->js_stringtmethmethodindexOf:js_stringt->intmethmethodindexOf_from:js_stringt->int->intmethmethodlastIndexOf:js_stringt->intmethmethodlastIndexOf_from:js_stringt->int->intmethmethodlocaleCompare:js_stringt->numbertmethmethod_match:regExpt->match_result_handletoptmethmethodnormalize:js_stringtmethmethodnormalize_form:normalizationt->js_stringtmethmethodreplace:regExpt->js_stringt->js_stringtmethmethodreplace_string:js_stringt->js_stringt->js_stringtmethmethodsearch:regExpt->intmethmethodslice:int->int->js_stringtmethmethodslice_end:int->js_stringtmethmethodsplit:js_stringt->string_arraytmethmethodsplit_limited:js_stringt->int->string_arraytmethmethodsplit_regExp:regExpt->string_arraytmethmethodsplit_regExpLimited:regExpt->int->string_arraytmethmethodsubstring:int->int->js_stringtmethmethodsubstring_toEnd:int->js_stringtmethmethodtoLowerCase:js_stringtmethmethodtoLocaleLowerCase:js_stringtmethmethodtoUpperCase:js_stringtmethmethodtoLocaleUpperCase:js_stringtmethmethodtrim:js_stringtmethmethodlength:intreadonly_propendandregExp=objectmethodexec:js_stringt->match_result_handletoptmethmethodtest:js_stringt->booltmethmethodtoString:js_stringtmethmethodsource:js_stringtreadonly_propmethodglobal:booltreadonly_propmethodignoreCase:booltreadonly_propmethodmultiline:booltreadonly_propmethodlastIndex:intpropendandnormalization=js_stringtypenumber_t=numbert(* string is used by ppx_js, it needs to come before any use of the
new syntax in this file *)externalstring:string->js_stringt="caml_jsstring_of_string"externalto_string:js_stringt->string="caml_string_of_jsstring"letnfc=string"NFC"letnfd=string"NFD"letnfkc=string"NFKC"letnfkd=string"NFKD"endincludeJsclasstypestring_constr=objectmethodfromCharCode:int->js_stringtmethendletstring_constr=Unsafe.global##._StringletregExp=Unsafe.global##._RegExpletregExp_copy=regExpletregExp_withFlags=regExpclasstype['a]js_array=objectmethodtoString:js_stringtmethmethodtoLocaleString:js_stringtmethmethodconcat:'ajs_arrayt->'ajs_arraytmethmethodjoin:js_stringt->js_stringtmethmethodpop:'aoptdefmethmethodpush:'a->intmethmethodpush_2:'a->'a->intmethmethodpush_3:'a->'a->'a->intmethmethodpush_4:'a->'a->'a->'a->intmethmethodreverse:'ajs_arraytmethmethodshift:'aoptdefmethmethodslice:int->int->'ajs_arraytmethmethodslice_end:int->'ajs_arraytmethmethodsort:('a->'a->number_t)callback->'ajs_arraytmethmethodsort_asStrings:'ajs_arraytmethmethodsplice:int->int->'ajs_arraytmethmethodsplice_1:int->int->'a->'ajs_arraytmethmethodsplice_2:int->int->'a->'a->'ajs_arraytmethmethodsplice_3:int->int->'a->'a->'a->'ajs_arraytmethmethodsplice_4:int->int->'a->'a->'a->'a->'ajs_arraytmethmethodunshift:'a->intmethmethodunshift_2:'a->'a->intmethmethodunshift_3:'a->'a->'a->intmethmethodunshift_4:'a->'a->'a->'a->intmethmethodsome:('a->int->'ajs_arrayt->boolt)callback->booltmethmethodevery:('a->int->'ajs_arrayt->boolt)callback->booltmethmethodforEach:('a->int->'ajs_arrayt->unit)callback->unitmethmethodmap:('a->int->'ajs_arrayt->'b)callback->'bjs_arraytmethmethodfilter:('a->int->'ajs_arrayt->boolt)callback->'ajs_arraytmethmethodreduce_init:('b->'a->int->'ajs_arrayt->'b)callback->'b->'bmethmethodreduce:('a->'a->int->'ajs_arrayt->'a)callback->'amethmethodreduceRight_init:('b->'a->int->'ajs_arrayt->'b)callback->'b->'bmethmethodreduceRight:('a->'a->int->'ajs_arrayt->'a)callback->'amethmethodlength:intpropendletobject_constructor=Unsafe.global##._Objectletobject_keyso:js_stringtjs_arrayt=object_constructor##keysoletarray_constructor=Unsafe.global##._Arrayletarray_empty=array_constructorletarray_length=array_constructorletarray_get:'a#js_arrayt->int->'aoptdef=Unsafe.getletarray_set:'a#js_arrayt->int->'a->unit=Unsafe.setletarray_map_poly:'a#js_arrayt->('a->int->'a#js_arrayt->'b)callback->'b#js_arrayt=funacb->(Unsafe.coercea)##mapcbletarray_mapfa=array_map_polya(wrap_callback(funx_idx_->fx))letarray_mapifa=array_map_polya(wrap_callback(funxidx_->fidxx))classtypematch_result=objectinherit[js_stringt]js_arraymethodindex:intreadonly_propmethodinput:js_stringtreadonly_propendletstr_array:string_arrayt->js_stringtjs_arrayt=Unsafe.coerceletmatch_result:match_result_handlet->match_resultt=Unsafe.coerceclasstypedate=objectmethodtoString:js_stringtmethmethodtoDateString:js_stringtmethmethodtoTimeString:js_stringtmethmethodtoLocaleString:js_stringtmethmethodtoLocaleDateString:js_stringtmethmethodtoLocaleTimeString:js_stringtmethmethodvalueOf:number_tmethmethodgetTime:number_tmethmethodgetFullYear:intmethmethodgetUTCFullYear:intmethmethodgetMonth:intmethmethodgetUTCMonth:intmethmethodgetDate:intmethmethodgetUTCDate:intmethmethodgetDay:intmethmethodgetUTCDay:intmethmethodgetHours:intmethmethodgetUTCHours:intmethmethodgetMinutes:intmethmethodgetUTCMinutes:intmethmethodgetSeconds:intmethmethodgetUTCSeconds:intmethmethodgetMilliseconds:intmethmethodgetUTCMilliseconds:intmethmethodgetTimezoneOffset:intmethmethodsetTime:number_t->number_tmethmethodsetFullYear:int->number_tmethmethodsetUTCFullYear:int->number_tmethmethodsetMonth:int->number_tmethmethodsetUTCMonth:int->number_tmethmethodsetDate:int->number_tmethmethodsetUTCDate:int->number_tmethmethodsetDay:int->number_tmethmethodsetUTCDay:int->number_tmethmethodsetHours:int->number_tmethmethodsetUTCHours:int->number_tmethmethodsetMinutes:int->number_tmethmethodsetUTCMinutes:int->number_tmethmethodsetSeconds:int->number_tmethmethodsetUTCSeconds:int->number_tmethmethodsetMilliseconds:int->number_tmethmethodsetUTCMilliseconds:int->number_tmethmethodtoUTCString:js_stringtmethmethodtoISOString:js_stringtmethmethodtoJSON:'a->js_stringtmethendclasstypedate_constr=objectmethodparse:js_stringt->number_tmethmethod_UTC_month:int->int->number_tmethmethod_UTC_day:int->int->number_tmethmethod_UTC_hour:int->int->int->int->number_tmethmethod_UTC_min:int->int->int->int->int->number_tmethmethod_UTC_sec:int->int->int->int->int->int->number_tmethmethod_UTC_ms:int->int->int->int->int->int->int->number_tmethmethodnow:number_tmethendletdate_constr=Unsafe.global##._Dateletdate:date_constrt=date_constrletdate_now:datetconstr=date_constrletdate_fromTimeValue:(number_t->datet)constr=date_constrletdate_month:(int->int->datet)constr=date_constrletdate_day:(int->int->int->datet)constr=date_constrletdate_hour:(int->int->int->int->datet)constr=date_constrletdate_min:(int->int->int->int->int->datet)constr=date_constrletdate_sec:(int->int->int->int->int->int->datet)constr=date_constrletdate_ms:(int->int->int->int->int->int->int->datet)constr=date_constrclasstypemath=objectmethod_E:number_treadonly_propmethod_LN2:number_treadonly_propmethod_LN10:number_treadonly_propmethod_LOG2E:number_treadonly_propmethod_LOG10E:number_treadonly_propmethod_PI:number_treadonly_propmethod_SQRT1_2_:number_treadonly_propmethod_SQRT2:number_treadonly_propmethodabs:number_t->number_tmethmethodacos:number_t->number_tmethmethodasin:number_t->number_tmethmethodatan:number_t->number_tmethmethodatan2:number_t->number_t->number_tmethmethodceil:number_t->number_tmethmethodcos:number_t->number_tmethmethodexp:number_t->number_tmethmethodfloor:number_t->number_tmethmethodlog:number_t->number_tmethmethodmax:number_t->number_t->number_tmethmethodmax_3:number_t->number_t->number_t->number_tmethmethodmax_4:number_t->number_t->number_t->number_t->number_tmethmethodmin:number_t->number_t->number_tmethmethodmin_3:number_t->number_t->number_t->number_tmethmethodmin_4:number_t->number_t->number_t->number_t->number_tmethmethodpow:number_t->number_t->number_tmethmethodrandom:number_tmethmethodround:number_t->number_tmethmethodsin:number_t->number_tmethmethodsqrt:number_t->number_tmethmethodtan:number_t->number_tmethendletmath=Unsafe.global##._Mathclasstypeerror=objectmethodname:js_stringtpropmethodmessage:js_stringtpropmethodstack:js_stringtoptdefpropmethodtoString:js_stringtmethendleterror_constr=Unsafe.global##._ErrormoduleJs_error=structtypeerror_t=errortincludeJsoo_runtime.Errorexternalof_error:error_t->t="%identity"externalto_error:t->error_t="%identity"letnamee=to_string(to_errore)##.nameletmessagee=to_string(to_errore)##.messageletstack(e:t):stringoption=Opt.to_option(Opt.map(to_errore)##.stackto_string)letto_stringe=to_string(to_errore)##toStringendmoduleMagic=structmoduletypeT=sigexceptionErroroferrortendtype('a,'b)eq=Eq:('a,'a)eqlet(eq:(errort,Js_error.t)eq)=Obj.magicEqletm=matcheqwith|Eq->(modulestructexceptionError=Js_error.Exnend:T)moduleError=(valm:T)endincludeMagic.Errorletraise_js_errore=Js_error.raise_(Js_error.of_errore)letstring_of_errore=Js_error.to_string(Js_error.of_errore)letexn_with_js_backtrace=Js_error.attach_js_backtraceexternaljs_error_of_exn:exn->errortopt="caml_js_error_of_exception"classtypejson=objectmethodparse:js_stringt->'amethmethodstringify:'a->js_stringtmethendlet_JSON:jsont=Unsafe.global##._JSONletdecodeURI(s:js_stringt):js_stringt=Unsafe.fun_callUnsafe.global##.decodeURI[|Unsafe.injects|]letdecodeURIComponent(s:js_stringt):js_stringt=Unsafe.fun_callUnsafe.global##.decodeURIComponent[|Unsafe.injects|]letencodeURI(s:js_stringt):js_stringt=Unsafe.fun_callUnsafe.global##.encodeURI[|Unsafe.injects|]letencodeURIComponent(s:js_stringt):js_stringt=Unsafe.fun_callUnsafe.global##.encodeURIComponent[|Unsafe.injects|]letescape(s:js_stringt):js_stringt=Unsafe.fun_callUnsafe.global##.escape[|Unsafe.injects|]letunescape(s:js_stringt):js_stringt=Unsafe.fun_callUnsafe.global##.unescape[|Unsafe.injects|]externalbool:bool->boolt="caml_js_from_bool"externalto_bool:boolt->bool="caml_js_to_bool"externalarray:'aarray->'ajs_arrayt="caml_js_from_array"externalto_array:'ajs_arrayt->'aarray="caml_js_to_array"externalbytestring:string->js_stringt="caml_jsbytes_of_string"externalto_bytestring:js_stringt->string="caml_string_of_jsbytes"externalfloat:float->number_t="caml_js_from_float"externalto_float:number_t->float="caml_js_to_float"externalnumber_of_float:float->numbert="caml_js_from_float"externalfloat_of_number:numbert->float="caml_js_to_float"externalint32:int32->number_t="caml_js_from_int32"externalto_int32:number_t->int32="caml_js_to_int32"externalnativeint:nativeint->number_t="caml_js_from_nativeint"externalto_nativeint:number_t->nativeint="caml_js_to_nativeint"externaltypeof:_t->js_stringt="caml_js_typeof"externalinstanceof:_t->_constr->bool="caml_js_instanceof"letisNaN(i:'a):bool=to_bool(Unsafe.fun_callUnsafe.global##.isNaN[|Unsafe.injecti|])letparseInt(s:js_stringt):int=lets=Unsafe.fun_callUnsafe.global##.parseInt[|Unsafe.injects|]inifisNaNsthenfailwith"parseInt"elsesletparseFloat(s:js_stringt):number_t=lets=Unsafe.fun_callUnsafe.global##.parseFloat[|Unsafe.injects|]inifisNaNsthenfailwith"parseFloat"elseslet_=Printexc.register_printer(fune->ifinstanceof(Obj.magice:<..>t)error_constrthenlete=Js_error.of_error(Obj.magice:errort)inSome(Js_error.to_stringe)elsematchewith|Js_error.Exne->Some(Js_error.to_stringe)|_->None)letexport_js(field:js_stringt)x=Unsafe.set(Unsafe.pure_js_expr"jsoo_exports")field(ifString.equal(Js.to_string(typeof(Obj.magicx)))"function"(* function with arity/length equal to zero are already wrapped *)&&Unsafe.get(Obj.magicx)(Js.string"length")>0thenObj.magic(wrap_callback(Obj.magicx))elsex)letexportfieldx=export_js(stringfield)xletexport_allobj=letkeys=object_keysobjinkeys##forEach(wrap_callback(fun(key:js_stringt)__->export_jskey(Unsafe.getobjkey)))(****)(* DEPRECATED *)typefloat_prop=number_tprop