Skip to content

Commit 865249e

Browse files
authored
Drop old compatibility with IE (#1774)
1 parent be85e6f commit 865249e

File tree

11 files changed

+24
-116
lines changed

11 files changed

+24
-116
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Test: use dune test stanzas (#1631)
66
* Merged Wasm_of_ocaml (#1724)
77
* Lib: removed no longer relevant Js.optdef type annotations (#1769)
8+
* Misc: drop support for IE
89

910
## Bug fixes
1011
* Fix small bug in global data flow analysis (#1768)

compiler/lib/js_output.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,14 @@ struct
543543
let c = s.[i] in
544544
match c with
545545
| '\000' when i = l - 1 || not (Char.is_num s.[i + 1]) -> Buffer.add_string b "\\0"
546-
| '\b' -> Buffer.add_string b "\\b"
547-
| '\t' -> Buffer.add_string b "\\t"
548-
| '\n' -> Buffer.add_string b "\\n"
549-
(* This escape sequence is not supported by IE < 9
550-
| '\011' -> "\\v"
551-
*)
546+
| '\b' (* 008 *) -> Buffer.add_string b "\\b"
547+
| '\t' (* 009 *) -> Buffer.add_string b "\\t"
548+
| '\n' (* 010 *) -> Buffer.add_string b "\\n"
549+
| '\011' -> Buffer.add_string b "\\v"
552550
| '\012' -> Buffer.add_string b "\\f"
551+
| '\r' (* 013 *) -> Buffer.add_string b "\\r"
553552
(* https://github.com/ocsigen/js_of_ocaml/issues/898 *)
554553
| '/' when i > 0 && Char.equal s.[i - 1] '<' -> Buffer.add_string b "\\/"
555-
| '\r' -> Buffer.add_string b "\\r"
556554
| '\000' .. '\031' | '\127' ->
557555
Buffer.add_string b "\\x";
558556
Buffer.add_char_hex b c

compiler/tests-js-parser/run.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ let normalize_string s =
7070
| '\b' -> Buffer.add_string b "\\b"
7171
| '\t' -> Buffer.add_string b "\\t"
7272
| '\n' -> Buffer.add_string b "\\n"
73-
(* This escape sequence is not supported by IE < 9
74-
| '\011' -> "\\v"
75-
*)
73+
| '\011' -> Buffer.add_string b "\\v"
7674
| '\012' -> Buffer.add_string b "\\f"
7775
(* https://github.com/ocsigen/js_of_ocaml/issues/898 *)
7876
| '/' when i > 0 && Char.equal s.[i - 1] '<' -> Buffer.add_string b "\\/"

lib/js_of_ocaml/dom.ml

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ class type ['a] event = object
281281

282282
method currentTarget : 'a t opt readonly_prop
283283

284+
method preventDefault : unit meth
285+
284286
(* Legacy methods *)
285287
method srcElement : 'a t opt readonly_prop
286288
end
@@ -293,55 +295,27 @@ end
293295

294296
let no_handler : ('a, 'b) event_listener = Js.null
295297

296-
let window_event () : 'a #event t = Js.Unsafe.pure_js_expr "event"
297-
298298
(* The function preventDefault must be called explicitly when
299299
using addEventListener... *)
300300
let handler f =
301301
Js.some
302302
(Js.Unsafe.callback (fun e ->
303-
(* depending on the internet explorer version, e can be null or undefined. *)
304-
if not (Js.Opt.test (some e))
305-
then (
306-
let e = window_event () in
307-
let res = f e in
308-
if not (Js.to_bool res) then e##.returnValue := res;
309-
res)
310-
else
311-
let res = f e in
312-
if not (Js.to_bool res) then (Js.Unsafe.coerce e)##preventDefault;
313-
res))
303+
let res = f e in
304+
if not (Js.to_bool res) then e##preventDefault;
305+
res))
314306

315307
let full_handler f =
316308
Js.some
317309
(Js.Unsafe.meth_callback (fun this e ->
318-
(* depending on the internet explorer version, e can be null or undefined *)
319-
if not (Js.Opt.test (some e))
320-
then (
321-
let e = window_event () in
322-
let res = f this e in
323-
if not (Js.to_bool res) then e##.returnValue := res;
324-
res)
325-
else
326-
let res = f this e in
327-
if not (Js.to_bool res) then (Js.Unsafe.coerce e)##preventDefault;
328-
res))
310+
let res = f this e in
311+
if not (Js.to_bool res) then e##preventDefault;
312+
res))
329313

330314
let invoke_handler (f : ('a, 'b) event_listener) (this : 'a) (event : 'b) : bool t =
331315
Js.Unsafe.call f this [| Js.Unsafe.inject event |]
332316

333317
let eventTarget (e : (< .. > as 'a) #event t) : 'a t =
334-
let target =
335-
Opt.get e##.target (fun () -> Opt.get e##.srcElement (fun () -> raise Not_found))
336-
in
337-
if Js.instanceof target Js.Unsafe.global##._Node
338-
then
339-
(* Workaround for Safari bug *)
340-
let target' : node Js.t = Js.Unsafe.coerce target in
341-
if target'##.nodeType == TEXT
342-
then Js.Unsafe.coerce (Opt.get target'##.parentNode (fun () -> assert false))
343-
else target
344-
else target
318+
Opt.get e##.target (fun () -> Opt.get e##.srcElement (fun () -> raise Not_found))
345319

346320
module Event = struct
347321
type 'a typ = Js.js_string Js.t
@@ -384,10 +358,7 @@ let addEventListener (e : (< .. > as 'a) t) typ h capt =
384358

385359
let removeEventListener id = id ()
386360

387-
let preventDefault ev =
388-
if Js.Optdef.test (Js.Unsafe.coerce ev)##.preventDefault (* IE hack *)
389-
then (Js.Unsafe.coerce ev)##preventDefault
390-
else (Js.Unsafe.coerce ev)##.returnValue := Js.bool false
361+
let preventDefault ev = ev##preventDefault
391362

392363
let createCustomEvent ?bubbles ?cancelable ?detail typ =
393364
let opt_iter f = function
@@ -407,8 +378,6 @@ let createCustomEvent ?bubbles ?cancelable ?detail typ =
407378
in
408379
new%js constr typ opts
409380

410-
(* IE < 9 *)
411-
412381
class type stringList = object
413382
method item : int -> js_string t opt meth
414383

lib/js_of_ocaml/dom.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ class type ['a] event = object
292292

293293
method currentTarget : 'a t opt readonly_prop
294294

295+
method preventDefault : unit meth
296+
295297
(* Legacy methods *)
296298
method srcElement : 'a t opt readonly_prop
297299
end

lib/js_of_ocaml/dom_html.ml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
open Js
2222
open! Import
2323

24-
external caml_js_on_ie : unit -> bool t = "caml_js_on_ie"
25-
26-
let onIE = Js.to_bool (caml_js_on_ie ())
27-
2824
external html_escape : js_string t -> js_string t = "caml_js_html_escape"
2925

3026
external html_entities : js_string t -> js_string t opt = "caml_js_html_entities"
@@ -2717,18 +2713,8 @@ let createCanvas doc : canvasElement t =
27172713
let html_element : htmlElement t constr = Js.Unsafe.global##._HTMLElement
27182714

27192715
module CoerceTo = struct
2720-
let element : #Dom.node Js.t -> element Js.t Js.opt =
2721-
if not (Js.Optdef.test (def html_element))
2722-
then
2723-
(* ie < 9 does not have HTMLElement: we have to cheat to check
2724-
that something is an html element *)
2725-
fun e ->
2726-
if not (Js.Optdef.test (def (Js.Unsafe.coerce e)##.innerHTML))
2727-
then Js.null
2728-
else Js.some (Js.Unsafe.coerce e)
2729-
else
2730-
fun e ->
2731-
if Js.instanceof e html_element then Js.some (Js.Unsafe.coerce e) else Js.null
2716+
let element (e : #Dom.node Js.t) : element Js.t Js.opt =
2717+
if Js.instanceof e html_element then Js.some (Js.Unsafe.coerce e) else Js.null
27322718

27332719
let unsafeCoerce tag (e : #element t) =
27342720
if Js.equals e##.tagName##toLowerCase (Js.string tag)

lib/js_of_ocaml/dom_html.mli

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,6 @@ and element = object
742742

743743
method offsetTop : int readonly_prop
744744

745-
(* Incorrect in IE until IE7 included *)
746745
method offsetParent : element t opt readonly_prop
747746

748747
method offsetWidth : int readonly_prop
@@ -925,7 +924,6 @@ class type selectElement = object ('self)
925924

926925
method _type : js_string t readonly_prop
927926

928-
(* Cannot be changed under IE *)
929927
method selectedIndex : int prop
930928

931929
method value : js_string t prop
@@ -942,7 +940,6 @@ class type selectElement = object ('self)
942940

943941
method name : js_string t readonly_prop
944942

945-
(* Cannot be changed under IE *)
946943
method size : int prop
947944

948945
method tabIndex : int prop
@@ -953,7 +950,6 @@ class type selectElement = object ('self)
953950

954951
method required : bool t writeonly_prop
955952

956-
(* Not supported by IE 9/Safari *)
957953
method onchange : ('self t, event t) event_listener prop
958954

959955
method oninput : ('self t, event t) event_listener prop
@@ -972,6 +968,7 @@ class type inputElement = object ('self)
972968

973969
method accessKey : js_string t prop
974970

971+
(* deprecated *)
975972
method align : js_string t prop
976973

977974
method alt : js_string t prop
@@ -984,12 +981,10 @@ class type inputElement = object ('self)
984981

985982
method name : js_string t readonly_prop
986983

987-
(* Cannot be changed under IE *)
988984
method readOnly : bool t prop
989985

990986
method required : bool t writeonly_prop
991987

992-
(* Not supported by IE 9/Safari *)
993988
method size : int prop
994989

995990
method src : js_string t prop
@@ -998,7 +993,7 @@ class type inputElement = object ('self)
998993

999994
method _type : js_string t readonly_prop
1000995

1001-
(* Cannot be changed under IE *)
996+
(* Deprecated *)
1002997
method useMap : js_string t prop
1003998

1004999
method value : js_string t prop
@@ -1009,7 +1004,6 @@ class type inputElement = object ('self)
10091004

10101005
method placeholder : js_string t writeonly_prop
10111006

1012-
(* Not supported by IE 9 *)
10131007
method selectionDirection : js_string t prop
10141008

10151009
method selectionStart : int prop
@@ -1042,7 +1036,6 @@ class type textAreaElement = object ('self)
10421036

10431037
method name : js_string t readonly_prop
10441038

1045-
(* Cannot be changed under IE *)
10461039
method readOnly : bool t prop
10471040

10481041
method rows : int prop
@@ -1057,17 +1050,14 @@ class type textAreaElement = object ('self)
10571050

10581051
method _type : js_string t readonly_prop
10591052

1060-
(* Cannot be changed under IE *)
10611053
method value : js_string t prop
10621054

10631055
method select : unit meth
10641056

10651057
method required : bool t writeonly_prop
10661058

1067-
(* Not supported by IE 9/Safari *)
10681059
method placeholder : js_string t writeonly_prop
10691060

1070-
(* Not supported by IE 9 *)
10711061
method onselect : ('self t, event t) event_listener prop
10721062

10731063
method onchange : ('self t, event t) event_listener prop
@@ -1090,12 +1080,10 @@ class type buttonElement = object
10901080

10911081
method name : js_string t readonly_prop
10921082

1093-
(* Cannot be changed under IE *)
10941083
method tabIndex : int prop
10951084

10961085
method _type : js_string t readonly_prop
10971086

1098-
(* Cannot be changed under IE *)
10991087
method value : js_string t prop
11001088
end
11011089

@@ -3226,8 +3214,6 @@ val _requestAnimationFrame : (unit -> unit) Js.callback -> unit
32263214

32273215
val decode_html_entities : js_string t -> js_string t
32283216

3229-
val onIE : bool
3230-
32313217
val hasPushState : unit -> bool
32323218

32333219
val hasPlaceholder : unit -> bool

lib/js_of_ocaml/js_of_ocaml_stubs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ void caml_js_html_escape () {
2424
caml_fatal_error("Unimplemented Javascript primitive caml_js_html_escape!");
2525
}
2626

27-
void caml_js_on_ie () {
28-
caml_fatal_error("Unimplemented Javascript primitive caml_js_on_ie!");
29-
}
30-
3127
void caml_uint8_array_of_bytes () {
3228
caml_fatal_error("Unimplemented Javascript primitive caml_uint8_array_of_bytes!");
3329
}

lib/lwt/lwt_xmlHttpRequest.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,7 @@ let perform_raw
221221
req##.onreadystatechange :=
222222
Js.wrap_callback (fun _ ->
223223
match req##.readyState with
224-
(* IE doesn't have the same semantics for HEADERS_RECEIVED.
225-
so we wait til LOADING to check headers. See:
226-
http://msdn.microsoft.com/en-us/library/ms534361(v=vs.85).aspx *)
227-
| HEADERS_RECEIVED when not Dom_html.onIE -> ignore (do_check_headers ())
228-
| LOADING when Dom_html.onIE -> ignore (do_check_headers ())
224+
| HEADERS_RECEIVED -> ignore (do_check_headers ())
229225
| DONE ->
230226
(* If we didn't catch a previous event, we check the header. *)
231227
if do_check_headers ()

runtime/js/jslib_js_of_ocaml.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919

2020
///////////// Jslib: code specific to Js_of_ocaml
2121

22-
//Provides: caml_js_on_ie const
23-
function caml_js_on_ie() {
24-
var ua =
25-
globalThis.navigator && globalThis.navigator.userAgent
26-
? globalThis.navigator.userAgent
27-
: "";
28-
return ua.indexOf("MSIE") !== -1 && ua.indexOf("Opera") !== 0;
29-
}
30-
3122
//Provides: caml_js_html_escape const (const)
3223
var caml_js_regexps = { amp: /&/g, lt: /</g, quot: /"/g, all: /[&<"]/ };
3324
function caml_js_html_escape(s) {
@@ -86,17 +77,6 @@ function caml_xmlhttprequest_create(unit) {
8677
return new globalThis.XMLHttpRequest();
8778
} catch (e) {}
8879
}
89-
if (typeof globalThis.activeXObject !== "undefined") {
90-
try {
91-
return new globalThis.activeXObject("Msxml2.XMLHTTP");
92-
} catch (e) {}
93-
try {
94-
return new globalThis.activeXObject("Msxml3.XMLHTTP");
95-
} catch (e) {}
96-
try {
97-
return new globalThis.activeXObject("Microsoft.XMLHTTP");
98-
} catch (e) {}
99-
}
10080
caml_failwith("Cannot create a XMLHttpRequest");
10181
}
10282

0 commit comments

Comments
 (0)