@@ -86,8 +86,8 @@ module Language.Javascript.JSaddle.Object (
87import Prelude hiding ((!!))
87import Prelude hiding ((!!))
88import Language.Javascript.JSaddle.Types
88import Language.Javascript.JSaddle.Types
89− (JSPropertyNameArrayRef, JSStringRef, Object(..), JSValueRefRef,
89+ (JSPropertyNameArray, JSString, Object(..), MutableJSArray,
90− JSValueRef, JSContextRef, Index)
90+ JSVal, Index)
91import Foreign.C.Types (CSize(..), CULong(..), CUInt(..), CULLong(..))
91import Foreign.C.Types (CSize(..), CULong(..), CUInt(..), CULLong(..))
92#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
92#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
93import GHCJS.Types (nullRef, jsval)
93import GHCJS.Types (nullRef, jsval)
@@ -119,7 +119,7 @@ import Language.Javascript.JSaddle.Exception (rethrow)
119import Language.Javascript.JSaddle.Value
119import Language.Javascript.JSaddle.Value
120 (JSUndefined, valMakeUndefined, valToObject)
120 (JSUndefined, valMakeUndefined, valToObject)
121import Language.Javascript.JSaddle.Classes
121import Language.Javascript.JSaddle.Classes
122− (MakeValueRef(..), MakeStringRef(..), MakeArgRefs(..), MakeObject(..))
122+ (MakeVal(..), MakeString(..), MakeArgs(..), MakeObject(..))
123import Language.Javascript.JSaddle.Monad
123import Language.Javascript.JSaddle.Monad
125import Control.Monad.Trans.Reader (runReaderT, ask)
125import Control.Monad.Trans.Reader (runReaderT, ask)
@@ -149,15 +149,15 @@ instance MakeObject v => MakeObject (JSM v) where
149-- >>> testJSaddle $ eval "'Hello World'.length"
149-- >>> testJSaddle $ eval "'Hello World'.length"
150-- >>> testJSaddle $ val "Hello World" ! "length"
150-- >>> testJSaddle $ val "Hello World" ! "length"
152−(!) :: (MakeObject this, MakeStringRef name)
152+(!) :: (MakeObject this, MakeString name)
153 => this -- ^ Object to look on
153 => this -- ^ Object to look on
154 -> name -- ^ Name of the property to find
154 -> name -- ^ Name of the property to find
155− -> JSM JSValueRef -- ^ Property reference
155+ -> JSM JSVal -- ^ Property reference
156this ! name = do
156this ! name = do
157 rthis <- makeObject this
157 rthis <- makeObject this
158 rethrow $ objGetPropertyByName rthis rname
158 rethrow $ objGetPropertyByName rthis rname
160− rname = makeStringRef name
160+ rname = makeString name
161{-# INLINE (!) #-}
161{-# INLINE (!) #-}
163-- | Lookup a property based on its index.
163-- | Lookup a property based on its index.
@@ -168,7 +168,7 @@ this ! name = do
168(!!) :: (MakeObject this)
168(!!) :: (MakeObject this)
169 => this -- ^ Object to look on
169 => this -- ^ Object to look on
170 -> Index -- ^ Index of the property to lookup
170 -> Index -- ^ Index of the property to lookup
171− -> JSM JSValueRef -- ^ Property reference
171+ -> JSM JSVal -- ^ Property reference
172this !! index = do
172this !! index = do
173 rthis <- makeObject this
173 rthis <- makeObject this
174 rethrow $ objGetPropertyAtIndex rthis index
174 rethrow $ objGetPropertyAtIndex rthis index
@@ -181,9 +181,9 @@ this !! index = do
181-- >>> testJSaddle $ eval "'Hello World'.length"
181-- >>> testJSaddle $ eval "'Hello World'.length"
182-- >>> testJSaddle $ val "Hello World" ^. js "length"
182-- >>> testJSaddle $ val "Hello World" ^. js "length"
184−js :: (MakeObject s, MakeStringRef name)
184+js :: (MakeObject s, MakeString name)
185 => name -- ^ Name of the property to find
185 => name -- ^ Name of the property to find
186− -> IndexPreservingGetter s (JSM JSValueRef)
186+ -> IndexPreservingGetter s (JSM JSVal)
187js name = to (!name)
187js name = to (!name)
188{-# INLINE js #-}
188{-# INLINE js #-}
@@ -194,7 +194,7 @@ js name = to (!name)
194-- >>> testJSaddle $ eval "'Hello World'.length"
194-- >>> testJSaddle $ eval "'Hello World'.length"
195-- >>> testJSaddle $ val "Hello World" ^. js "length"
195-- >>> testJSaddle $ val "Hello World" ^. js "length"
197−jss :: (MakeStringRef name, MakeValueRef val)
197+jss :: (MakeString name, MakeVal val)
198 => name -- ^ Name of the property to find
198 => name -- ^ Name of the property to find
200 -> forall o . MakeObject o => IndexPreservingGetter o (JSM ())
200 -> forall o . MakeObject o => IndexPreservingGetter o (JSM ())
@@ -207,12 +207,12 @@ jss name val = to (\o -> o <# name $ val)
208-- >>> testJSaddle $ val "Hello World" ^. jsf "indexOf" ["World"]
208-- >>> testJSaddle $ val "Hello World" ^. jsf "indexOf" ["World"]
210−jsf :: (MakeStringRef name, MakeArgRefs args) => name -> args -> JSF
210+jsf :: (MakeString name, MakeArgs args) => name -> args -> JSF
211jsf name args = to (\o -> o # name $ args)
211jsf name args = to (\o -> o # name $ args)
212{-# INLINE jsf #-}
212{-# INLINE jsf #-}
214-- | Java script function applications have this type
214-- | Java script function applications have this type
215−type JSF = forall o . MakeObject o => IndexPreservingGetter o (JSM JSValueRef)
215+type JSF = forall o . MakeObject o => IndexPreservingGetter o (JSM JSVal)
217-- | Handy way to call a function that expects no arguments
217-- | Handy way to call a function that expects no arguments
@@ -220,7 +220,7 @@ type JSF = forall o . MakeObject o => IndexPreservingGetter o (JSM JSValueRef)
221-- >>> testJSaddle $ val "Hello World" ^. js0 "toLowerCase"
221-- >>> testJSaddle $ val "Hello World" ^. js0 "toLowerCase"
222-- hello world
222-- hello world
223−js0 :: (MakeStringRef name) => name -> JSF
223+js0 :: (MakeString name) => name -> JSF
224js0 name = jsf name ()
224js0 name = jsf name ()
225{-# INLINE js0 #-}
225{-# INLINE js0 #-}
@@ -230,31 +230,31 @@ js0 name = jsf name ()
231-- >>> testJSaddle $ val "Hello World" ^. js1 "indexOf" "World"
231-- >>> testJSaddle $ val "Hello World" ^. js1 "indexOf" "World"
233−js1 :: (MakeStringRef name, MakeValueRef a0) => name -> a0 -> JSF
233+js1 :: (MakeString name, MakeVal a0) => name -> a0 -> JSF
234js1 name a0 = jsf name [a0]
234js1 name a0 = jsf name [a0]
235{-# INLINE js1 #-}
235{-# INLINE js1 #-}
237-- | Handy way to call a function that expects two arguments
237-- | Handy way to call a function that expects two arguments
238−js2 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1) => name -> a0 -> a1 -> JSF
238+js2 :: (MakeString name, MakeVal a0, MakeVal a1) => name -> a0 -> a1 -> JSF
239js2 name a0 a1 = jsf name (a0, a1)
239js2 name a0 a1 = jsf name (a0, a1)
240{-# INLINE js2 #-}
240{-# INLINE js2 #-}
242-- | Handy way to call a function that expects three arguments
242-- | Handy way to call a function that expects three arguments
243−js3 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2)
243+js3 :: (MakeString name, MakeVal a0, MakeVal a1, MakeVal a2)
244 => name -> a0 -> a1 -> a2 -> JSF
244 => name -> a0 -> a1 -> a2 -> JSF
245js3 name a0 a1 a2 = jsf name (a0, a1, a2)
245js3 name a0 a1 a2 = jsf name (a0, a1, a2)
246{-# INLINE js3 #-}
246{-# INLINE js3 #-}
248-- | Handy way to call a function that expects four arguments
248-- | Handy way to call a function that expects four arguments
249−js4 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2,
249+js4 :: (MakeString name, MakeVal a0, MakeVal a1, MakeVal a2,
250− MakeValueRef a3)
250+ MakeVal a3)
251 => name -> a0 -> a1 -> a2 -> a3 -> JSF
251 => name -> a0 -> a1 -> a2 -> a3 -> JSF
252js4 name a0 a1 a2 a3 = jsf name (a0, a1, a2, a3)
252js4 name a0 a1 a2 a3 = jsf name (a0, a1, a2, a3)
253{-# INLINE js4 #-}
253{-# INLINE js4 #-}
255-- | Handy way to call a function that expects five arguments
255-- | Handy way to call a function that expects five arguments
256−js5 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2,
256+js5 :: (MakeString name, MakeVal a0, MakeVal a1, MakeVal a2,
257− MakeValueRef a3, MakeValueRef a4)
257+ MakeVal a3, MakeVal a4)
258 => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSF
258 => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSF
259js5 name a0 a1 a2 a3 a4 = jsf name (a0, a1, a2, a3, a4)
259js5 name a0 a1 a2 a3 a4 = jsf name (a0, a1, a2, a3, a4)
260{-# INLINE js5 #-}
260{-# INLINE js5 #-}
@@ -265,7 +265,7 @@ js5 name a0 a1 a2 a3 a4 = jsf name (a0, a1, a2, a3, a4)
265-- >>> testJSaddle $ eval "w = console; w.log('Hello World')"
265-- >>> testJSaddle $ eval "w = console; w.log('Hello World')"
266-- >>> testJSaddle $ do w <- jsg "console"; w ^. js "log" # ["Hello World"]
266-- >>> testJSaddle $ do w <- jsg "console"; w ^. js "log" # ["Hello World"]
268−jsg :: MakeStringRef a => a -> JSM JSValueRef
268+jsg :: MakeString a => a -> JSM JSVal
269jsg name = global ! name
269jsg name = global ! name
270{-# INLINE jsg #-}
270{-# INLINE jsg #-}
@@ -275,7 +275,7 @@ jsg name = global ! name
276-- >>> testJSaddle $ jsf "globalFunc" ["World"]
276-- >>> testJSaddle $ jsf "globalFunc" ["World"]
278−jsgf :: (MakeStringRef name, MakeArgRefs args) => name -> args -> JSM JSValueRef
278+jsgf :: (MakeString name, MakeArgs args) => name -> args -> JSM JSVal
279jsgf name = global # name
279jsgf name = global # name
280{-# INLINE jsgf #-}
280{-# INLINE jsgf #-}
@@ -285,7 +285,7 @@ jsgf name = global # name
286-- >>> testJSaddle $ js0 "globalFunc"
286-- >>> testJSaddle $ js0 "globalFunc"
287-- hello world
287-- hello world
288−jsg0 :: (MakeStringRef name) => name -> JSM JSValueRef
288+jsg0 :: (MakeString name) => name -> JSM JSVal
289jsg0 name = jsgf name ()
289jsg0 name = jsgf name ()
290{-# INLINE jsg0 #-}
290{-# INLINE jsg0 #-}
@@ -295,32 +295,32 @@ jsg0 name = jsgf name ()
296-- >>> testJSaddle $ jsg1 "globalFunc" "World"
296-- >>> testJSaddle $ jsg1 "globalFunc" "World"
298−jsg1 :: (MakeStringRef name, MakeValueRef a0) => name -> a0 -> JSM JSValueRef
298+jsg1 :: (MakeString name, MakeVal a0) => name -> a0 -> JSM JSVal
299jsg1 name a0 = jsgf name [a0]
299jsg1 name a0 = jsgf name [a0]
300{-# INLINE jsg1 #-}
300{-# INLINE jsg1 #-}
302-- | Handy way to call a function that expects two arguments
302-- | Handy way to call a function that expects two arguments
303−jsg2 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1) => name -> a0 -> a1 -> JSM JSValueRef
303+jsg2 :: (MakeString name, MakeVal a0, MakeVal a1) => name -> a0 -> a1 -> JSM JSVal
304jsg2 name a0 a1 = jsgf name (a0, a1)
304jsg2 name a0 a1 = jsgf name (a0, a1)
305{-# INLINE jsg2 #-}
305{-# INLINE jsg2 #-}
307-- | Handy way to call a function that expects three arguments
307-- | Handy way to call a function that expects three arguments
308−jsg3 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2)
308+jsg3 :: (MakeString name, MakeVal a0, MakeVal a1, MakeVal a2)
309− => name -> a0 -> a1 -> a2 -> JSM JSValueRef
309+ => name -> a0 -> a1 -> a2 -> JSM JSVal
310jsg3 name a0 a1 a2 = jsgf name (a0, a1, a2)
310jsg3 name a0 a1 a2 = jsgf name (a0, a1, a2)
311{-# INLINE jsg3 #-}
311{-# INLINE jsg3 #-}
313-- | Handy way to call a function that expects four arguments
313-- | Handy way to call a function that expects four arguments
314−jsg4 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2,
314+jsg4 :: (MakeString name, MakeVal a0, MakeVal a1, MakeVal a2,
315− MakeValueRef a3)
315+ MakeVal a3)
316− => name -> a0 -> a1 -> a2 -> a3 -> JSM JSValueRef
316+ => name -> a0 -> a1 -> a2 -> a3 -> JSM JSVal
317jsg4 name a0 a1 a2 a3 = jsgf name (a0, a1, a2, a3)
317jsg4 name a0 a1 a2 a3 = jsgf name (a0, a1, a2, a3)
318{-# INLINE jsg4 #-}
318{-# INLINE jsg4 #-}
320-- | Handy way to call a function that expects five arguments
320-- | Handy way to call a function that expects five arguments
321−jsg5 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2,
321+jsg5 :: (MakeString name, MakeVal a0, MakeVal a1, MakeVal a2,
322− MakeValueRef a3, MakeValueRef a4)
322+ MakeVal a3, MakeVal a4)
323− => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSM JSValueRef
323+ => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSM JSVal
324jsg5 name a0 a1 a2 a3 a4 = jsgf name (a0, a1, a2, a3, a4)
324jsg5 name a0 a1 a2 a3 a4 = jsgf name (a0, a1, a2, a3, a4)
325{-# INLINE jsg5 #-}
325{-# INLINE jsg5 #-}
@@ -330,8 +330,8 @@ jsg5 name a0 a1 a2 a3 a4 = jsgf name (a0, a1, a2, a3, a4)
330-- >>> testJSaddle $ val "Hello World" # "indexOf" $ ["World"]
330-- >>> testJSaddle $ val "Hello World" # "indexOf" $ ["World"]
332infixr 2 #
332infixr 2 #
333−(#) :: (MakeObject this, MakeStringRef name, MakeArgRefs args)
333+(#) :: (MakeObject this, MakeString name, MakeArgs args)
334− => this -> name -> args -> JSM JSValueRef
334+ => this -> name -> args -> JSM JSVal
335(#) this name args = do
335(#) this name args = do
336 rthis <- makeObject this
336 rthis <- makeObject this
337 f <- rethrow $ objGetPropertyByName rthis name
337 f <- rethrow $ objGetPropertyByName rthis name
@@ -344,8 +344,8 @@ infixr 2 #
344-- >>> testJSaddle $ eval "something[6]('World')"
344-- >>> testJSaddle $ eval "something[6]('World')"
345-- >>> testJSaddle $ val something ## 6 ["World"]
345-- >>> testJSaddle $ val something ## 6 ["World"]
346infixr 2 ##
346infixr 2 ##
347−(##) :: (MakeObject this, MakeArgRefs args)
347+(##) :: (MakeObject this, MakeArgs args)
348− => this -> Index -> args -> JSM JSValueRef
348+ => this -> Index -> args -> JSM JSVal
349(##) this index args = do
349(##) this index args = do
350 rthis <- makeObject this
350 rthis <- makeObject this
351 f <- rethrow $ objGetPropertyAtIndex rthis index
351 f <- rethrow $ objGetPropertyAtIndex rthis index
@@ -359,7 +359,7 @@ infixr 2 ##
359-- >>> testJSaddle $ do {j <- eval "({})"; j <# "x" 1; j!"x"}
359-- >>> testJSaddle $ do {j <- eval "({})"; j <# "x" 1; j!"x"}
361infixr 1 <#
361infixr 1 <#
362−(<#) :: (MakeObject this, MakeStringRef name, MakeValueRef val)
362+(<#) :: (MakeObject this, MakeString name, MakeVal val)
363 => this -- ^ Object to set the property on
363 => this -- ^ Object to set the property on
364 -> name -- ^ Name of the property to set
364 -> name -- ^ Name of the property to set
365 -> val -- ^ Value to set it to
365 -> val -- ^ Value to set it to
@@ -375,7 +375,7 @@ infixr 1 <#
375-- >>> testJSaddle $ do {j <- eval "({})"; j <## 6 1; j!!6}
375-- >>> testJSaddle $ do {j <- eval "({})"; j <## 6 1; j!!6}
377infixr 1 <##
377infixr 1 <##
378−(<##) :: (MakeObject this, MakeValueRef val)
378+(<##) :: (MakeObject this, MakeVal val)
379 => this -- ^ Object to set the property on
379 => this -- ^ Object to set the property on
380 -> Index -- ^ Index of the property to set
380 -> Index -- ^ Index of the property to set
381 -> val -- ^ Value to set it to
381 -> val -- ^ Value to set it to
@@ -392,10 +392,10 @@ infixr 1 <##
393-- >>> testJSaddle $ new "Date" (2013, 1, 1)
393-- >>> testJSaddle $ new "Date" (2013, 1, 1)
394-- Fri Feb 01 2013 00:00:00 GMT+1300 (NZDT)
394-- Fri Feb 01 2013 00:00:00 GMT+1300 (NZDT)
395−new :: (MakeObject constructor, MakeArgRefs args)
395+new :: (MakeObject constructor, MakeArgs args)
396 => constructor
396 => constructor
398− -> JSM JSValueRef
398+ -> JSM JSVal
399new constructor args = do
399new constructor args = do
400 f <- makeObject constructor
400 f <- makeObject constructor
401 rethrow $ objCallAsConstructor f args
401 rethrow $ objCallAsConstructor f args
@@ -406,8 +406,8 @@ new constructor args = do
406-- >>> testJSaddle $ eval "(function(){return this;}).apply('Hello', [])"
406-- >>> testJSaddle $ eval "(function(){return this;}).apply('Hello', [])"
407-- >>> testJSaddle $ do { test <- eval "(function(){return this;})"; call test (val "Hello") () }
407-- >>> testJSaddle $ do { test <- eval "(function(){return this;})"; call test (val "Hello") () }
409−call :: (MakeObject function, MakeObject this, MakeArgRefs args)
409+call :: (MakeObject function, MakeObject this, MakeArgs args)
410− => function -> this -> args -> JSM JSValueRef
410+ => function -> this -> args -> JSM JSVal
411call function this args = do
411call function this args = do
412 rfunction <- makeObject function
412 rfunction <- makeObject function
413 rthis <- makeObject this
413 rthis <- makeObject this
@@ -430,9 +430,9 @@ obj = do
430{-# INLINE obj #-}
430{-# INLINE obj #-}
432-- | Type used for Haskell functions called from JavaScript.
432-- | Type used for Haskell functions called from JavaScript.
433−type JSCallAsFunction = JSValueRef -- ^ Function object
433+type JSCallAsFunction = JSVal -- ^ Function object
434− -> JSValueRef -- ^ this
434+ -> JSVal -- ^ this
435− -> [JSValueRef] -- ^ Function arguments
435+ -> [JSVal] -- ^ Function arguments
436 -> JSM JSUndefined -- ^ Only 'JSUndefined' can be returned because
436 -> JSM JSUndefined -- ^ Only 'JSUndefined' can be returned because
437 -- the function may need to be executed in a
437 -- the function may need to be executed in a
438 -- different thread. If you need to get a
438 -- different thread. If you need to get a
@@ -456,7 +456,7 @@ foreign import ccall "wrapper"
458-- ^ Make a JavaScript function object that wraps a Haskell function.
458-- ^ Make a JavaScript function object that wraps a Haskell function.
459−function :: MakeStringRef name
459+function :: MakeString name
460 => name -- ^ Name of the function
460 => name -- ^ Name of the function
461 -> JSCallAsFunction -- ^ Haskell function to call
461 -> JSCallAsFunction -- ^ Haskell function to call
462 -> JSM Object -- ^ Returns a JavaScript function object that will
462 -> JSM Object -- ^ Returns a JavaScript function object that will
@@ -466,21 +466,21 @@ function name f = liftIO $ do
466 callback <- syncCallback2 ContinueAsync $ \this args -> do
466 callback <- syncCallback2 ContinueAsync $ \this args -> do
467 rargs <- Array.toListIO (coerce args)
467 rargs <- Array.toListIO (coerce args)
468 runReaderT (f this this rargs) () -- TODO pass function object through
468 runReaderT (f this this rargs) () -- TODO pass function object through
469− makeFunctionWithCallback (makeStringRef name) callback
469+ makeFunctionWithCallback (makeString name) callback
470foreign import javascript unsafe "$r = function () { $2(this, arguments); }"
470foreign import javascript unsafe "$r = function () { $2(this, arguments); }"
471− makeFunctionWithCallback :: JSStringRef -> Callback (JSValueRef -> JSValueRef -> IO ()) -> IO Object
471+ makeFunctionWithCallback :: JSString -> Callback (JSVal -> JSVal -> IO ()) -> IO Object
472#elif defined(USE_WEBKIT)
472#elif defined(USE_WEBKIT)
473function name f = do
473function name f = do
474 gctxt <- ask
474 gctxt <- ask
475 callback <- liftIO $ mkJSObjectCallAsFunctionCallback wrap
475 callback <- liftIO $ mkJSObjectCallAsFunctionCallback wrap
476− liftIO $ Object <$> jsobjectmakefunctionwithcallback gctxt (makeStringRef name) callback
476+ liftIO $ Object <$> jsobjectmakefunctionwithcallback gctxt (makeString name) callback
478 wrap ctx fobj this argc argv exception = do
478 wrap ctx fobj this argc argv exception = do
479 args <- peekArray (fromIntegral argc) argv
479 args <- peekArray (fromIntegral argc) argv
480 (`runReaderT` ctx) $
480 (`runReaderT` ctx) $
481− f fobj this args >>= makeValueRef
481+ f fobj this args >>= makeVal
482 `E.catch` \(e :: SomeException) -> do
482 `E.catch` \(e :: SomeException) -> do
483− str <- runReaderT (makeValueRef . T.pack $ show e) ctx
483+ str <- runReaderT (makeVal . T.pack $ show e) ctx
484 poke exception str
484 poke exception str
485 jsvaluemakeundefined ctx
485 jsvaluemakeundefined ctx
@@ -490,33 +490,33 @@ function = undefined
490-- | A callback to Haskell can be used as a JavaScript value. This will create
490-- | A callback to Haskell can be used as a JavaScript value. This will create
491-- an anonymous JavaScript function object. Use 'function' to create one with
491-- an anonymous JavaScript function object. Use 'function' to create one with
492-- a name.
492-- a name.
493−instance MakeValueRef JSCallAsFunction where
493+instance MakeVal JSCallAsFunction where
494#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
494#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
495− makeValueRef f = jsval <$> function (pFromJSVal nullRef :: JSStringRef) f
495+ makeVal f = jsval <$> function (pFromJSVal nullRef :: JSString) f
497− makeValueRef f = function (nullPtr :: JSStringRef) f >>= makeValueRef
497+ makeVal f = function (nullPtr :: JSString) f >>= makeVal
499− {-# INLINE makeValueRef #-}
499+ {-# INLINE makeVal #-}
501−instance MakeArgRefs JSCallAsFunction where
501+instance MakeArgs JSCallAsFunction where
502− makeArgRefs f = do
502+ makeArgs f = do
503#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
503#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
504− rarg <- jsval <$> function (pFromJSVal nullRef :: JSStringRef) f
504+ rarg <- jsval <$> function (pFromJSVal nullRef :: JSString) f
506− rarg <- function (nullPtr:: JSStringRef) f >>= makeValueRef
506+ rarg <- function (nullPtr:: JSString) f >>= makeVal
508 return [rarg]
508 return [rarg]
509− {-# INLINE makeArgRefs #-}
509+ {-# INLINE makeArgs #-}
511−makeArray :: MakeArgRefs args => args -> JSValueRefRef -> JSM Object
511+makeArray :: MakeArgs args => args -> MutableJSArray -> JSM Object
512#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
512#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
513makeArray args exceptions = do
513makeArray args exceptions = do
514− rargs <- makeArgRefs args
514+ rargs <- makeArgs args
515 liftIO $ Object . jsval <$> Array.fromListIO rargs
515 liftIO $ Object . jsval <$> Array.fromListIO rargs
517makeArray args exceptions = do
517makeArray args exceptions = do
518 gctxt <- ask
518 gctxt <- ask
519− rargs <- makeArgRefs args
519+ rargs <- makeArgs args
520 liftIO $ withArrayLen rargs $ \ len ptr ->
520 liftIO $ withArrayLen rargs $ \ len ptr ->
521 Object <$> jsobjectmakearray gctxt (fromIntegral len) ptr exceptions
521 Object <$> jsobjectmakearray gctxt (fromIntegral len) ptr exceptions
@@ -530,7 +530,7 @@ makeArray args exceptions = do
530-- >>> testJSaddle $ eval "['Hello', null, undefined, true, 1]"
530-- >>> testJSaddle $ eval "['Hello', null, undefined, true, 1]"
531-- >>> testJSaddle $ array ("Hello", JSNull, (), True, 1.0::Double)
531-- >>> testJSaddle $ array ("Hello", JSNull, (), True, 1.0::Double)
532-- Hello,,,true,1
532-- Hello,,,true,1
533−array :: MakeArgRefs args => args -> JSM Object
533+array :: MakeArgs args => args -> JSM Object
534array = rethrow . makeArray
534array = rethrow . makeArray
536-- | JavaScript's global object
536-- | JavaScript's global object
@@ -549,7 +549,7 @@ global = undefined
550-- | Get an array containing the property names present on a given object
550-- | Get an array containing the property names present on a given object
551#if (!defined(ghcjs_HOST_OS) || !defined(USE_JAVASCRIPTFFI)) && defined(USE_WEBKIT)
551#if (!defined(ghcjs_HOST_OS) || !defined(USE_JAVASCRIPTFFI)) && defined(USE_WEBKIT)
552−copyPropertyNames :: MakeObject this => this -> JSM JSPropertyNameArrayRef
552+copyPropertyNames :: MakeObject this => this -> JSM JSPropertyNameArray
553copyPropertyNames this = do
553copyPropertyNames this = do
554 gctxt <- ask
554 gctxt <- ask
555 Object rthis <- makeObject this
555 Object rthis <- makeObject this
@@ -557,17 +557,17 @@ copyPropertyNames this = do
557{-# INLINE copyPropertyNames #-}
557{-# INLINE copyPropertyNames #-}
559-- | Get the number of names in a property name array
559-- | Get the number of names in a property name array
560−propertyNamesCount :: MonadIO m => JSPropertyNameArrayRef -> m CSize
560+propertyNamesCount :: MonadIO m => JSPropertyNameArray -> m CSize
561propertyNamesCount names = liftIO $ jspropertynamearraygetcount names
561propertyNamesCount names = liftIO $ jspropertynamearraygetcount names
562{-# INLINE propertyNamesCount #-}
562{-# INLINE propertyNamesCount #-}
564-- | Get a name out of a property name array
564-- | Get a name out of a property name array
565−propertyNamesAt :: MonadIO m => JSPropertyNameArrayRef -> CSize -> m JSStringRef
565+propertyNamesAt :: MonadIO m => JSPropertyNameArray -> CSize -> m JSString
566propertyNamesAt names index = liftIO $ jspropertynamearraygetnameatindex names index
566propertyNamesAt names index = liftIO $ jspropertynamearraygetnameatindex names index
567{-# INLINE propertyNamesAt #-}
567{-# INLINE propertyNamesAt #-}
569-- | Convert property array to a list
569-- | Convert property array to a list
570−propertyNamesList :: MonadIO m => JSPropertyNameArrayRef -> m [JSStringRef]
570+propertyNamesList :: MonadIO m => JSPropertyNameArray -> m [JSString]
571propertyNamesList names = do
571propertyNamesList names = do
572 count <- propertyNamesCount names
572 count <- propertyNamesCount names
573 mapM (propertyNamesAt names) $ enumFromTo 0 (count - 1)
573 mapM (propertyNamesAt names) $ enumFromTo 0 (count - 1)
@@ -575,7 +575,7 @@ propertyNamesList names = do
577-- | Get a list containing the property names present on a given object
577-- | Get a list containing the property names present on a given object
578−propertyNames :: MakeObject this => this -> JSM [JSStringRef]
578+propertyNames :: MakeObject this => this -> JSM [JSString]
579#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
579#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
580propertyNames this = makeObject this >>= liftIO . js_propertyNames >>= liftIO . (fmap (map pFromJSVal)) . Array.toListIO
580propertyNames this = makeObject this >>= liftIO . js_propertyNames >>= liftIO . (fmap (map pFromJSVal)) . Array.toListIO
581{-# INLINE propertyNames #-}
581{-# INLINE propertyNames #-}
@@ -589,27 +589,27 @@ propertyNames = undefined
591-- | Get a list containing references to all the properties present on a given object
591-- | Get a list containing references to all the properties present on a given object
592−properties :: MakeObject this => this -> JSM [JSValueRef]
592+properties :: MakeObject this => this -> JSM [JSVal]
593properties this = propertyNames this >>= mapM (this !)
593properties this = propertyNames this >>= mapM (this !)
595-- | Call a JavaScript object as function. Consider using '#'.
595-- | Call a JavaScript object as function. Consider using '#'.
596−objCallAsFunction :: MakeArgRefs args
596+objCallAsFunction :: MakeArgs args
597 => Object
597 => Object
598 -> Object
598 -> Object
600− -> JSValueRefRef
600+ -> MutableJSArray
601− -> JSM JSValueRef
601+ -> JSM JSVal
602#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
602#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
603objCallAsFunction function this args exceptions = do
603objCallAsFunction function this args exceptions = do
604− rargs <- makeArgRefs args >>= liftIO . Array.fromListIO
604+ rargs <- makeArgs args >>= liftIO . Array.fromListIO
605 liftIO $ js_apply function this rargs exceptions
605 liftIO $ js_apply function this rargs exceptions
606{-# INLINE objCallAsFunction #-}
606{-# INLINE objCallAsFunction #-}
607foreign import javascript unsafe "try { $r = $1.apply($2, $3) } catch(e) { $4[0] = e }"
607foreign import javascript unsafe "try { $r = $1.apply($2, $3) } catch(e) { $4[0] = e }"
608− js_apply :: Object -> Object -> JSValueRefRef -> JSValueRefRef -> IO JSValueRef
608+ js_apply :: Object -> Object -> MutableJSArray -> MutableJSArray -> IO JSVal
609#elif defined(USE_WEBKIT)
609#elif defined(USE_WEBKIT)
610objCallAsFunction (Object function) (Object this) args exceptions = do
610objCallAsFunction (Object function) (Object this) args exceptions = do
611 gctxt <- ask
611 gctxt <- ask
612− rargs <- makeArgRefs args
612+ rargs <- makeArgs args
613 liftIO $ withArrayLen rargs $ \ largs pargs ->
613 liftIO $ withArrayLen rargs $ \ largs pargs ->
614 jsobjectcallasfunction gctxt function this (fromIntegral largs) pargs exceptions
614 jsobjectcallasfunction gctxt function this (fromIntegral largs) pargs exceptions
615{-# INLINE objCallAsFunction #-}
615{-# INLINE objCallAsFunction #-}
@@ -621,14 +621,14 @@ objCallAsFunction = undefined
622-- If you pass more than 7 arguments to a constructor for a built in
622-- If you pass more than 7 arguments to a constructor for a built in
623-- JavaScript type (like Date) then this function will fail.
623-- JavaScript type (like Date) then this function will fail.
624−objCallAsConstructor :: MakeArgRefs args
624+objCallAsConstructor :: MakeArgs args
625 => Object
625 => Object
627− -> JSValueRefRef
627+ -> MutableJSArray
628− -> JSM JSValueRef
628+ -> JSM JSVal
629#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
629#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
630objCallAsConstructor function args exceptions = do
630objCallAsConstructor function args exceptions = do
631− rargs <- makeArgRefs args >>= liftIO . Array.fromListIO
631+ rargs <- makeArgs args >>= liftIO . Array.fromListIO
632 liftIO $ js_new function rargs exceptions
632 liftIO $ js_new function rargs exceptions
633foreign import javascript unsafe "\
633foreign import javascript unsafe "\
@@ -657,11 +657,11 @@ foreign import javascript unsafe "\
657 catch(e) {\
657 catch(e) {\
658 $3[0] = e;\
658 $3[0] = e;\
660− js_new :: Object -> JSValueRefRef -> JSValueRefRef -> IO JSValueRef
660+ js_new :: Object -> MutableJSArray -> MutableJSArray -> IO JSVal
661#elif defined(USE_WEBKIT)
661#elif defined(USE_WEBKIT)
662objCallAsConstructor (Object function) args exceptions = do
662objCallAsConstructor (Object function) args exceptions = do
663 gctxt <- ask
663 gctxt <- ask
664− rargs <- makeArgRefs args
664+ rargs <- makeArgs args
665 liftIO $ withArrayLen rargs $ \ largs pargs ->
665 liftIO $ withArrayLen rargs $ \ largs pargs ->
666 jsobjectcallasconstructor gctxt function (fromIntegral largs) pargs exceptions
666 jsobjectcallasconstructor gctxt function (fromIntegral largs) pargs exceptions