From 39ce1b91ad469d3878dc04e72c4e6b03b009bb94 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Mon, 6 Jan 2025 23:35:52 -0800 Subject: [PATCH] fix(runtime): alias typed array bindings to their corresponding `Js.*` types (#1281) * fix(runtime): alias typed array bindings to their corresponding `Js.*` types * add changelog entry --- Changes.md | 3 ++- jscomp/runtime/js_typed_array.cppo.ml | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Changes.md b/Changes.md index 695878ef2..68b9d72b9 100644 --- a/Changes.md +++ b/Changes.md @@ -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 diff --git a/jscomp/runtime/js_typed_array.cppo.ml b/jscomp/runtime/js_typed_array.cppo.ml index 4b032816f..6980a736c 100644 --- a/jscomp/runtime/js_typed_array.cppo.ml +++ b/jscomp/runtime/js_typed_array.cppo.ml @@ -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]\ @@ -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