33{-# LANGUAGE DefaultSignatures #-}
44{- | Basic interop between Haskell and JavaScript.
55
6- The principal type here is 'JSRef ', which is a lifted type that contains
7- a JavaScript reference. The 'JSRef ' type is parameterized with one phantom
6+ The principal type here is 'JSVal ', which is a lifted type that contains
7+ a JavaScript reference. The 'JSVal ' type is parameterized with one phantom
88 type, and GHCJS.Types defines several type synonyms for specific variants.
99
10- The code in this module makes no assumptions about 'JSRef a' types.
10+ The code in this module makes no assumptions about 'JSVal a' types.
1111 Operations that can result in a JS exception that can kill a Haskell thread
12- are marked unsafe (for example if the 'JSRef ' contains a null or undefined
12+ are marked unsafe (for example if the 'JSVal ' contains a null or undefined
1313 value). There are safe variants where the JS exception is propagated as
1414 a Haskell exception, so that it can be handled on the Haskell side.
1515
1616 For more specific types, like 'JSArray' or 'JSBool', the code assumes that
17- the contents of the 'JSRef ' actually is a JavaScript array or bool value.
17+ the contents of the 'JSVal ' actually is a JavaScript array or bool value.
1818 If it contains an unexpected value, the code can result in exceptions that
1919 kill the Haskell thread, even for functions not marked unsafe.
2020
@@ -70,7 +70,7 @@ module GHCJS.Foreign ( jsTrue
7070 , jsTypeOf , JSType (.. )
7171 , jsonTypeOf , JSONType (.. )
7272{- , wrapBuffer, wrapMutableBuffer
73- , byteArrayJSRef, mutableByteArrayJSRef
73+ , byteArrayJSVal, mutableByteArrayJSVal
7474 , bufferByteString, byteArrayByteString
7575 , unsafeMutableByteArrayByteString -}
7676 ) where
@@ -88,14 +88,14 @@ import qualified Data.Text as T
8888class ToJSString a where
8989 toJSString :: a -> JSString
9090
91- -- toJSString = ptoJSRef
91+ -- toJSString = ptoJSVal
9292
9393
9494class FromJSString a where
9595 fromJSString :: JSString -> a
9696
97- -- default PFromJSRef
98- -- fromJSString = pfromJSRef
97+ -- default PFromJSVal
98+ -- fromJSString = pfromJSVal
9999-- {-# INLINE fromJSString #-}
100100{-
101101instance ToJSString [Char]
@@ -114,26 +114,26 @@ instance FromJSString JSString
114114 o is not a JS object or the property cannot be accessed
115115 -}
116116getProp :: ToJSString a => a -- ^ the property name
117- -> JSRef b -- ^ the object
118- -> IO (JSRef c) -- ^ the property value
117+ -> JSVal b -- ^ the object
118+ -> IO (JSVal c) -- ^ the property value
119119getProp p o = js_getProp (toJSString p) o
120120{- # INLINE getProp #-}
121121
122122{- | Read a property from a JS object. Kills the Haskell thread
123123 if o is not a JS object or the property cannot be accessed
124124 -}
125125unsafeGetProp :: ToJSString a => a -- ^ the property name
126- -> JSRef b -- ^ the object
127- -> IO (JSRef c) -- ^ the property value, Nothing if the object doesn't have a property with the given name
126+ -> JSVal b -- ^ the object
127+ -> IO (JSVal c) -- ^ the property value, Nothing if the object doesn't have a property with the given name
128128unsafeGetProp p o = js_unsafeGetProp (toJSString p) o
129129{- # INLINE unsafeGetProp #-}
130130
131131{- | Read a property from a JS object. Throws a JSException if
132132 o is not a JS object or the property cannot be accessed
133133 -}
134134getPropMaybe :: ToJSString a => a -- ^ the property name
135- -> JSRef b -- ^ the object
136- -> IO (Maybe (JSRef c)) -- ^ the property value, Nothing if the object doesn't have a property with the given name
135+ -> JSVal b -- ^ the object
136+ -> IO (Maybe (JSVal c)) -- ^ the property value, Nothing if the object doesn't have a property with the given name
137137getPropMaybe p o = do
138138 p' <- js_getProp (toJSString p) o
139139 if isUndefined p' then return Nothing else return (Just p')
@@ -143,8 +143,8 @@ getPropMaybe p o = do
143143 if o is not a JS object or the property cannot be accessed
144144 -}
145145unsafeGetPropMaybe :: ToJSString a => a -- ^ the property name
146- -> JSRef b -- ^ the object
147- -> IO (Maybe (JSRef c)) -- ^ the property value, Nothing if the object doesn't have a property with the given name
146+ -> JSVal b -- ^ the object
147+ -> IO (Maybe (JSVal c)) -- ^ the property value, Nothing if the object doesn't have a property with the given name
148148unsafeGetPropMaybe p o = do
149149 p' <- js_unsafeGetProp (toJSString p) o
150150 if isUndefined p' then return Nothing else return (Just p')
@@ -155,8 +155,8 @@ unsafeGetPropMaybe p o = do
155155 be set
156156 -}
157157setProp :: ToJSString a => a -- ^ the property name
158- -> JSRef b -- ^ the value
159- -> JSRef c -- ^ the object
158+ -> JSVal b -- ^ the value
159+ -> JSVal c -- ^ the object
160160 -> IO ()
161161setProp p v o = js_setProp (toJSString p) v o
162162{- # INLINE setProp #-}
@@ -165,8 +165,8 @@ setProp p v o = js_setProp (toJSString p) v o
165165 if the property cannot be set.
166166-}
167167unsafeSetProp :: ToJSString a => a -- ^ the property name
168- -> JSRef b -- ^ the value
169- -> JSRef c -- ^ the object
168+ -> JSVal b -- ^ the value
169+ -> JSVal c -- ^ the object
170170 -> IO ()
171171unsafeSetProp p v o = js_unsafeSetProp (toJSString p) v o
172172
0 commit comments