1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677(* 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##._JSONletinput_reviver=letreviver_this_key(value:Unsafe.any):Obj.t=iftypeofvalue==string"string"thenObj.repr(to_bytestring(Unsafe.coercevalue))elseifinstanceofvalueJs.array_empty&&(Unsafe.coercevalue)##.length==4&&Unsafe.getvalue0==255thenObj.repr(Jsoo_runtime.Int64.create_int64_lo_mi_hi(Unsafe.getvalue1)(Unsafe.getvalue2)(Unsafe.getvalue3))elseObj.reprvalueinwrap_meth_callbackreviverletunsafe_inputs=json##parse_sinput_reviverclasstypeobj=objectmethodconstructor:'a.'aconstrJs.readonly_propendletmlInt64_constr=letdummy_int64=1Linletdummy_obj:objt=Obj.magicdummy_int64indummy_obj##.constructorletoutput_reviver_key(value:Unsafe.any):Obj.t=ifObj.tag(Obj.reprvalue)=Obj.string_tagthenObj.repr(bytestring(Obj.magicvalue:string))elseifinstanceofvaluemlInt64_constrthenletvalue=Unsafe.coercevalueinObj.repr(array[|255;value##.lo;value##.mi;value##.hi|])elseObj.reprvalueletoutputobj=json##stringify_objoutput_reviver