on master help sign in
Update GHCJS preprocessor define used
f6726d9Hamish Mackenzie
jsc.cabal+2−2
@@ -1,5 +1,5 @@
1name: jsc
1name: jsc
2−version: 0.1.1.1
2+version: 0.1.1.2
3cabal-version: >=1.10
3cabal-version: >=1.10
4license: MIT
4license: MIT
5license-file: LICENSE
5license-file: LICENSE
@@ -92,7 +92,7 @@ test-suite test-tool
92
92
93 build-depends: template-haskell -any, base <5, lens >=3.8.5 && <4.1,
93 build-depends: template-haskell -any, base <5, lens >=3.8.5 && <4.1,
94 text >=0.11.2.3 && <1.2, transformers >=0.3.0.0 && <0.4,
94 text >=0.11.2.3 && <1.2, transformers >=0.3.0.0 && <0.4,
95− hslogger -any, jsc ==0.1.1.1
95+ hslogger -any, jsc ==0.1.1.2
96 type: exitcode-stdio-1.0
96 type: exitcode-stdio-1.0
97 main-is: TestJSC.hs
97 main-is: TestJSC.hs
98 default-language: Haskell2010
98 default-language: Haskell2010
src/Language/Javascript/JSC/Evaluate.hs+4−4
@@ -1,5 +1,5 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
2+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
3{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
3{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
4#endif
4#endif
5-----------------------------------------------------------------------------
5-----------------------------------------------------------------------------
@@ -25,7 +25,7 @@ import Control.Monad.IO.Class (MonadIO(..))
25import Language.Javascript.JSC.Types
25import Language.Javascript.JSC.Types
26 (JSStringRef, JSValueRef, JSObjectRef,
26 (JSStringRef, JSValueRef, JSObjectRef,
27 JSValueRefRef)
27 JSValueRefRef)
28−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
28+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
29import GHCJS.Types (nullRef)
29import GHCJS.Types (nullRef)
30#else
30#else
31import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSBase
31import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSBase
@@ -51,7 +51,7 @@ evaluateScript :: (MakeStringRef script, MakeObjectRef this, MakeStringRef url)
51 -> url
51 -> url
52 -> Int -- ^ The Line number of the first line of the script
52 -> Int -- ^ The Line number of the first line of the script
53 -> JSC JSValueRef
53 -> JSC JSValueRef
54−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
54+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
55evaluateScript script this url line = liftIO $ js_eval (makeStringRef script)
55evaluateScript script this url line = liftIO $ js_eval (makeStringRef script)
56foreign import javascript unsafe "$r = eval(s);"
56foreign import javascript unsafe "$r = eval(s);"
57 js_eval :: JSStringRef -> IO JSValueRef
57 js_eval :: JSStringRef -> IO JSValueRef
@@ -71,7 +71,7 @@ evaluateScript = undefined
71eval :: MakeStringRef script
71eval :: MakeStringRef script
72 => script -- ^ JavaScript to evaluate
72 => script -- ^ JavaScript to evaluate
73 -> JSC JSValueRef
73 -> JSC JSValueRef
74−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
74+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
75eval script = evaluateScript script (nullRef::JSObjectRef) (nullRef::JSStringRef) 1
75eval script = evaluateScript script (nullRef::JSObjectRef) (nullRef::JSStringRef) 1
76#else
76#else
77eval script = evaluateScript script (nullPtr::JSObjectRef) (nullPtr::JSStringRef) 1
77eval script = evaluateScript script (nullPtr::JSObjectRef) (nullPtr::JSStringRef) 1
src/Language/Javascript/JSC/Monad.hs+3−3
@@ -30,7 +30,7 @@ import Control.Monad.Trans.Reader (runReaderT, ask, ReaderT(..))
30import Language.Javascript.JSC.Types
30import Language.Javascript.JSC.Types
31 (JSValueRefRef, JSValueRef, JSContextRef)
31 (JSValueRefRef, JSValueRef, JSContextRef)
32import Control.Monad.IO.Class (MonadIO(..))
32import Control.Monad.IO.Class (MonadIO(..))
33−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
33+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
34import GHCJS.Types (isUndefined, isNull)
34import GHCJS.Types (isUndefined, isNull)
35import GHCJS.Foreign (newArray, indexArray)
35import GHCJS.Foreign (newArray, indexArray)
36#else
36#else
@@ -69,7 +69,7 @@ t `catch` c = do
69-- to throw exceptions.
69-- to throw exceptions.
70catchval :: (JSValueRefRef -> JSC a) -> (JSValueRef -> JSC a) -> JSC a
70catchval :: (JSValueRefRef -> JSC a) -> (JSValueRef -> JSC a) -> JSC a
71catchval f catcher = do
71catchval f catcher = do
72−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
72+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
73 pexc <- liftIO $ newArray
73 pexc <- liftIO $ newArray
74 result <- f pexc
74 result <- f pexc
75 exc <- liftIO $ indexArray 0 pexc
75 exc <- liftIO $ indexArray 0 pexc
@@ -87,7 +87,7 @@ catchval f catcher = do
87 else catcher exc
87 else catcher exc
88#endif
88#endif
89
89
90−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
90+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
91runJSC :: w -> JSC a -> IO a
91runJSC :: w -> JSC a -> IO a
92runJSC _ f = runReaderT f ()
92runJSC _ f = runReaderT f ()
93#else
93#else
src/Language/Javascript/JSC/Object.hs+13−13
@@ -4,7 +4,7 @@
4{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE ScopedTypeVariables #-}
5{-# LANGUAGE Rank2Types #-}
5{-# LANGUAGE Rank2Types #-}
6{-# LANGUAGE ForeignFunctionInterface #-}
6{-# LANGUAGE ForeignFunctionInterface #-}
7−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
7+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
8{-# LANGUAGE JavaScriptFFI #-}
8{-# LANGUAGE JavaScriptFFI #-}
9#endif
9#endif
10-----------------------------------------------------------------------------
10-----------------------------------------------------------------------------
@@ -79,7 +79,7 @@ import Language.Javascript.JSC.Types
79 (JSPropertyNameArrayRef, JSStringRef, JSObjectRef, JSValueRefRef,
79 (JSPropertyNameArrayRef, JSStringRef, JSObjectRef, JSValueRefRef,
80 JSValueRef, JSContextRef, Index)
80 JSValueRef, JSContextRef, Index)
81import Foreign.C.Types (CSize(..), CULong(..), CUInt(..))
81import Foreign.C.Types (CSize(..), CULong(..), CUInt(..))
82−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
82+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
83import GHCJS.Types (nullRef, castRef, JSArray, JSFun)
83import GHCJS.Types (nullRef, castRef, JSArray, JSFun)
84import GHCJS.Foreign (newObj, toArray, fromArray, syncCallback2)
84import GHCJS.Foreign (newObj, toArray, fromArray, syncCallback2)
85import Control.Monad (liftM)
85import Control.Monad (liftM)
@@ -292,7 +292,7 @@ call function this args = do
292-- >>> testJSC $ do { a <- obj; a ^. js "x" <# "Hello"; a ^. js "x" }
292-- >>> testJSC $ do { a <- obj; a ^. js "x" <# "Hello"; a ^. js "x" }
293-- Hello
293-- Hello
294obj :: JSC JSObjectRef
294obj :: JSC JSObjectRef
295−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
295+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
296obj = liftIO $ newObj
296obj = liftIO $ newObj
297#else
297#else
298obj = do
298obj = do
@@ -320,7 +320,7 @@ type JSCallAsFunction = JSValueRef -- ^ Function object
320fun :: JSCallAsFunction -> JSCallAsFunction
320fun :: JSCallAsFunction -> JSCallAsFunction
321fun = id
321fun = id
322
322
323−#if (!defined(__GHCJS__) || !defined(USE_JAVASCRIPTFFI)) && defined(USE_WEBKIT)
323+#if (!defined(ghcjs_HOST_OS) || !defined(USE_JAVASCRIPTFFI)) && defined(USE_WEBKIT)
324foreign import ccall "wrapper"
324foreign import ccall "wrapper"
325 mkJSObjectCallAsFunctionCallback :: JSObjectCallAsFunctionCallback' -> IO JSObjectCallAsFunctionCallback
325 mkJSObjectCallAsFunctionCallback :: JSObjectCallAsFunctionCallback' -> IO JSObjectCallAsFunctionCallback
326#endif
326#endif
@@ -331,7 +331,7 @@ function :: MakeStringRef name
331 -> JSCallAsFunction -- ^ Haskell function to call
331 -> JSCallAsFunction -- ^ Haskell function to call
332 -> JSC JSObjectRef -- ^ Returns a JavaScript function object that will
332 -> JSC JSObjectRef -- ^ Returns a JavaScript function object that will
333 -- call the Haskell one when it is called
333 -- call the Haskell one when it is called
334−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
334+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
335function name f = liftIO $ do
335function name f = liftIO $ do
336 callback <- syncCallback2 False True $ \this args -> do
336 callback <- syncCallback2 False True $ \this args -> do
337 rargs <- fromArray args
337 rargs <- fromArray args
@@ -361,7 +361,7 @@ function = undefined
361-- an anonymous JavaScript function object. Use 'function' to create one with
361-- an anonymous JavaScript function object. Use 'function' to create one with
362-- a name.
362-- a name.
363instance MakeValueRef JSCallAsFunction where
363instance MakeValueRef JSCallAsFunction where
364−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
364+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
365 makeValueRef = function (nullRef::JSStringRef)
365 makeValueRef = function (nullRef::JSStringRef)
366#else
366#else
367 makeValueRef = function (nullPtr::JSStringRef)
367 makeValueRef = function (nullPtr::JSStringRef)
@@ -369,7 +369,7 @@ instance MakeValueRef JSCallAsFunction where
369
369
370instance MakeArgRefs JSCallAsFunction where
370instance MakeArgRefs JSCallAsFunction where
371 makeArgRefs f = do
371 makeArgRefs f = do
372−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
372+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
373 rarg <- function (nullRef::JSStringRef) f
373 rarg <- function (nullRef::JSStringRef) f
374#else
374#else
375 rarg <- function (nullPtr::JSStringRef) f
375 rarg <- function (nullPtr::JSStringRef) f
@@ -377,7 +377,7 @@ instance MakeArgRefs JSCallAsFunction where
377 return [rarg]
377 return [rarg]
378
378
379makeArray :: MakeArgRefs args => args -> JSValueRefRef -> JSC JSObjectRef
379makeArray :: MakeArgRefs args => args -> JSValueRefRef -> JSC JSObjectRef
380−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
380+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
381makeArray args exceptions = makeArgRefs args >>= liftM castRef . liftIO . toArray
381makeArray args exceptions = makeArgRefs args >>= liftM castRef . liftIO . toArray
382#else
382#else
383makeArray args exceptions = do
383makeArray args exceptions = do
@@ -400,7 +400,7 @@ array = rethrow . makeArray
400
400
401-- | JavaScript's global object
401-- | JavaScript's global object
402global :: JSC JSObjectRef
402global :: JSC JSObjectRef
403−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
403+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
404global = liftIO js_window
404global = liftIO js_window
405foreign import javascript unsafe "$r = window"
405foreign import javascript unsafe "$r = window"
406 js_window :: IO JSObjectRef
406 js_window :: IO JSObjectRef
@@ -411,7 +411,7 @@ global = undefined
411#endif
411#endif
412
412
413-- | Get an array containing the property names present on a given object
413-- | Get an array containing the property names present on a given object
414−#if (!defined(__GHCJS__) || !defined(USE_JAVASCRIPTFFI)) && defined(USE_WEBKIT)
414+#if (!defined(ghcjs_HOST_OS) || !defined(USE_JAVASCRIPTFFI)) && defined(USE_WEBKIT)
415copyPropertyNames :: MakeObjectRef this => this -> JSC JSPropertyNameArrayRef
415copyPropertyNames :: MakeObjectRef this => this -> JSC JSPropertyNameArrayRef
416copyPropertyNames this = do
416copyPropertyNames this = do
417 gctxt <- ask
417 gctxt <- ask
@@ -435,7 +435,7 @@ propertyNamesList names = do
435
435
436-- | Get a list containing the property names present on a given object
436-- | Get a list containing the property names present on a given object
437propertyNames :: MakeObjectRef this => this -> JSC [JSStringRef]
437propertyNames :: MakeObjectRef this => this -> JSC [JSStringRef]
438−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
438+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
439propertyNames this = makeObjectRef this >>= liftIO . js_propertyNames >>= liftIO . fromArray
439propertyNames this = makeObjectRef this >>= liftIO . js_propertyNames >>= liftIO . fromArray
440foreign import javascript unsafe "$r = []; h$forIn($1, function(n){$r.push(n);})"
440foreign import javascript unsafe "$r = []; h$forIn($1, function(n){$r.push(n);})"
441 js_propertyNames :: JSObjectRef -> IO (JSArray a)
441 js_propertyNames :: JSObjectRef -> IO (JSArray a)
@@ -456,7 +456,7 @@ objCallAsFunction :: MakeArgRefs args
456 -> args
456 -> args
457 -> JSValueRefRef
457 -> JSValueRefRef
458 -> JSC JSValueRef
458 -> JSC JSValueRef
459−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
459+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
460objCallAsFunction function this args exceptions = do
460objCallAsFunction function this args exceptions = do
461 rargs <- makeArgRefs args >>= liftIO . toArray
461 rargs <- makeArgRefs args >>= liftIO . toArray
462 liftIO $ js_apply function this rargs exceptions
462 liftIO $ js_apply function this rargs exceptions
@@ -478,7 +478,7 @@ objCallAsConstructor :: MakeArgRefs args
478 -> args
478 -> args
479 -> JSValueRefRef
479 -> JSValueRefRef
480 -> JSC JSValueRef
480 -> JSC JSValueRef
481−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
481+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
482objCallAsConstructor function args exceptions = do
482objCallAsConstructor function args exceptions = do
483 rargs <- makeArgRefs args >>= liftIO . toArray
483 rargs <- makeArgRefs args >>= liftIO . toArray
484 liftIO $ js_new function rargs exceptions
484 liftIO $ js_new function rargs exceptions
src/Language/Javascript/JSC/Properties.hs+6−6
@@ -1,7 +1,7 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE TypeSynonymInstances #-}
3{-# LANGUAGE TypeSynonymInstances #-}
4−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
4+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
5{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
5{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
6#endif
6#endif
7-----------------------------------------------------------------------------
7-----------------------------------------------------------------------------
@@ -45,7 +45,7 @@ import Language.Javascript.JSC.Monad (JSC)
45import Language.Javascript.JSC.Types
45import Language.Javascript.JSC.Types
46 (JSValueRefRef, JSObjectRef, JSPropertyAttributes,
46 (JSValueRefRef, JSObjectRef, JSPropertyAttributes,
47 Index(..), JSStringRef)
47 Index(..), JSStringRef)
48−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
48+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
49#else
49#else
50import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSObjectRef
50import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSObjectRef
51 (jsobjectgetpropertyatindex, jsobjectgetproperty,
51 (jsobjectgetpropertyatindex, jsobjectgetproperty,
@@ -88,7 +88,7 @@ objGetPropertyByName :: MakeStringRef name
88 -> name -- ^ name of the property.
88 -> name -- ^ name of the property.
89 -> JSValueRefRef -- ^ exception if one is raised.
89 -> JSValueRefRef -- ^ exception if one is raised.
90 -> JSC JSValueRef -- ^ returns the property value.
90 -> JSC JSValueRef -- ^ returns the property value.
91−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
91+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
92objGetPropertyByName this name = liftIO . js_tryGetProp (makeStringRef name) this
92objGetPropertyByName this name = liftIO . js_tryGetProp (makeStringRef name) this
93foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
93foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
94 js_tryGetProp :: JSStringRef -> JSObjectRef -> JSValueRefRef -> IO JSValueRef
94 js_tryGetProp :: JSStringRef -> JSObjectRef -> JSValueRefRef -> IO JSValueRef
@@ -105,7 +105,7 @@ objGetPropertyAtIndex :: JSObjectRef -- ^ object to find the property on.
105 -> Index -- ^ index of the property.
105 -> Index -- ^ index of the property.
106 -> JSValueRefRef -- ^ exception if one is raised.
106 -> JSValueRefRef -- ^ exception if one is raised.
107 -> JSC JSValueRef -- ^ returns the property value.
107 -> JSC JSValueRef -- ^ returns the property value.
108−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
108+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
109objGetPropertyAtIndex this index = liftIO . js_tryIndex index this
109objGetPropertyAtIndex this index = liftIO . js_tryIndex index this
110foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
110foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
111 js_tryIndex :: Index -> JSObjectRef -> JSValueRefRef -> IO JSValueRef
111 js_tryIndex :: Index -> JSObjectRef -> JSValueRefRef -> IO JSValueRef
@@ -145,7 +145,7 @@ objSetPropertyByName :: (MakeStringRef name, MakeValueRef val)
145 -> JSPropertyAttributes -- ^ property attributes to give the property.
145 -> JSPropertyAttributes -- ^ property attributes to give the property.
146 -> JSValueRefRef -- ^ exception if one is raised.
146 -> JSValueRefRef -- ^ exception if one is raised.
147 -> JSC ()
147 -> JSC ()
148−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
148+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
149objSetPropertyByName this name val attributes exceptions = do
149objSetPropertyByName this name val attributes exceptions = do
150 vref <- makeValueRef val
150 vref <- makeValueRef val
151 liftIO $ js_trySetProp (makeStringRef name) this vref exceptions
151 liftIO $ js_trySetProp (makeStringRef name) this vref exceptions
@@ -167,7 +167,7 @@ objSetPropertyAtIndex :: (MakeValueRef val)
167 -> val -- ^ new value to set the property to.
167 -> val -- ^ new value to set the property to.
168 -> JSValueRefRef -- ^ exception if one is raised.
168 -> JSValueRefRef -- ^ exception if one is raised.
169 -> JSC ()
169 -> JSC ()
170−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
170+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
171objSetPropertyAtIndex this index val exceptions = do
171objSetPropertyAtIndex this index val exceptions = do
172 vref <- makeValueRef val
172 vref <- makeValueRef val
173 liftIO $ js_trySetAtIndex index this vref exceptions
173 liftIO $ js_trySetAtIndex index this vref exceptions
src/Language/Javascript/JSC/String.hs+3−3
@@ -26,7 +26,7 @@ import Data.Text (Text)
26import qualified Data.Text as T (pack)
26import qualified Data.Text as T (pack)
27import Control.Monad.IO.Class (MonadIO(..))
27import Control.Monad.IO.Class (MonadIO(..))
28import Language.Javascript.JSC.Types (JSStringRef)
28import Language.Javascript.JSC.Types (JSStringRef)
29−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
29+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
30import GHCJS.Foreign (fromJSString, toJSString)
30import GHCJS.Foreign (fromJSString, toJSString)
31#else
31#else
32import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSStringRef
32import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSStringRef
@@ -51,7 +51,7 @@ instance MakeStringRef String where
51
51
52-- | Convert a JavaScript string to a Haskell 'Text'
52-- | Convert a JavaScript string to a Haskell 'Text'
53strToText :: MonadIO m => JSStringRef -> m Text
53strToText :: MonadIO m => JSStringRef -> m Text
54−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
54+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
55strToText = return . fromJSString
55strToText = return . fromJSString
56#else
56#else
57strToText jsstring = liftIO $ do
57strToText jsstring = liftIO $ do
@@ -62,7 +62,7 @@ strToText jsstring = liftIO $ do
62
62
63-- | Convert a Haskell 'Text' to a JavaScript string
63-- | Convert a Haskell 'Text' to a JavaScript string
64textToStr :: Text -> JSStringRef
64textToStr :: Text -> JSStringRef
65−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
65+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
66textToStr = toJSString
66textToStr = toJSString
67#else
67#else
68textToStr text = unsafePerformIO $
68textToStr text = unsafePerformIO $
src/Language/Javascript/JSC/Types.hs+2−2
@@ -22,7 +22,7 @@ module Language.Javascript.JSC.Types (
22 , Index(..)
22 , Index(..)
23) where
23) where
24
24
25−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
25+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
26import GHCJS.Types
26import GHCJS.Types
27import Data.Word (Word(..))
27import Data.Word (Word(..))
28#else
28#else
@@ -33,7 +33,7 @@ import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSObjectRef (JSPropertyAttributes)
33import Foreign.C (CUInt(..))
33import Foreign.C (CUInt(..))
34#endif
34#endif
35
35
36−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
36+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
37data ValueOrObject
37data ValueOrObject
38data Object
38data Object
39data PropertyNameArray
39data PropertyNameArray
src/Language/Javascript/JSC/Value.hs+13−13
@@ -2,7 +2,7 @@
2{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE TypeSynonymInstances #-}
4{-# LANGUAGE TypeSynonymInstances #-}
5−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
5+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
6{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
6{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
7#endif
7#endif
8-----------------------------------------------------------------------------
8-----------------------------------------------------------------------------
@@ -66,7 +66,7 @@ module Language.Javascript.JSC.Value (
66import Prelude hiding (catch)
66import Prelude hiding (catch)
67import Language.Javascript.JSC.Types
67import Language.Javascript.JSC.Types
68 (JSValueRefRef, JSObjectRef, JSStringRef, JSValueRef)
68 (JSValueRefRef, JSObjectRef, JSStringRef, JSValueRef)
69−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
69+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
70import GHCJS.Types (castRef, JSRef(..))
70import GHCJS.Types (castRef, JSRef(..))
71import GHCJS.Foreign (toJSBool, fromJSBool', jsNull, jsUndefined, toJSString)
71import GHCJS.Foreign (toJSBool, fromJSBool', jsNull, jsUndefined, toJSString)
72import GHCJS.Marshal (toJSRef)
72import GHCJS.Marshal (toJSRef)
@@ -136,7 +136,7 @@ data JSValue = ValNull -- ^ null
136-- >>> testJSC $ valToBool "1"
136-- >>> testJSC $ valToBool "1"
137-- true
137-- true
138valToBool :: MakeValueRef val => val -> JSC JSBool
138valToBool :: MakeValueRef val => val -> JSC JSBool
139−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
139+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
140valToBool val = fromJSBool' <$> makeValueRef val
140valToBool val = fromJSBool' <$> makeValueRef val
141#else
141#else
142valToBool val = do
142valToBool val = do
@@ -165,7 +165,7 @@ valToBool val = do
165-- >>> testJSC $ show <$> valToNumber "1"
165-- >>> testJSC $ show <$> valToNumber "1"
166-- 1.0
166-- 1.0
167valToNumber :: MakeValueRef val => val -> JSC JSNumber
167valToNumber :: MakeValueRef val => val -> JSC JSNumber
168−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
168+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
169valToNumber val = jsrefToNumber <$> makeValueRef val
169valToNumber val = jsrefToNumber <$> makeValueRef val
170foreign import javascript unsafe "$r = Number($1);" jsrefToNumber :: JSRef a -> Double
170foreign import javascript unsafe "$r = Number($1);" jsrefToNumber :: JSRef a -> Double
171#elif defined(USE_WEBKIT)
171#elif defined(USE_WEBKIT)
@@ -197,7 +197,7 @@ valToNumber = undefined
197-- >>> testJSC $ valToStr "1" >>= strToText
197-- >>> testJSC $ valToStr "1" >>= strToText
198-- 1
198-- 1
199valToStr :: MakeValueRef val => val -> JSC JSStringRef
199valToStr :: MakeValueRef val => val -> JSC JSStringRef
200−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
200+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
201valToStr val = jsrefToString <$> makeValueRef val
201valToStr val = jsrefToString <$> makeValueRef val
202foreign import javascript unsafe "$r = $1.toString();" jsrefToString :: JSRef a -> JSStringRef
202foreign import javascript unsafe "$r = $1.toString();" jsrefToString :: JSRef a -> JSStringRef
203#elif defined(USE_WEBKIT)
203#elif defined(USE_WEBKIT)
@@ -253,7 +253,7 @@ valToText jsvar = valToStr jsvar >>= strToText
253-- >>> testJSC $ obj >>= valToJSON 0 >>= strToText
253-- >>> testJSC $ obj >>= valToJSON 0 >>= strToText
254-- {}
254-- {}
255valToJSON :: MakeValueRef val => Word -> val -> JSC JSStringRef
255valToJSON :: MakeValueRef val => Word -> val -> JSC JSStringRef
256−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
256+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
257valToJSON indent val = jsrefToJSON <$> makeValueRef val
257valToJSON indent val = jsrefToJSON <$> makeValueRef val
258foreign import javascript unsafe "$r = JSON.stringify($1);" jsrefToJSON :: JSRef a -> JSStringRef
258foreign import javascript unsafe "$r = JSON.stringify($1);" jsrefToJSON :: JSRef a -> JSStringRef
259#elif defined(USE_WEBKIT)
259#elif defined(USE_WEBKIT)
@@ -285,7 +285,7 @@ valToJSON = undefined
285-- >>> testJSC $ valToObject "1"
285-- >>> testJSC $ valToObject "1"
286-- 1
286-- 1
287valToObject :: MakeValueRef val => val -> JSC JSObjectRef
287valToObject :: MakeValueRef val => val -> JSC JSObjectRef
288−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
288+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
289valToObject val = castRef <$> makeValueRef val
289valToObject val = castRef <$> makeValueRef val
290#else
290#else
291valToObject val = do
291valToObject val = do
@@ -316,7 +316,7 @@ instance MakeValueRef v => MakeValueRef (JSC v) where
316----------- null ---------------
316----------- null ---------------
317-- | Make a @null@ JavaScript value
317-- | Make a @null@ JavaScript value
318valMakeNull :: JSC JSValueRef
318valMakeNull :: JSC JSValueRef
319−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
319+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
320valMakeNull = return jsNull
320valMakeNull = return jsNull
321#else
321#else
322valMakeNull = ask >>= (liftIO . jsvaluemakenull)
322valMakeNull = ask >>= (liftIO . jsvaluemakenull)
@@ -333,7 +333,7 @@ instance MakeArgRefs JSNull where
333----------- undefined ---------------
333----------- undefined ---------------
334-- | Make an @undefined@ JavaScript value
334-- | Make an @undefined@ JavaScript value
335valMakeUndefined :: JSC JSValueRef
335valMakeUndefined :: JSC JSValueRef
336−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
336+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
337valMakeUndefined = return jsUndefined
337valMakeUndefined = return jsUndefined
338#else
338#else
339valMakeUndefined = ask >>= (liftIO . jsvaluemakeundefined)
339valMakeUndefined = ask >>= (liftIO . jsvaluemakeundefined)
@@ -355,7 +355,7 @@ instance MakeArgRefs () where
355----------- booleans ---------------
355----------- booleans ---------------
356-- | Make a JavaScript boolean value
356-- | Make a JavaScript boolean value
357valMakeBool :: JSBool -> JSC JSValueRef
357valMakeBool :: JSBool -> JSC JSValueRef
358−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
358+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
359valMakeBool b = return . castRef $ toJSBool b
359valMakeBool b = return . castRef $ toJSBool b
360#else
360#else
361valMakeBool b = do
361valMakeBool b = do
@@ -374,7 +374,7 @@ instance MakeArgRefs Bool where
374----------- numbers ---------------
374----------- numbers ---------------
375-- | Make a JavaScript number
375-- | Make a JavaScript number
376valMakeNumber :: JSNumber -> JSC JSValueRef
376valMakeNumber :: JSNumber -> JSC JSValueRef
377−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
377+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
378valMakeNumber n = liftIO $ castRef <$> toJSRef n
378valMakeNumber n = liftIO $ castRef <$> toJSRef n
379#else
379#else
380valMakeNumber n = do
380valMakeNumber n = do
@@ -393,7 +393,7 @@ instance MakeArgRefs Double where
393----------- numbers ---------------
393----------- numbers ---------------
394-- | Make a JavaScript string
394-- | Make a JavaScript string
395valMakeString :: Text -> JSC JSValueRef
395valMakeString :: Text -> JSC JSValueRef
396−#if (defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
396+#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
397valMakeString = return . castRef . toJSString
397valMakeString = return . castRef . toJSString
398#else
398#else
399valMakeString text = do
399valMakeString text = do
@@ -434,7 +434,7 @@ instance MakeValueRef String where
434-- >>> testJSC $ show <$> valToObject True >>= deRefVal
434-- >>> testJSC $ show <$> valToObject True >>= deRefVal
435-- ValObject 0x...
435-- ValObject 0x...
436deRefVal :: MakeValueRef val => val -> JSC JSValue
436deRefVal :: MakeValueRef val => val -> JSC JSValue
437−#if defined(__GHCJS__) && defined(USE_JAVASCRIPTFFI)
437+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
438deRefVal val = do
438deRefVal val = do
439 gctxt <- ask
439 gctxt <- ask
440 valref <- makeValueRef val
440 valref <- makeValueRef val