From 2b4f30e8d1f63812c6f7695890a61dcbf5060694 Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Mon, 22 Jul 2024 11:12:08 +0200 Subject: [PATCH] Stop exposing numbers as floats This is for compatibility with wasm_of_ocaml, in which Javascript numbers and floats cannot be manipulated using the same functions and require conversions. --- lib/js_of_ocaml/js.ml | 8 ++++---- lib/js_of_ocaml/js.mli | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/js_of_ocaml/js.ml b/lib/js_of_ocaml/js.ml index e9972add32..c51958422d 100644 --- a/lib/js_of_ocaml/js.ml +++ b/lib/js_of_ocaml/js.ml @@ -246,8 +246,6 @@ module Js = struct type string_array - type number_t = float - class type number = object method toString : js_string t meth @@ -271,7 +269,7 @@ module Js = struct method charAt : int -> js_string t meth - method charCodeAt : int -> number_t meth + method charCodeAt : int -> number t meth (* This may return NaN... *) method concat : js_string t -> js_string t meth @@ -291,7 +289,7 @@ module Js = struct method lastIndexOf_from : js_string t -> int -> int meth - method localeCompare : js_string t -> number_t meth + method localeCompare : js_string t -> number t meth method _match : regExp t -> match_result_handle t opt meth @@ -354,6 +352,8 @@ module Js = struct and normalization = js_string + type number_t = number t + (* string is used by ppx_js, it needs to come before any use of the new syntax in this file *) external string : string -> js_string t = "caml_jsstring_of_string" diff --git a/lib/js_of_ocaml/js.mli b/lib/js_of_ocaml/js.mli index 47013b7c95..cdaf7ad8f4 100644 --- a/lib/js_of_ocaml/js.mli +++ b/lib/js_of_ocaml/js.mli @@ -219,8 +219,6 @@ val nfkc : normalization t (** Specification of Javascript number objects. *) -type number_t = float - class type number = object method toString : js_string t meth @@ -245,7 +243,7 @@ and js_string = object method charAt : int -> js_string t meth - method charCodeAt : int -> number_t meth + method charCodeAt : int -> number t meth (* This may return NaN... *) method concat : js_string t -> js_string t meth @@ -265,7 +263,7 @@ and js_string = object method lastIndexOf_from : js_string t -> int -> int meth - method localeCompare : js_string t -> number_t meth + method localeCompare : js_string t -> number t meth method _match : regExp t -> match_result_handle t opt meth @@ -328,6 +326,8 @@ and regExp = object method lastIndex : int prop end +type number_t = number t + (** Specification of the string constructor, considered as an object. *) class type string_constr = object method fromCharCode : int -> js_string t meth