|
1 | 1 | module Instance = struct |
2 | | - type t = Array | Blob | Date | File | Promise | RegExp |
| 2 | + type t = |
| 3 | + | Array |
| 4 | + | ArrayBuffer |
| 5 | + | BigInt64Array |
| 6 | + | BigUint64Array |
| 7 | + | Blob |
| 8 | + | DataView |
| 9 | + | Date |
| 10 | + | File |
| 11 | + | Float32Array |
| 12 | + | Float64Array |
| 13 | + | Int16Array |
| 14 | + | Int32Array |
| 15 | + | Int8Array |
| 16 | + | Promise |
| 17 | + | RegExp |
| 18 | + | Uint16Array |
| 19 | + | Uint32Array |
| 20 | + | Uint8Array |
| 21 | + | Uint8ClampedArray |
3 | 22 | let to_string = function |
4 | 23 | | Array -> "Array" |
| 24 | + | ArrayBuffer -> "ArrayBuffer" |
| 25 | + | BigInt64Array -> "BigInt64Array" |
| 26 | + | BigUint64Array -> "BigUint64Array" |
5 | 27 | | Blob -> "Blob" |
| 28 | + | DataView -> "DataView" |
6 | 29 | | Date -> "Date" |
7 | 30 | | File -> "File" |
| 31 | + | Float32Array -> "Float32Array" |
| 32 | + | Float64Array -> "Float64Array" |
| 33 | + | Int16Array -> "Int16Array" |
| 34 | + | Int32Array -> "Int32Array" |
| 35 | + | Int8Array -> "Int8Array" |
8 | 36 | | Promise -> "Promise" |
9 | 37 | | RegExp -> "RegExp" |
| 38 | + | Uint16Array -> "Uint16Array" |
| 39 | + | Uint32Array -> "Uint32Array" |
| 40 | + | Uint8Array -> "Uint8Array" |
| 41 | + | Uint8ClampedArray -> "Uint8ClampedArray" |
10 | 42 | end |
11 | 43 |
|
12 | 44 | type untagged_error = |
@@ -200,37 +232,54 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) = |
200 | 232 | | Tconstr (path, _, _) when Path.same path Predef.path_array -> Some Array |
201 | 233 | | Tconstr (path, _, _) -> ( |
202 | 234 | match Path.name path with |
| 235 | + | "Stdlib_ArrayBuffer.t" -> Some ArrayBuffer |
| 236 | + | "Stdlib.BigInt64Array.t" -> Some BigInt64Array |
| 237 | + | "Stdlib.BigUint64Array.t" -> Some BigUint64Array |
| 238 | + | "Stdlib.DataView.t" -> Some DataView |
203 | 239 | | "Stdlib_Date.t" -> Some Date |
| 240 | + | "Stdlib.Float32Array.t" -> Some Float32Array |
| 241 | + | "Stdlib.Float64Array.t" -> Some Float64Array |
| 242 | + | "Stdlib.Int16Array.t" -> Some Int16Array |
| 243 | + | "Stdlib.Int32Array.t" -> Some Int32Array |
| 244 | + | "Stdlib.Int8Array.t" -> Some Int8Array |
204 | 245 | | "Stdlib_RegExp.t" -> Some RegExp |
| 246 | + | "Stdlib.Uint16Array.t" -> Some Uint16Array |
| 247 | + | "Stdlib.Uint32Array.t" -> Some Uint32Array |
| 248 | + | "Stdlib.Uint8Array.t" -> Some Uint8Array |
| 249 | + | "Stdlib.Uint8ClampedArray.t" -> Some Uint8ClampedArray |
205 | 250 | | "Js_file.t" -> Some File |
206 | 251 | | "Js_blob.t" -> Some Blob |
207 | 252 | | _ -> None) |
208 | 253 | | _ -> None |
209 | 254 |
|
210 | 255 | let get_block_type_from_typ ~env (t : Types.type_expr) : block_type option = |
211 | | - let t = !expand_head env t in |
212 | | - match t with |
213 | | - | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_string -> |
214 | | - Some StringType |
215 | | - | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_int -> |
216 | | - Some IntType |
217 | | - | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_float -> |
218 | | - Some FloatType |
219 | | - | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_bigint -> |
220 | | - Some BigintType |
221 | | - | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_bool -> |
222 | | - Some BooleanType |
223 | | - | {desc = Tarrow _} -> Some FunctionType |
224 | | - | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_string -> |
225 | | - Some StringType |
226 | | - | {desc = Tconstr _} as t when type_is_builtin_object t -> Some ObjectType |
227 | | - | {desc = Tconstr _} as t |
228 | | - when type_to_instanceof_backed_obj t |> Option.is_some -> ( |
229 | | - match type_to_instanceof_backed_obj t with |
230 | | - | None -> None |
231 | | - | Some instance_type -> Some (InstanceType instance_type)) |
232 | | - | {desc = Ttuple _} -> Some (InstanceType Array) |
233 | | - | _ -> None |
| 256 | + (* First check the original (unexpanded) type for typed arrays and other instance types *) |
| 257 | + match type_to_instanceof_backed_obj t with |
| 258 | + | Some instance_type -> Some (InstanceType instance_type) |
| 259 | + | None -> ( |
| 260 | + (* If original type didn't match, expand and try standard checks *) |
| 261 | + let expanded_t = !expand_head env t in |
| 262 | + match expanded_t with |
| 263 | + | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_string -> |
| 264 | + Some StringType |
| 265 | + | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_int -> |
| 266 | + Some IntType |
| 267 | + | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_float -> |
| 268 | + Some FloatType |
| 269 | + | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_bigint -> |
| 270 | + Some BigintType |
| 271 | + | {desc = Tconstr (path, _, _)} when Path.same path Predef.path_bool -> |
| 272 | + Some BooleanType |
| 273 | + | {desc = Tarrow _} -> Some FunctionType |
| 274 | + | {desc = Tconstr _} as expanded_t when type_is_builtin_object expanded_t -> |
| 275 | + Some ObjectType |
| 276 | + | {desc = Tconstr _} as expanded_t |
| 277 | + when type_to_instanceof_backed_obj expanded_t |> Option.is_some -> ( |
| 278 | + match type_to_instanceof_backed_obj expanded_t with |
| 279 | + | None -> None |
| 280 | + | Some instance_type -> Some (InstanceType instance_type)) |
| 281 | + | {desc = Ttuple _} -> Some (InstanceType Array) |
| 282 | + | _ -> None) |
234 | 283 |
|
235 | 284 | let get_block_type ~env (cstr : Types.constructor_declaration) : |
236 | 285 | block_type option = |
|
0 commit comments