Skip to content

Commit

Permalink
fix(runtime): alias typed array bindings to their corresponding `Js.*…
Browse files Browse the repository at this point in the history
…` types (#1281)

* fix(runtime): alias typed array bindings to their corresponding `Js.*` types

* add changelog entry
  • Loading branch information
anmonteiro authored Jan 7, 2025
1 parent c961cc8 commit 39ce1b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Unreleased
- `melange.js`: Add `Js.FormData` with bindings to the
[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) API
([#1153](https://github.com/melange-re/melange/pull/1153),
[#1270](https://github.com/melange-re/melange/pull/1270))
[#1270](https://github.com/melange-re/melange/pull/1270),
[#1281](https://github.com/melange-re/melange/pull/1281)
- `melange.js`: Add `Js.Blob` and `Js.File` with bindings to the
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and
[File](https://developer.mozilla.org/en-US/docs/Web/API/File) APIs
Expand Down
22 changes: 11 additions & 11 deletions jscomp/runtime/js_typed_array.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ module ArrayBuffer = struct
[@@mel.send.pipe: t]
end

#define COMMON_EXTERNALS(moduleName, eltType)\
#define COMMON_EXTERNALS(moduleName, eltType, jsTypeAlias)\
(** *)\
type elt = eltType\
type 'a typed_array\
type 'a typed_array = jsTypeAlias\
type t = elt typed_array\
\
external unsafe_get : t -> int -> elt = "" [@@mel.get_index]\
Expand Down Expand Up @@ -145,43 +145,43 @@ end
external values : t -> elt Js.iterator = "values" [@@mel.send]

module Int8Array = struct
COMMON_EXTERNALS(Int8Array,int)
COMMON_EXTERNALS(Int8Array,int,int8Array)
end


module Uint8Array = struct
COMMON_EXTERNALS(Uint8Array,int)
COMMON_EXTERNALS(Uint8Array,int,uint8Array)
end

module Uint8ClampedArray = struct
COMMON_EXTERNALS(Uint8ClampedArray,int)
COMMON_EXTERNALS(Uint8ClampedArray,int,uint8ClampedArray)
end

module Int16Array = struct
COMMON_EXTERNALS(Int16Array,int)
COMMON_EXTERNALS(Int16Array,int,int16Array)
end

module Uint16Array = struct
COMMON_EXTERNALS(Uint16Array,int)
COMMON_EXTERNALS(Uint16Array,int,uint16Array)
end

module Int32Array = struct
COMMON_EXTERNALS(Int32Array,int32)
COMMON_EXTERNALS(Int32Array,int32,int32Array)
end

module Uint32Array = struct
COMMON_EXTERNALS(Uint32Array,int)
COMMON_EXTERNALS(Uint32Array,int,uint32Array)
end

(*
it still return number, [float] in this case
*)
module Float32Array = struct
COMMON_EXTERNALS(Float32Array,float)
COMMON_EXTERNALS(Float32Array,float,float32Array)
end

module Float64Array = struct
COMMON_EXTERNALS(Float64Array,float)
COMMON_EXTERNALS(Float64Array,float,float64Array)
end


Expand Down

0 comments on commit 39ce1b9

Please sign in to comment.