12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091(* Js_of_ocaml library
* http://www.ocsigen.org/js_of_ocaml/
* Copyright Grégoire Henry 2010.
*
* 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.
*)openJsopen!Importclasstypejson=objectmethodparse:'a.js_stringt->'amethmethodparse_:'a'b'c'd.js_stringt->('bt,js_stringt->'c->'d)meth_callback->'amethmethodstringify:'a.'a->js_stringtmeth(* Beware that this is only works when the function argument
expects exactly two arguments (no curryfication is performed). *)methodstringify_:'a'b'c'd.'a->(js_stringt->'c->'d)->js_stringtmethendletjson:jsonJs.t=Unsafe.global##._JSONexternalunsafe_equals:'a->'b->bool="caml_js_equals"externalof_jsbytes:js_stringt->string="caml_string_of_jsbytes"externalto_jsbytes:'at->js_stringt="caml_jsbytes_of_string"externalcreate_int64_lo_mi_hi:int->int->int->Int64.t="caml_int64_create_lo_mi_hi"letinput_reviver=letreviver_this_key(value:Unsafe.any):Obj.t=ifunsafe_equals(typeofvalue)(typeof(string"foo"))thenObj.repr(of_jsbytes(Unsafe.coercevalue))elseifinstanceofvalueJs.array_empty&&(Unsafe.coercevalue)##.length==4&&Unsafe.getvalue0==255thenObj.repr(create_int64_lo_mi_hi(Unsafe.getvalue1)(Unsafe.getvalue2)(Unsafe.getvalue3))elseObj.reprvalueinwrap_meth_callbackreviverletunsafe_inputs=json##parse_sinput_reviverclasstypeobj=objectmethodconstructor:'a.'aconstrJs.readonly_propendletmlString_constr=letdummy_string=""inletdummy_obj:objt=Obj.magicdummy_stringindummy_obj##.constructorletmlInt64_constr=letdummy_int64=1Linletdummy_obj:objt=Obj.magicdummy_int64indummy_obj##.constructorletoutput_reviver_key(value:Unsafe.any):Obj.t=ifinstanceofvaluemlString_constrthenObj.repr(to_jsbytes(Unsafe.coercevalue))elseifinstanceofvaluemlInt64_constrthenletvalue=Unsafe.coercevalueinObj.repr(array[|255;value##.lo;value##.mi;value##.hi|])elseObj.reprvalueletoutputobj=json##stringify_objoutput_reviver