Safe Haskell | None |
---|---|
Language | Haskell2010 |
Documentation
This provides a consistent way to convert to JSVal, with different semantics for Char. In the Char's instance of ToJS, it converts to a string instead of integer - IMHO this is less surprising.
The other reason for this class is while GHCJS base provide both IsJSVal and PToJSVal to convert to jsval, some types are instances of one or the other class. This means you can't use the "Maybe a" instance of PToJSVal if it contains IsISJVal but not pToJSVal.
This is a pure conversion, so instances must be able to convert the same or equivalent JSVal each time.
toJS :: IsJSVal a => a -> JSVal Source #
This is a pure conversion, so instances must be able to convert the same or equivalent JSVal each time.
ToJS Bool Source # | |
ToJS Char Source # | Char instance converts to string |
ToJS Double Source # | |
ToJS Float Source # | |
ToJS Int Source # | |
ToJS Int8 Source # | |
ToJS Int16 Source # | |
ToJS Int32 Source # | |
ToJS Word Source # | |
ToJS Word8 Source # | |
ToJS Word16 Source # | |
ToJS Word32 Source # | |
ToJS Text Source # | |
ToJS Object Source # | |
ToJS JSString Source # | |
ToJS JSVal Source # | |
ToJS [Char] Source # | |
ToJS a => ToJS (Maybe a) Source # | |
ToJS (Nullable a) Source # | |
ToJS (Export a) Source # | |
ToJS (Callback a) Source # | |
ToJS (SomeJSArray * m) Source # | |
This provides a consistent way to safely convert from JSVal. The semantics is that if the return value is a Just, then the JSVal is not a null value. Also, Nothing is also returned for values out of range. They are not silently truncated. (Except for Float where there may be loss of precision) during conversion.
The reason for this class is because GHCJS.Marshal.fromJSVal and GHCJS.Marshal.pFromJSVal
are not safe to use as it assumes that the JSVal are of the correct type and not null.
(https:/github.comghcjsghcjs-baseissues/87).
The safe way to convert from JSVal is to use JavaScript.Cast or to use the 'Maybe a' instance of FromJSVal,
ie fromJSVal :: JSVal -> IO (Maybe (Maybe a))
, which is a bit more awkward to use.
Also, Javascript.Cast doesn't have much instances, and it hardcodes the instance detection method
to javascript isinstance
which is not sufficient for complex
types (https:/github.comghcjsghcjs-baseissues/86).
fromJS :: JSVal -> IO (Maybe a) Source #
This is an IO because since JSVal is mutable, this function may different results for the same JSVal at later points in time.
FromJS Bool Source # | |
FromJS Char Source # | This will only succeed on a single character string |
FromJS Double Source # | |
FromJS Float Source # | |
FromJS Int Source # | |
FromJS Int8 Source # | |
FromJS Int16 Source # | |
FromJS Int32 Source # | |
FromJS Word Source # | |
FromJS Word8 Source # | |
FromJS Word16 Source # | |
FromJS Word32 Source # | |
FromJS Text Source # | |
FromJS Object Source # | |
FromJS JSString Source # | |
FromJS JSVal Source # | |
FromJS [Char] Source # | |
FromJS (SomeJSArray * m) Source # | |