Closed s9gf4ult closed 7 years ago
IIRC pToJSVal
and pFromJSVal
should work (and jsval
will also get the JSVal
for a JSString
). However if you want to be sure your code is portable to GHC you might need to use toJSVal
and fromJSVal
.
For instance in jsaddle (which tries to provide a ghcjs-base compatible interface on GHC), JSString
is newtype JSString = JSString Text
. This allows for pure conversion to/from Text
(Data.JSString.Text), but requires conversion to/from JSVal
must be done with toJSVal
and fromJSVal
(the monad is needed to determine the JavaScript context to create the JSVal
in).
Is there any reason to not export
JSString
constructor? It is implemented as newtype aroundJSVal
and not exported constructor cause to useunsafeCoerce :: JSVal -> JSString
and vise versa instead ofcoerce
or explicit packing/unpacking.