2 // http://www.ocsigen.org/js_of_ocaml/
3 // Copyright (C) 2010 Jérôme Vouillon
4 // Laboratoire PPS - CNRS Université Paris Diderot
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, with linking exception;
9 // either version 2.1 of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 //Provides: caml_js_pure_expr const
23 function caml_js_pure_expr (f
) { return f(); }
25 //Provides: caml_js_set
26 function caml_js_set(o
,f
,v
) { o
[f
]=v
; }
27 //Provides: caml_js_get mutable
28 function caml_js_get(o
,f
) { return o
[f
]; }
30 //Provides: caml_js_instanceof
31 function caml_js_instanceof(o
,c
) { return o
instanceof c
; }
33 //Provides: caml_js_typeof
34 function caml_js_typeof(o
) { return typeof o
; }
36 //Provides: caml_js_on_ie const
37 function caml_js_on_ie () {
38 var ua
= window
.navigator
?window
.navigator
.userAgent
:"";
39 return ua
.indexOf("MSIE") != -1 && ua
.indexOf("Opera") != 0;
42 //Provides: caml_js_html_escape const
43 var caml_js_regexps
= { amp
:/&/g, lt:/</g, quot:/\"/g, all:/[&<\"]/ };
44 function caml_js_html_escape (s
) {
45 if (!caml_js_regexps
.all
.test(s
)) return s
;
46 return s
.replace(caml_js_regexps
.amp
, "&")
47 .replace(caml_js_regexps
.lt
, "<")
48 .replace(caml_js_regexps
.quot
, """);
51 /////////// Debugging console
52 //Provides: caml_js_get_console const
53 function caml_js_get_console () {
54 var c
= window
.console
?window
.console
:{};
55 var m
= ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
56 "trace", "group", "groupCollapsed", "groupEnd", "time", "timeEnd"];
58 for (var i
= 0; i
< m
.length
; i
++) if (!c
[m
[i
]]) c
[m
[i
]]=f
;