Skip to content

Commit

Permalink
Drop old compatibility with IE (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo authored Dec 17, 2024
1 parent be85e6f commit 865249e
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 116 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Test: use dune test stanzas (#1631)
* Merged Wasm_of_ocaml (#1724)
* Lib: removed no longer relevant Js.optdef type annotations (#1769)
* Misc: drop support for IE

## Bug fixes
* Fix small bug in global data flow analysis (#1768)
Expand Down
12 changes: 5 additions & 7 deletions compiler/lib/js_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -543,16 +543,14 @@ struct
let c = s.[i] in
match c with
| '\000' when i = l - 1 || not (Char.is_num s.[i + 1]) -> Buffer.add_string b "\\0"
| '\b' -> Buffer.add_string b "\\b"
| '\t' -> Buffer.add_string b "\\t"
| '\n' -> Buffer.add_string b "\\n"
(* This escape sequence is not supported by IE < 9
| '\011' -> "\\v"
*)
| '\b' (* 008 *) -> Buffer.add_string b "\\b"
| '\t' (* 009 *) -> Buffer.add_string b "\\t"
| '\n' (* 010 *) -> Buffer.add_string b "\\n"
| '\011' -> Buffer.add_string b "\\v"
| '\012' -> Buffer.add_string b "\\f"
| '\r' (* 013 *) -> Buffer.add_string b "\\r"
(* https://github.com/ocsigen/js_of_ocaml/issues/898 *)
| '/' when i > 0 && Char.equal s.[i - 1] '<' -> Buffer.add_string b "\\/"
| '\r' -> Buffer.add_string b "\\r"
| '\000' .. '\031' | '\127' ->
Buffer.add_string b "\\x";
Buffer.add_char_hex b c
Expand Down
4 changes: 1 addition & 3 deletions compiler/tests-js-parser/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ let normalize_string s =
| '\b' -> Buffer.add_string b "\\b"
| '\t' -> Buffer.add_string b "\\t"
| '\n' -> Buffer.add_string b "\\n"
(* This escape sequence is not supported by IE < 9
| '\011' -> "\\v"
*)
| '\011' -> Buffer.add_string b "\\v"
| '\012' -> Buffer.add_string b "\\f"
(* https://github.com/ocsigen/js_of_ocaml/issues/898 *)
| '/' when i > 0 && Char.equal s.[i - 1] '<' -> Buffer.add_string b "\\/"
Expand Down
51 changes: 10 additions & 41 deletions lib/js_of_ocaml/dom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ class type ['a] event = object

method currentTarget : 'a t opt readonly_prop

method preventDefault : unit meth

(* Legacy methods *)
method srcElement : 'a t opt readonly_prop
end
Expand All @@ -293,55 +295,27 @@ end

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

let window_event () : 'a #event t = Js.Unsafe.pure_js_expr "event"

(* The function preventDefault must be called explicitly when
using addEventListener... *)
let handler f =
Js.some
(Js.Unsafe.callback (fun e ->
(* depending on the internet explorer version, e can be null or undefined. *)
if not (Js.Opt.test (some e))
then (
let e = window_event () in
let res = f e in
if not (Js.to_bool res) then e##.returnValue := res;
res)
else
let res = f e in
if not (Js.to_bool res) then (Js.Unsafe.coerce e)##preventDefault;
res))
let res = f e in
if not (Js.to_bool res) then e##preventDefault;
res))

let full_handler f =
Js.some
(Js.Unsafe.meth_callback (fun this e ->
(* depending on the internet explorer version, e can be null or undefined *)
if not (Js.Opt.test (some e))
then (
let e = window_event () in
let res = f this e in
if not (Js.to_bool res) then e##.returnValue := res;
res)
else
let res = f this e in
if not (Js.to_bool res) then (Js.Unsafe.coerce e)##preventDefault;
res))
let res = f this e in
if not (Js.to_bool res) then e##preventDefault;
res))

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

let eventTarget (e : (< .. > as 'a) #event t) : 'a t =
let target =
Opt.get e##.target (fun () -> Opt.get e##.srcElement (fun () -> raise Not_found))
in
if Js.instanceof target Js.Unsafe.global##._Node
then
(* Workaround for Safari bug *)
let target' : node Js.t = Js.Unsafe.coerce target in
if target'##.nodeType == TEXT
then Js.Unsafe.coerce (Opt.get target'##.parentNode (fun () -> assert false))
else target
else target
Opt.get e##.target (fun () -> Opt.get e##.srcElement (fun () -> raise Not_found))

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

let removeEventListener id = id ()

let preventDefault ev =
if Js.Optdef.test (Js.Unsafe.coerce ev)##.preventDefault (* IE hack *)
then (Js.Unsafe.coerce ev)##preventDefault
else (Js.Unsafe.coerce ev)##.returnValue := Js.bool false
let preventDefault ev = ev##preventDefault

let createCustomEvent ?bubbles ?cancelable ?detail typ =
let opt_iter f = function
Expand All @@ -407,8 +378,6 @@ let createCustomEvent ?bubbles ?cancelable ?detail typ =
in
new%js constr typ opts

(* IE < 9 *)

class type stringList = object
method item : int -> js_string t opt meth

Expand Down
2 changes: 2 additions & 0 deletions lib/js_of_ocaml/dom.mli
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ class type ['a] event = object

method currentTarget : 'a t opt readonly_prop

method preventDefault : unit meth

(* Legacy methods *)
method srcElement : 'a t opt readonly_prop
end
Expand Down
18 changes: 2 additions & 16 deletions lib/js_of_ocaml/dom_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
open Js
open! Import

external caml_js_on_ie : unit -> bool t = "caml_js_on_ie"

let onIE = Js.to_bool (caml_js_on_ie ())

external html_escape : js_string t -> js_string t = "caml_js_html_escape"

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

module CoerceTo = struct
let element : #Dom.node Js.t -> element Js.t Js.opt =
if not (Js.Optdef.test (def html_element))
then
(* ie < 9 does not have HTMLElement: we have to cheat to check
that something is an html element *)
fun e ->
if not (Js.Optdef.test (def (Js.Unsafe.coerce e)##.innerHTML))
then Js.null
else Js.some (Js.Unsafe.coerce e)
else
fun e ->
if Js.instanceof e html_element then Js.some (Js.Unsafe.coerce e) else Js.null
let element (e : #Dom.node Js.t) : element Js.t Js.opt =
if Js.instanceof e html_element then Js.some (Js.Unsafe.coerce e) else Js.null

let unsafeCoerce tag (e : #element t) =
if Js.equals e##.tagName##toLowerCase (Js.string tag)
Expand Down
18 changes: 2 additions & 16 deletions lib/js_of_ocaml/dom_html.mli
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ and element = object

method offsetTop : int readonly_prop

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

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

method _type : js_string t readonly_prop

(* Cannot be changed under IE *)
method selectedIndex : int prop

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

method name : js_string t readonly_prop

(* Cannot be changed under IE *)
method size : int prop

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

method required : bool t writeonly_prop

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

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

method accessKey : js_string t prop

(* deprecated *)
method align : js_string t prop

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

method name : js_string t readonly_prop

(* Cannot be changed under IE *)
method readOnly : bool t prop

method required : bool t writeonly_prop

(* Not supported by IE 9/Safari *)
method size : int prop

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

method _type : js_string t readonly_prop

(* Cannot be changed under IE *)
(* Deprecated *)
method useMap : js_string t prop

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

method placeholder : js_string t writeonly_prop

(* Not supported by IE 9 *)
method selectionDirection : js_string t prop

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

method name : js_string t readonly_prop

(* Cannot be changed under IE *)
method readOnly : bool t prop

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

method _type : js_string t readonly_prop

(* Cannot be changed under IE *)
method value : js_string t prop

method select : unit meth

method required : bool t writeonly_prop

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

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

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

method name : js_string t readonly_prop

(* Cannot be changed under IE *)
method tabIndex : int prop

method _type : js_string t readonly_prop

(* Cannot be changed under IE *)
method value : js_string t prop
end

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

val decode_html_entities : js_string t -> js_string t

val onIE : bool

val hasPushState : unit -> bool

val hasPlaceholder : unit -> bool
Expand Down
4 changes: 0 additions & 4 deletions lib/js_of_ocaml/js_of_ocaml_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ void caml_js_html_escape () {
caml_fatal_error("Unimplemented Javascript primitive caml_js_html_escape!");
}

void caml_js_on_ie () {
caml_fatal_error("Unimplemented Javascript primitive caml_js_on_ie!");
}

void caml_uint8_array_of_bytes () {
caml_fatal_error("Unimplemented Javascript primitive caml_uint8_array_of_bytes!");
}
Expand Down
6 changes: 1 addition & 5 deletions lib/lwt/lwt_xmlHttpRequest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,7 @@ let perform_raw
req##.onreadystatechange :=
Js.wrap_callback (fun _ ->
match req##.readyState with
(* IE doesn't have the same semantics for HEADERS_RECEIVED.
so we wait til LOADING to check headers. See:
http://msdn.microsoft.com/en-us/library/ms534361(v=vs.85).aspx *)
| HEADERS_RECEIVED when not Dom_html.onIE -> ignore (do_check_headers ())
| LOADING when Dom_html.onIE -> ignore (do_check_headers ())
| HEADERS_RECEIVED -> ignore (do_check_headers ())
| DONE ->
(* If we didn't catch a previous event, we check the header. *)
if do_check_headers ()
Expand Down
20 changes: 0 additions & 20 deletions runtime/js/jslib_js_of_ocaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@

///////////// Jslib: code specific to Js_of_ocaml

//Provides: caml_js_on_ie const
function caml_js_on_ie() {
var ua =
globalThis.navigator && globalThis.navigator.userAgent
? globalThis.navigator.userAgent
: "";
return ua.indexOf("MSIE") !== -1 && ua.indexOf("Opera") !== 0;
}

//Provides: caml_js_html_escape const (const)
var caml_js_regexps = { amp: /&/g, lt: /</g, quot: /"/g, all: /[&<"]/ };
function caml_js_html_escape(s) {
Expand Down Expand Up @@ -86,17 +77,6 @@ function caml_xmlhttprequest_create(unit) {
return new globalThis.XMLHttpRequest();
} catch (e) {}
}
if (typeof globalThis.activeXObject !== "undefined") {
try {
return new globalThis.activeXObject("Msxml2.XMLHTTP");
} catch (e) {}
try {
return new globalThis.activeXObject("Msxml3.XMLHTTP");
} catch (e) {}
try {
return new globalThis.activeXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
caml_failwith("Cannot create a XMLHttpRequest");
}

Expand Down
4 changes: 0 additions & 4 deletions runtime/wasm/jslib_js_of_ocaml.wat
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
(func $caml_js_new (param (ref eq)) (param (ref eq)) (result (ref eq))))
(import "jslib" "caml_js_from_array"
(func $caml_js_from_array (param (ref eq)) (result (ref eq))))
(import "js" "caml_js_on_ie" (func $caml_js_on_ie (result i32)))
(import "js" "caml_js_html_escape"
(func $caml_js_html_escape (param anyref) (result anyref)))
(import "js" "caml_js_html_entities"
Expand All @@ -35,9 +34,6 @@
(type $block (array (mut (ref eq))))
(type $string (array (mut i8)))

(func (export "caml_js_on_ie") (param (ref eq)) (result (ref eq))
(ref.i31 (call $caml_js_on_ie)))

(func (export "caml_js_html_escape") (param (ref eq)) (result (ref eq))
(return_call $wrap
(call $caml_js_html_escape (call $unwrap (local.get 0)))))
Expand Down

0 comments on commit 865249e

Please sign in to comment.