/
Types.hs
66 lines (52 loc) · 1.57 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE JavaScriptFFI #-}
module GHCJS.Types ( JSVal
, WouldBlockException(..)
, JSException(..)
, IsJSVal
, jsval
, isNull
, isUndefined
, nullRef
, JSString
, mkRef
, Ref#
, toPtr
, fromPtr
, JSRef
) where
import Data.JSString.Internal.Type (JSString)
import GHCJS.Internal.Types
import GHC.JS.Prim
import GHC.Int
import GHC.Types
import GHC.Prim
import GHC.Ptr
import Control.DeepSeq
type Ref# = ByteArray#
mkRef :: ByteArray# -> JSVal
mkRef x = JSVal x
nullRef :: JSVal
nullRef = js_nullRef
{-# INLINE nullRef #-}
toPtr :: JSVal -> Ptr a
toPtr j = js_mkPtr j
{-# INLINE toPtr #-}
fromPtr :: Ptr a -> JSVal
fromPtr p = js_ptrVal p
{-# INLINE fromPtr #-}
foreign import javascript unsafe "((x) => { return null; })"
js_nullRef :: JSVal
foreign import javascript unsafe "((x,y) => { return x; })"
js_ptrVal :: Ptr a -> JSVal
foreign import javascript unsafe "((x) => { h$ret1 = 0; return x; })"
js_mkPtr :: JSVal -> Ptr a
-- | This is a deprecated copmatibility wrapper for the old JSRef type.
--
-- See https://github.com/ghcjs/ghcjs/issues/421
type JSRef a = JSVal
{-# DEPRECATED JSRef "Use JSVal instead, or a more specific newtype wrapper of JSVal " #-}