Skip to content

Commit 9601c2b

Browse files
committed
make Export newtype and fix unsafeCoerce bug when dereferencing exports
1 parent 619edd0 commit 9601c2b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

GHCJS/Foreign/Export.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ import Unsafe.Coerce
3030
import qualified GHC.Exts as Exts
3131

3232
import GHCJS.Prim
33+
import GHCJS.Types
3334

34-
type Export a = JSVal
35+
newtype Export a = Export JSVal
36+
instance IsJSVal (Export a)
3537

3638
{- |
3739
Export any Haskell value to a JavaScript reference without evaluating it.
@@ -66,7 +68,7 @@ derefExport e = do
6668
r <- js_derefExport w1 w2 e
6769
if isNull r
6870
then return Nothing
69-
else unsafeCoerce (js_toHeapObject r)
71+
else unsafeCoerce <$> js_toHeapObject r
7072

7173
{- |
7274
Release all memory associated with the export. Subsequent calls to
@@ -82,10 +84,10 @@ foreign import javascript unsafe
8284
js_export :: Word64 -> Word64 -> Any -> IO (Export a)
8385
foreign import javascript unsafe
8486
"h$derefExport"
85-
js_derefExport :: Word64 -> Word64 -> JSVal -> IO JSVal
87+
js_derefExport :: Word64 -> Word64 -> Export a -> IO JSVal
8688
foreign import javascript unsafe
87-
"$r = $1;" js_toHeapObject :: JSVal -> Exts.Any
89+
"$r = $1;" js_toHeapObject :: JSVal -> IO Exts.Any
8890

8991
foreign import javascript unsafe
9092
"h$releaseExport"
91-
js_releaseExport :: JSVal -> IO ()
93+
js_releaseExport :: Export a -> IO ()

0 commit comments

Comments
 (0)