@@ -27,6 +27,7 @@ task name expr portType =
2727
2828data JSType
2929 = JSNumber
30+ | JSInt
3031 | JSBoolean
3132 | JSString
3233 | JSArray
@@ -37,6 +38,7 @@ typeToString :: JSType -> String
3738typeToString tipe =
3839 case tipe of
3940 JSNumber -> "a number"
41+ JSInt -> "an integer"
4042 JSBoolean -> "a boolean (true or false)"
4143 JSString -> "a string"
4244 JSArray -> "an array"
@@ -81,12 +83,31 @@ check x jsType continue =
8183
8284 checks =
8385 case jsType of
84− JSNumber -> [typeof "number"]
85− JSBoolean -> [typeof "boolean"]
86− JSString -> [typeof "string", instanceof "String"]
87− JSArray -> [instanceof "Array"]
86+ JSNumber ->
87+ [typeof "number"]
88+
89+ JSInt ->
90+ [jsFold OpLAnd intChecks]
91+
92+ JSBoolean ->
93+ [typeof "boolean"]
94+
95+ JSString ->
96+ [typeof "string", instanceof "String"]
97+
98+ JSArray ->
99+ [instanceof "Array"]
100+
88101 JSObject fields ->
89− [jsFold OpLAnd (typeof "object" : map member fields)]
102+ [jsFold OpLAnd (typeof "object" : map member fields)]
103+
104+
105+intChecks :: [Expression () -> Expression ()]
106+intChecks =
107+ [ typeof "number"
108+ , \x -> ref "isFinite" <| x
109+ , \x -> equal (obj ["Math","floor"] <| x) x
110+ ]
90111
91112
92113-- INBOUND
@@ -127,8 +148,8 @@ toType tipe x =
127148 toType (T.dealias args t) x
128149
129150 T.Type (Var.Canonical Var.BuiltIn name)
130− | name == "Int" -> from JSNumber
131151 | name == "Float" -> from JSNumber
152+ | name == "Int" -> from JSInt
132153 | name == "Bool" -> from JSBoolean
133154 | name == "String" -> from JSString
134155 where