@@ -341,9 +341,9 @@ and keyboardEvent = object
341341
342342 method location : int readonly_prop
343343
344- method key : js_string t readonly_prop
344+ method key : js_string t optdef readonly_prop
345345
346- method code : js_string t readonly_prop
346+ method code : js_string t optdef readonly_prop
347347
348348 method isComposing : bool t readonly_prop
349349
@@ -2351,9 +2351,9 @@ class type window = object
23512351
23522352 method scrollBy : number_t -> number_t -> unit meth
23532353
2354- method sessionStorage : storage t readonly_prop
2354+ method sessionStorage : storage t optdef readonly_prop
23552355
2356- method localStorage : storage t readonly_prop
2356+ method localStorage : storage t optdef readonly_prop
23572357
23582358 method top : window t readonly_prop
23592359
@@ -3368,6 +3368,10 @@ module Keyboard_code = struct
33683368
33693369 let make_unidentified _ = Unidentified
33703370
3371+ let try_next value f = function
3372+ | Unidentified -> Optdef. case value make_unidentified f
3373+ | v -> v
3374+
33713375 let run_next value f = function
33723376 | Unidentified -> f value
33733377 | v -> v
@@ -3383,8 +3387,9 @@ module Keyboard_code = struct
33833387
33843388 let ( |> ) x f = f x
33853389
3386- let of_event (evt : keyboardEvent Js.t ) =
3387- try_code evt##.code
3390+ let of_event evt =
3391+ Unidentified
3392+ |> try_next evt##.code try_code
33883393 |> try_key_location evt
33893394 |> run_next (get_key_code evt) try_key_code_normal
33903395
@@ -3397,10 +3402,12 @@ module Keyboard_key = struct
33973402 let char_of_int value =
33983403 if 0 < value then try Some (Uchar. of_int value) with _ -> None else None
33993404
3405+ let empty_string _ = Js. string " "
3406+
34003407 let none _ = None
34013408
34023409 let of_event evt =
3403- let key = evt##.key in
3410+ let key = Optdef. get evt##.key empty_string in
34043411 match key##.length with
34053412 | 0 -> Optdef. case evt##.charCode none char_of_int
34063413 | 1 -> char_of_int (int_of_float (Js. to_float (key##charCodeAt 0 )))
0 commit comments