Skip to content

Commit c1feba6

Browse files
committed
js: classify bigint type correctly
1 parent 60fff75 commit c1feba6

9 files changed

+97
-68
lines changed

jscomp/main/builtin_cmi_datasets.ml

+4-4
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

+16-16
Large diffs are not rendered by default.

jscomp/others/js_types.ml

+14-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
type symbol
2828
(** Js symbol type only available in ES6 *)
2929

30+
type bigint_val
31+
(** Js bigint type only available in ES2020 *)
32+
3033
type obj_val
3134
type undefined_val
3235
(** This type has only one value `undefined` *)
@@ -45,6 +48,7 @@ type _ t =
4548
| Function : function_val t
4649
| Object : obj_val t
4750
| Symbol : symbol t
51+
| BigInt : bigint_val t
4852

4953

5054

@@ -58,6 +62,7 @@ type tagged_t =
5862
| JSFunction of function_val
5963
| JSObject of obj_val
6064
| JSSymbol of symbol
65+
| JSBigInt of bigint_val
6166

6267
let classify (x : 'a) : tagged_t =
6368
let ty = Js.typeof x in
@@ -66,7 +71,7 @@ let classify (x : 'a) : tagged_t =
6671
if x == (Obj.magic Js_null.empty) then
6772
JSNull else
6873
if ty = "number" then
69-
JSNumber (Obj.magic x ) else
74+
JSNumber (Obj.magic x) else
7075
if ty = "string" then
7176
JSString (Obj.magic x) else
7277
if ty = "boolean" then
@@ -75,9 +80,11 @@ let classify (x : 'a) : tagged_t =
7580
if ty = "function" then
7681
JSFunction (Obj.magic x) else
7782
if ty = "object" then
78-
JSObject (Obj.magic x)
79-
else
83+
JSObject (Obj.magic x) else
84+
if ty = "symbol" then
8085
JSSymbol (Obj.magic x)
86+
else
87+
JSBigInt (Obj.magic x)
8188

8289

8390
let test (type a) (x : 'a) (v : a t) : bool =
@@ -105,5 +112,7 @@ let test (type a) (x : 'a) (v : a t) : bool =
105112
Js.typeof x = "object"
106113
| Symbol
107114
->
108-
Js.typeof x = "symbol"
109-
115+
Js.typeof x = "symbol"
116+
| BigInt
117+
->
118+
Js.typeof x = "bigint"

jscomp/others/js_types.mli

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
type symbol
2929
(** Js symbol type only available in ES6 *)
3030

31+
type bigint_val
32+
(** Js bigint type only available in ES2020 *)
33+
3134
type obj_val
3235
type undefined_val
3336
(** This type has only one value `undefined` *)
@@ -46,6 +49,7 @@ type _ t =
4649
| Function : function_val t
4750
| Object : obj_val t
4851
| Symbol : symbol t
52+
| BigInt : bigint_val t
4953

5054

5155
val test : 'a -> 'b t -> bool
@@ -66,6 +70,7 @@ type tagged_t =
6670
| JSFunction of function_val
6771
| JSObject of obj_val
6872
| JSSymbol of symbol
73+
| JSBigInt of bigint_val
6974

7075

7176
val classify : 'a -> tagged_t

jscomp/test/typeof_test.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ let string_or_number (type t) x =
1010
| JSFalse | JSTrue -> false
1111
| JSFunction _ -> Js.log ("Function"); false
1212
| JSObject _ -> false
13-
| JSSymbol _ -> false
13+
| JSSymbol _ -> false
14+
| JSBigInt _ -> false
1415

1516
let suites = Mt.[
1617
"int_type", (fun _ -> Eq(Js.typeof 3, "number") );

lib/4.06.1/unstable/js_compiler.ml

+20-20
Large diffs are not rendered by default.

lib/4.06.1/whole_compiler.ml

+20-20
Large diffs are not rendered by default.

lib/es6/js_types.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ function classify(x) {
3333
TAG: /* JSObject */3,
3434
_0: x
3535
};
36-
} else {
36+
} else if (ty === "symbol") {
3737
return {
3838
TAG: /* JSSymbol */4,
3939
_0: x
4040
};
41+
} else {
42+
return {
43+
TAG: /* JSBigInt */5,
44+
_0: x
45+
};
4146
}
4247
}
4348

@@ -59,6 +64,8 @@ function test(x, v) {
5964
return typeof x === "object";
6065
case /* Symbol */7 :
6166
return typeof x === "symbol";
67+
case /* BigInt */8 :
68+
return typeof x === "bigint";
6269

6370
}
6471
}

lib/js/js_types.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ function classify(x) {
3333
TAG: /* JSObject */3,
3434
_0: x
3535
};
36-
} else {
36+
} else if (ty === "symbol") {
3737
return {
3838
TAG: /* JSSymbol */4,
3939
_0: x
4040
};
41+
} else {
42+
return {
43+
TAG: /* JSBigInt */5,
44+
_0: x
45+
};
4146
}
4247
}
4348

@@ -59,6 +64,8 @@ function test(x, v) {
5964
return typeof x === "object";
6065
case /* Symbol */7 :
6166
return typeof x === "symbol";
67+
case /* BigInt */8 :
68+
return typeof x === "bigint";
6269

6370
}
6471
}

0 commit comments

Comments
 (0)