on master help sign in
Remove INLINEs for faster jsaddle-dom compilation
d023035Hamish Mackenzie
src/Language/Javascript/JSaddle/Arguments.hs−7
@@ -28,18 +28,15 @@ class MakeArgs this where
28
28
29instance MakeArgs arg => MakeArgs (JSM arg) where
29instance MakeArgs arg => MakeArgs (JSM arg) where
30 makeArgs arg = arg >>= makeArgs
30 makeArgs arg = arg >>= makeArgs
31− {-# INLINE makeArgs #-}
32
31
33instance ToJSVal arg => MakeArgs [arg] where
32instance ToJSVal arg => MakeArgs [arg] where
34 makeArgs = mapM toJSVal
33 makeArgs = mapM toJSVal
35− {-# INLINE makeArgs #-}
36
34
37instance (ToJSVal arg1, ToJSVal arg2) => MakeArgs (arg1, arg2) where
35instance (ToJSVal arg1, ToJSVal arg2) => MakeArgs (arg1, arg2) where
38 makeArgs (arg1, arg2) = do
36 makeArgs (arg1, arg2) = do
39 rarg1 <- toJSVal arg1
37 rarg1 <- toJSVal arg1
40 rarg2 <- toJSVal arg2
38 rarg2 <- toJSVal arg2
41 return [rarg1, rarg2]
39 return [rarg1, rarg2]
42− {-# INLINE makeArgs #-}
43
40
44instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3) => MakeArgs (arg1, arg2, arg3) where
41instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3) => MakeArgs (arg1, arg2, arg3) where
45 makeArgs (arg1, arg2, arg3) = do
42 makeArgs (arg1, arg2, arg3) = do
@@ -47,7 +44,6 @@ instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3) => MakeArgs (arg1, arg2, arg
47 rarg2 <- toJSVal arg2
44 rarg2 <- toJSVal arg2
48 rarg3 <- toJSVal arg3
45 rarg3 <- toJSVal arg3
49 return [rarg1, rarg2, rarg3]
46 return [rarg1, rarg2, rarg3]
50− {-# INLINE makeArgs #-}
51
47
52instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4) => MakeArgs (arg1, arg2, arg3, arg4) where
48instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4) => MakeArgs (arg1, arg2, arg3, arg4) where
53 makeArgs (arg1, arg2, arg3, arg4) = do
49 makeArgs (arg1, arg2, arg3, arg4) = do
@@ -56,7 +52,6 @@ instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4) => MakeArgs (a
56 rarg3 <- toJSVal arg3
52 rarg3 <- toJSVal arg3
57 rarg4 <- toJSVal arg4
53 rarg4 <- toJSVal arg4
58 return [rarg1, rarg2, rarg3, rarg4]
54 return [rarg1, rarg2, rarg3, rarg4]
59− {-# INLINE makeArgs #-}
60
55
61instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5) => MakeArgs (arg1, arg2, arg3, arg4, arg5) where
56instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5) => MakeArgs (arg1, arg2, arg3, arg4, arg5) where
62 makeArgs (arg1, arg2, arg3, arg4, arg5) = do
57 makeArgs (arg1, arg2, arg3, arg4, arg5) = do
@@ -66,7 +61,6 @@ instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5)
66 rarg4 <- toJSVal arg4
61 rarg4 <- toJSVal arg4
67 rarg5 <- toJSVal arg5
62 rarg5 <- toJSVal arg5
68 return [rarg1, rarg2, rarg3, rarg4, rarg5]
63 return [rarg1, rarg2, rarg3, rarg4, rarg5]
69− {-# INLINE makeArgs #-}
70
64
71
65
72instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5, ToJSVal arg6) => MakeArgs (arg1, arg2, arg3, arg4, arg5, arg6) where
66instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5, ToJSVal arg6) => MakeArgs (arg1, arg2, arg3, arg4, arg5, arg6) where
@@ -78,5 +72,4 @@ instance (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5,
78 rarg5 <- toJSVal arg5
72 rarg5 <- toJSVal arg5
79 rarg6 <- toJSVal arg6
73 rarg6 <- toJSVal arg6
80 return [rarg1, rarg2, rarg3, rarg4, rarg5, rarg6]
74 return [rarg1, rarg2, rarg3, rarg4, rarg5, rarg6]
81− {-# INLINE makeArgs #-}
82
75
src/Language/Javascript/JSaddle/Classes.hs−2
@@ -38,10 +38,8 @@ class MakeObject this where
38
38
39instance ToJSVal Object where
39instance ToJSVal Object where
40 toJSVal (Object r) = return r
40 toJSVal (Object r) = return r
41− {-# INLINE toJSVal #-}
42
41
43-- | If we already have a Object we are fine
42-- | If we already have a Object we are fine
44instance MakeObject Object where
43instance MakeObject Object where
45 makeObject = return
44 makeObject = return
46− {-# INLINE makeObject #-}
47
45
src/Language/Javascript/JSaddle/Evaluate.hs−3
@@ -63,7 +63,6 @@ evaluateScript :: (ToJSString script, MakeObject this, ToJSString url)
63 -> JSM JSVal
63 -> JSM JSVal
64#ifdef ghcjs_HOST_OS
64#ifdef ghcjs_HOST_OS
65evaluateScript script this url line = liftIO $ js_eval (toJSString script)
65evaluateScript script this url line = liftIO $ js_eval (toJSString script)
66−{-# INLINE evaluateScript #-}
67foreign import javascript unsafe "$r = eval($1);"
66foreign import javascript unsafe "$r = eval($1);"
68 js_eval :: JSString -> IO JSVal
67 js_eval :: JSString -> IO JSVal
69#else
68#else
@@ -76,7 +75,6 @@ evaluateScript script this url line = do
76 withJSString (toJSString url) $ \url' ->
75 withJSString (toJSString url) $ \url' ->
77 rethrow $ liftIO . jsevaluatescript gctxt script' this' url' line
76 rethrow $ liftIO . jsevaluatescript gctxt script' this' url' line
78 makeNewJSVal result
77 makeNewJSVal result
79−{-# INLINE evaluateScript #-}
80#endif
78#endif
81
79
82-- | Evaluates a script (like eval in java script)
80-- | Evaluates a script (like eval in java script)
@@ -87,4 +85,3 @@ eval :: ToJSString script
87 => script -- ^ JavaScript to evaluate
85 => script -- ^ JavaScript to evaluate
88 -> JSM JSVal
86 -> JSM JSVal
89eval script = evaluateScript script nullObject nullJSString 1
87eval script = evaluateScript script nullObject nullJSString 1
90−{-# INLINE eval #-}
src/Language/Javascript/JSaddle/Monad.hs−5
@@ -87,7 +87,6 @@ catch :: (MonadIO m, E.Exception e)
87t `catch` c = do
87t `catch` c = do
88 r <- ask
88 r <- ask
89 liftIO (runReaderT t r `E.catch` \e -> runReaderT (c e) r)
89 liftIO (runReaderT t r `E.catch` \e -> runReaderT (c e) r)
90−{-# INLINE catch #-}
91
90
92-- | Wrapped version of 'E.bracket' that runs in a MonadIO that works
91-- | Wrapped version of 'E.bracket' that runs in a MonadIO that works
93-- a bit better with 'JSM'
92-- a bit better with 'JSM'
@@ -98,7 +97,6 @@ bracket aquire release f = do
98 (runReaderT aquire r)
97 (runReaderT aquire r)
99 (\x -> runReaderT (release x) r)
98 (\x -> runReaderT (release x) r)
100 (\x -> runReaderT (f x) r)
99 (\x -> runReaderT (f x) r)
101−{-# INLINE bracket #-}
102
100
103-- | Handle JavaScriptCore functions that take a MutableJSArray in order
101-- | Handle JavaScriptCore functions that take a MutableJSArray in order
104-- to throw exceptions.
102-- to throw exceptions.
@@ -132,7 +130,6 @@ runJSaddle webView f = do
132 withForeignPtr gctxt $ \ptr ->
130 withForeignPtr gctxt $ \ptr ->
133 runReaderT f (castPtr ptr)
131 runReaderT f (castPtr ptr)
134#endif
132#endif
135−{-# INLINE runJSaddle #-}
136
133
137postGUIAsyncJS :: JSM () -> JSM ()
134postGUIAsyncJS :: JSM () -> JSM ()
138#ifdef ghcjs_HOST_OS
135#ifdef ghcjs_HOST_OS
@@ -142,7 +139,6 @@ postGUIAsyncJS f = do
142 r <- ask
139 r <- ask
143 liftIO . postGUIAsync $ runReaderT f r
140 liftIO . postGUIAsync $ runReaderT f r
144#endif
141#endif
145−{-# INLINE postGUIAsyncJS #-}
146
142
147postGUISyncJS :: JSM a -> JSM a
143postGUISyncJS :: JSM a -> JSM a
148#ifdef ghcjs_HOST_OS
144#ifdef ghcjs_HOST_OS
@@ -152,5 +148,4 @@ postGUISyncJS f = do
152 r <- ask
148 r <- ask
153 liftIO . postGUISync $ runReaderT f r
149 liftIO . postGUISync $ runReaderT f r
154#endif
150#endif
155−{-# INLINE postGUISyncJS #-}
156
151
src/Language/Javascript/JSaddle/Native.hs−1
@@ -97,6 +97,5 @@ withToJSVal :: ToJSVal val => val -> (JSValueRef -> JSM a) -> JSM a
97withToJSVal val f = do
97withToJSVal val f = do
98 v <- toJSVal val
98 v <- toJSVal val
99 withJSVal v f
99 withJSVal v f
100−{-# INLINE withToJSVal #-}
101#endif
100#endif
102
101
src/Language/Javascript/JSaddle/Object.hs−51
@@ -155,7 +155,6 @@ import Data.Text (Text)
155-- as it returns something we can make into a Object.
155-- as it returns something we can make into a Object.
156instance MakeObject v => MakeObject (JSM v) where
156instance MakeObject v => MakeObject (JSM v) where
157 makeObject v = v >>= makeObject
157 makeObject v = v >>= makeObject
158− {-# INLINE makeObject #-}
159
158
160-- | Lookup a property based on its name.
159-- | Lookup a property based on its name.
161--
160--
@@ -172,7 +171,6 @@ this ! name = do
172 rethrow $ objGetPropertyByName rthis rname
171 rethrow $ objGetPropertyByName rthis rname
173 where
172 where
174 rname = toJSString name
173 rname = toJSString name
175−{-# INLINE (!) #-}
176
174
177-- | Lookup a property based on its index.
175-- | Lookup a property based on its index.
178--
176--
@@ -187,7 +185,6 @@ this ! name = do
187this !! index = do
185this !! index = do
188 rthis <- makeObject this
186 rthis <- makeObject this
189 rethrow $ objGetPropertyAtIndex rthis index
187 rethrow $ objGetPropertyAtIndex rthis index
190−{-# INLINE (!!) #-}
191
188
192-- | Makes a getter for a particular property name.
189-- | Makes a getter for a particular property name.
193--
190--
@@ -201,7 +198,6 @@ js :: (MakeObject s, ToJSString name)
201 => name -- ^ Name of the property to find
198 => name -- ^ Name of the property to find
202 -> IndexPreservingGetter s (JSM JSVal)
199 -> IndexPreservingGetter s (JSM JSVal)
203js name = to (!name)
200js name = to (!name)
204−{-# INLINE js #-}
205
201
206-- | Makes a setter for a particular property name.
202-- | Makes a setter for a particular property name.
207--
203--
@@ -216,7 +212,6 @@ jss :: (ToJSString name, ToJSVal val)
216 -> val
212 -> val
217 -> forall o . MakeObject o => IndexPreservingGetter o (JSM ())
213 -> forall o . MakeObject o => IndexPreservingGetter o (JSM ())
218jss name val = to (\o -> o <# name $ val)
214jss name val = to (\o -> o <# name $ val)
219−{-# INLINE jss #-}
220
215
221-- | Handy way to call a function
216-- | Handy way to call a function
222--
217--
@@ -226,7 +221,6 @@ jss name val = to (\o -> o <# name $ val)
226-- 6
221-- 6
227jsf :: (ToJSString name, MakeArgs args) => name -> args -> JSF
222jsf :: (ToJSString name, MakeArgs args) => name -> args -> JSF
228jsf name args = to (\o -> o # name $ args)
223jsf name args = to (\o -> o # name $ args)
229−{-# INLINE jsf #-}
230
224
231-- | Java script function applications have this type
225-- | Java script function applications have this type
232type JSF = forall o . MakeObject o => IndexPreservingGetter o (JSM JSVal)
226type JSF = forall o . MakeObject o => IndexPreservingGetter o (JSM JSVal)
@@ -239,7 +233,6 @@ type JSF = forall o . MakeObject o => IndexPreservingGetter o (JSM JSVal)
239-- hello world
233-- hello world
240js0 :: (ToJSString name) => name -> JSF
234js0 :: (ToJSString name) => name -> JSF
241js0 name = jsf name ()
235js0 name = jsf name ()
242−{-# INLINE js0 #-}
243
236
244-- | Handy way to call a function that expects one argument
237-- | Handy way to call a function that expects one argument
245--
238--
@@ -249,32 +242,27 @@ js0 name = jsf name ()
249-- 6
242-- 6
250js1 :: (ToJSString name, ToJSVal a0) => name -> a0 -> JSF
243js1 :: (ToJSString name, ToJSVal a0) => name -> a0 -> JSF
251js1 name a0 = jsf name [a0]
244js1 name a0 = jsf name [a0]
252−{-# INLINE js1 #-}
253
245
254-- | Handy way to call a function that expects two arguments
246-- | Handy way to call a function that expects two arguments
255js2 :: (ToJSString name, ToJSVal a0, ToJSVal a1) => name -> a0 -> a1 -> JSF
247js2 :: (ToJSString name, ToJSVal a0, ToJSVal a1) => name -> a0 -> a1 -> JSF
256js2 name a0 a1 = jsf name (a0, a1)
248js2 name a0 a1 = jsf name (a0, a1)
257−{-# INLINE js2 #-}
258
249
259-- | Handy way to call a function that expects three arguments
250-- | Handy way to call a function that expects three arguments
260js3 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2)
251js3 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2)
261 => name -> a0 -> a1 -> a2 -> JSF
252 => name -> a0 -> a1 -> a2 -> JSF
262js3 name a0 a1 a2 = jsf name (a0, a1, a2)
253js3 name a0 a1 a2 = jsf name (a0, a1, a2)
263−{-# INLINE js3 #-}
264
254
265-- | Handy way to call a function that expects four arguments
255-- | Handy way to call a function that expects four arguments
266js4 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2,
256js4 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2,
267 ToJSVal a3)
257 ToJSVal a3)
268 => name -> a0 -> a1 -> a2 -> a3 -> JSF
258 => name -> a0 -> a1 -> a2 -> a3 -> JSF
269js4 name a0 a1 a2 a3 = jsf name (a0, a1, a2, a3)
259js4 name a0 a1 a2 a3 = jsf name (a0, a1, a2, a3)
270−{-# INLINE js4 #-}
271
260
272-- | Handy way to call a function that expects five arguments
261-- | Handy way to call a function that expects five arguments
273js5 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2,
262js5 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2,
274 ToJSVal a3, ToJSVal a4)
263 ToJSVal a3, ToJSVal a4)
275 => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSF
264 => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSF
276js5 name a0 a1 a2 a3 a4 = jsf name (a0, a1, a2, a3, a4)
265js5 name a0 a1 a2 a3 a4 = jsf name (a0, a1, a2, a3, a4)
277−{-# INLINE js5 #-}
278
266
279
267
280-- | Handy way to get and hold onto a reference top level javascript
268-- | Handy way to get and hold onto a reference top level javascript
@@ -289,7 +277,6 @@ js5 name a0 a1 a2 a3 a4 = jsf name (a0, a1, a2, a3, a4)
289-- undefined
277-- undefined
290jsg :: ToJSString a => a -> JSM JSVal
278jsg :: ToJSString a => a -> JSM JSVal
291jsg name = global ! name
279jsg name = global ! name
292−{-# INLINE jsg #-}
293
280
294-- | Handy way to call a function
281-- | Handy way to call a function
295--
282--
@@ -301,7 +288,6 @@ jsg name = global ! name
301-- 5
288-- 5
302jsgf :: (ToJSString name, MakeArgs args) => name -> args -> JSM JSVal
289jsgf :: (ToJSString name, MakeArgs args) => name -> args -> JSM JSVal
303jsgf name = global # name
290jsgf name = global # name
304−{-# INLINE jsgf #-}
305
291
306-- | Handy way to call a function that expects no arguments
292-- | Handy way to call a function that expects no arguments
307--
293--
@@ -311,7 +297,6 @@ jsgf name = global # name
311-- TypeError:...undefined...is not an objec...
297-- TypeError:...undefined...is not an objec...
312jsg0 :: (ToJSString name) => name -> JSM JSVal
298jsg0 :: (ToJSString name) => name -> JSM JSVal
313jsg0 name = jsgf name ()
299jsg0 name = jsgf name ()
314−{-# INLINE jsg0 #-}
315
300
316-- | Handy way to call a function that expects one argument
301-- | Handy way to call a function that expects one argument
317--
302--
@@ -321,32 +306,27 @@ jsg0 name = jsgf name ()
321-- 5
306-- 5
322jsg1 :: (ToJSString name, ToJSVal a0) => name -> a0 -> JSM JSVal
307jsg1 :: (ToJSString name, ToJSVal a0) => name -> a0 -> JSM JSVal
323jsg1 name a0 = jsgf name [a0]
308jsg1 name a0 = jsgf name [a0]
324−{-# INLINE jsg1 #-}
325
309
326-- | Handy way to call a function that expects two arguments
310-- | Handy way to call a function that expects two arguments
327jsg2 :: (ToJSString name, ToJSVal a0, ToJSVal a1) => name -> a0 -> a1 -> JSM JSVal
311jsg2 :: (ToJSString name, ToJSVal a0, ToJSVal a1) => name -> a0 -> a1 -> JSM JSVal
328jsg2 name a0 a1 = jsgf name (a0, a1)
312jsg2 name a0 a1 = jsgf name (a0, a1)
329−{-# INLINE jsg2 #-}
330
313
331-- | Handy way to call a function that expects three arguments
314-- | Handy way to call a function that expects three arguments
332jsg3 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2)
315jsg3 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2)
333 => name -> a0 -> a1 -> a2 -> JSM JSVal
316 => name -> a0 -> a1 -> a2 -> JSM JSVal
334jsg3 name a0 a1 a2 = jsgf name (a0, a1, a2)
317jsg3 name a0 a1 a2 = jsgf name (a0, a1, a2)
335−{-# INLINE jsg3 #-}
336
318
337-- | Handy way to call a function that expects four arguments
319-- | Handy way to call a function that expects four arguments
338jsg4 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2,
320jsg4 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2,
339 ToJSVal a3)
321 ToJSVal a3)
340 => name -> a0 -> a1 -> a2 -> a3 -> JSM JSVal
322 => name -> a0 -> a1 -> a2 -> a3 -> JSM JSVal
341jsg4 name a0 a1 a2 a3 = jsgf name (a0, a1, a2, a3)
323jsg4 name a0 a1 a2 a3 = jsgf name (a0, a1, a2, a3)
342−{-# INLINE jsg4 #-}
343
324
344-- | Handy way to call a function that expects five arguments
325-- | Handy way to call a function that expects five arguments
345jsg5 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2,
326jsg5 :: (ToJSString name, ToJSVal a0, ToJSVal a1, ToJSVal a2,
346 ToJSVal a3, ToJSVal a4)
327 ToJSVal a3, ToJSVal a4)
347 => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSM JSVal
328 => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSM JSVal
348jsg5 name a0 a1 a2 a3 a4 = jsgf name (a0, a1, a2, a3, a4)
329jsg5 name a0 a1 a2 a3 a4 = jsgf name (a0, a1, a2, a3, a4)
349−{-# INLINE jsg5 #-}
350
330
351-- | Call a JavaScript function
331-- | Call a JavaScript function
352--
332--
@@ -362,7 +342,6 @@ infixr 2 #
362 f <- rethrow $ objGetPropertyByName rthis name
342 f <- rethrow $ objGetPropertyByName rthis name
363 f' <- valToObject f
343 f' <- valToObject f
364 rethrow $ objCallAsFunction f' rthis args
344 rethrow $ objCallAsFunction f' rthis args
365−{-# INLINE (#) #-}
366
345
367-- | Call a JavaScript function
346-- | Call a JavaScript function
368--
347--
@@ -378,7 +357,6 @@ infixr 2 ##
378 f <- rethrow $ objGetPropertyAtIndex rthis index
357 f <- rethrow $ objGetPropertyAtIndex rthis index
379 f' <- valToObject f
358 f' <- valToObject f
380 rethrow $ objCallAsFunction f' rthis args
359 rethrow $ objCallAsFunction f' rthis args
381−{-# INLINE (##) #-}
382
360
383-- | Set a JavaScript property
361-- | Set a JavaScript property
384--
362--
@@ -395,7 +373,6 @@ infixr 1 <#
395(<#) this name val = do
373(<#) this name val = do
396 rthis <- makeObject this
374 rthis <- makeObject this
397 rethrow $ objSetPropertyByName rthis name val 0
375 rethrow $ objSetPropertyByName rthis name val 0
398−{-# INLINE (<#) #-}
399
376
400-- | Set a JavaScript property
377-- | Set a JavaScript property
401--
378--
@@ -412,7 +389,6 @@ infixr 1 <##
412(<##) this index val = do
389(<##) this index val = do
413 rthis <- makeObject this
390 rthis <- makeObject this
414 rethrow $ objSetPropertyAtIndex rthis index val
391 rethrow $ objSetPropertyAtIndex rthis index val
415−{-# INLINE (<##) #-}
416
392
417-- | Use this to create a new JavaScript object
393-- | Use this to create a new JavaScript object
418--
394--
@@ -428,7 +404,6 @@ new :: (MakeObject constructor, MakeArgs args)
428new constructor args = do
404new constructor args = do
429 f <- makeObject constructor
405 f <- makeObject constructor
430 rethrow $ objCallAsConstructor f args
406 rethrow $ objCallAsConstructor f args
431−{-# INLINE new #-}
432
407
433-- | Call function with a given @this@. In most cases you should use '#'.
408-- | Call function with a given @this@. In most cases you should use '#'.
434--
409--
@@ -442,7 +417,6 @@ call f this args = do
442 rfunction <- makeObject f
417 rfunction <- makeObject f
443 rthis <- makeObject this
418 rthis <- makeObject this
444 rethrow $ objCallAsFunction rfunction rthis args
419 rethrow $ objCallAsFunction rfunction rthis args
445−{-# INLINE call #-}
446
420
447-- | Make an empty object using the default constuctor
421-- | Make an empty object using the default constuctor
448--
422--
@@ -458,7 +432,6 @@ obj = do
458 gctxt <- ask
432 gctxt <- ask
459 Object <$> (liftIO (jsobjectmake gctxt nullPtr nullPtr) >>= makeNewJSVal)
433 Object <$> (liftIO (jsobjectmake gctxt nullPtr nullPtr) >>= makeNewJSVal)
460#endif
434#endif
461−{-# INLINE obj #-}
462
435
463-- | Type used for Haskell functions called from JavaScript.
436-- | Type used for Haskell functions called from JavaScript.
464type JSCallAsFunction = JSVal -- ^ Function object
437type JSCallAsFunction = JSVal -- ^ Function object
@@ -482,7 +455,6 @@ type JSCallAsFunction = JSVal -- ^ Function object
482-- undefined
455-- undefined
483fun :: JSCallAsFunction -> JSCallAsFunction
456fun :: JSCallAsFunction -> JSCallAsFunction
484fun = id
457fun = id
485−{-# INLINE fun #-}
486
458
487#ifdef ghcjs_HOST_OS
459#ifdef ghcjs_HOST_OS
488type HaskellCallback = Callback (JSVal -> JSVal -> IO ())
460type HaskellCallback = Callback (JSVal -> JSVal -> IO ())
@@ -538,20 +510,17 @@ freeFunction (Function callback _) = liftIO $
538
510
539instance ToJSVal Function where
511instance ToJSVal Function where
540 toJSVal (Function _ f) = toJSVal f
512 toJSVal (Function _ f) = toJSVal f
541− {-# INLINE toJSVal #-}
542
513
543-- | A callback to Haskell can be used as a JavaScript value. This will create
514-- | A callback to Haskell can be used as a JavaScript value. This will create
544-- an anonymous JavaScript function object. Use 'function' to create one with
515-- an anonymous JavaScript function object. Use 'function' to create one with
545-- a name.
516-- a name.
546instance ToJSVal JSCallAsFunction where
517instance ToJSVal JSCallAsFunction where
547 toJSVal f = functionObject <$> function nullJSString f >>= toJSVal
518 toJSVal f = functionObject <$> function nullJSString f >>= toJSVal
548− {-# INLINE toJSVal #-}
549
519
550instance MakeArgs JSCallAsFunction where
520instance MakeArgs JSCallAsFunction where
551 makeArgs f = do
521 makeArgs f = do
552 rarg <- functionObject <$> function nullJSString f >>= toJSVal
522 rarg <- functionObject <$> function nullJSString f >>= toJSVal
553 return [rarg]
523 return [rarg]
554− {-# INLINE makeArgs #-}
555
524
556makeArray :: MakeArgs args => args -> MutableJSArray -> JSM Object
525makeArray :: MakeArgs args => args -> MutableJSArray -> JSM Object
557#ifdef ghcjs_HOST_OS
526#ifdef ghcjs_HOST_OS
@@ -568,7 +537,6 @@ makeArray args exceptions = do
568 jsobjectmakearray gctxt (fromIntegral len) ptr exceptions
537 jsobjectmakearray gctxt (fromIntegral len) ptr exceptions
569 Object <$> makeNewJSVal result
538 Object <$> makeNewJSVal result
570#endif
539#endif
571−{-# INLINE makeArray #-}
572
540
573-- | Make an JavaScript array from a list of values
541-- | Make an JavaScript array from a list of values
574--
542--
@@ -586,45 +554,35 @@ array = rethrow . makeArray
586-- Make an array out of various lists
554-- Make an array out of various lists
587instance ToJSVal [JSVal] where
555instance ToJSVal [JSVal] where
588 toJSVal = toJSVal . array
556 toJSVal = toJSVal . array
589− {-# INLINE toJSVal #-}
590
557
591instance ToJSVal [JSM JSVal] where
558instance ToJSVal [JSM JSVal] where
592 toJSVal = toJSVal . array
559 toJSVal = toJSVal . array
593− {-# INLINE toJSVal #-}
594
560
595instance ToJSVal [Double] where
561instance ToJSVal [Double] where
596 toJSVal = toJSVal . array
562 toJSVal = toJSVal . array
597− {-# INLINE toJSVal #-}
598
563
599instance ToJSVal [Float] where
564instance ToJSVal [Float] where
600 toJSVal = toJSVal . array
565 toJSVal = toJSVal . array
601− {-# INLINE toJSVal #-}
602
566
603instance ToJSVal [Int] where
567instance ToJSVal [Int] where
604 toJSVal = toJSVal . array
568 toJSVal = toJSVal . array
605− {-# INLINE toJSVal #-}
606
569
607instance ToJSVal [JSString] where
570instance ToJSVal [JSString] where
608 toJSVal = toJSVal . array
571 toJSVal = toJSVal . array
609− {-# INLINE toJSVal #-}
610
572
611instance ToJSVal [String] where
573instance ToJSVal [String] where
612 toJSVal = toJSVal . array
574 toJSVal = toJSVal . array
613− {-# INLINE toJSVal #-}
614
575
615instance ToJSVal [Text] where
576instance ToJSVal [Text] where
616 toJSVal = toJSVal . array
577 toJSVal = toJSVal . array
617− {-# INLINE toJSVal #-}
618
578
619instance ToJSVal [Bool] where
579instance ToJSVal [Bool] where
620 toJSVal = toJSVal . array
580 toJSVal = toJSVal . array
621− {-# INLINE toJSVal #-}
622
581
623-- | JavaScript's global object
582-- | JavaScript's global object
624global :: JSM Object
583global :: JSM Object
625#ifdef ghcjs_HOST_OS
584#ifdef ghcjs_HOST_OS
626global = liftIO js_window
585global = liftIO js_window
627−{-# INLINE global #-}
628foreign import javascript unsafe "$r = window"
586foreign import javascript unsafe "$r = window"
629 js_window :: IO Object
587 js_window :: IO Object
630#else
588#else
@@ -632,7 +590,6 @@ global = do
632 gctxt <- ask
590 gctxt <- ask
633 result <- liftIO $ jscontextgetglobalobject gctxt
591 result <- liftIO $ jscontextgetglobalobject gctxt
634 Object <$> makeNewJSVal result
592 Object <$> makeNewJSVal result
635−{-# INLINE global #-}
636#endif
593#endif
637
594
638-- | Get an array containing the property names present on a given object
595-- | Get an array containing the property names present on a given object
@@ -643,36 +600,30 @@ copyPropertyNames this = do
643 this' <- makeObject this
600 this' <- makeObject this
644 withObject this' $ \rthis ->
601 withObject this' $ \rthis ->
645 liftIO $ jsobjectcopypropertynames gctxt rthis
602 liftIO $ jsobjectcopypropertynames gctxt rthis
646−{-# INLINE copyPropertyNames #-}
647
603
648-- | Get the number of names in a property name array
604-- | Get the number of names in a property name array
649propertyNamesCount :: MonadIO m => JSPropertyNameArray -> m CSize
605propertyNamesCount :: MonadIO m => JSPropertyNameArray -> m CSize
650propertyNamesCount names = liftIO $ jspropertynamearraygetcount names
606propertyNamesCount names = liftIO $ jspropertynamearraygetcount names
651−{-# INLINE propertyNamesCount #-}
652
607
653-- | Get a name out of a property name array
608-- | Get a name out of a property name array
654propertyNamesAt :: MonadIO m => JSPropertyNameArray -> CSize -> m JSString
609propertyNamesAt :: MonadIO m => JSPropertyNameArray -> CSize -> m JSString
655propertyNamesAt names index = liftIO $ jspropertynamearraygetnameatindex names index >>= makeNewJSString
610propertyNamesAt names index = liftIO $ jspropertynamearraygetnameatindex names index >>= makeNewJSString
656−{-# INLINE propertyNamesAt #-}
657
611
658-- | Convert property array to a list
612-- | Convert property array to a list
659propertyNamesList :: MonadIO m => JSPropertyNameArray -> m [JSString]
613propertyNamesList :: MonadIO m => JSPropertyNameArray -> m [JSString]
660propertyNamesList names = do
614propertyNamesList names = do
661 count <- propertyNamesCount names
615 count <- propertyNamesCount names
662 mapM (propertyNamesAt names) $ enumFromTo 0 (count - 1)
616 mapM (propertyNamesAt names) $ enumFromTo 0 (count - 1)
663−{-# INLINE propertyNamesList #-}
664#endif
617#endif
665
618
666-- | Get a list containing the property names present on a given object
619-- | Get a list containing the property names present on a given object
667propertyNames :: MakeObject this => this -> JSM [JSString]
620propertyNames :: MakeObject this => this -> JSM [JSString]
668#ifdef ghcjs_HOST_OS
621#ifdef ghcjs_HOST_OS
669propertyNames this = makeObject this >>= liftIO . js_propertyNames >>= liftIO . (fmap (map pFromJSVal)) . Array.toListIO
622propertyNames this = makeObject this >>= liftIO . js_propertyNames >>= liftIO . (fmap (map pFromJSVal)) . Array.toListIO
670−{-# INLINE propertyNames #-}
671foreign import javascript unsafe "$r = []; h$forIn($1, function(n){$r.push(n);})"
623foreign import javascript unsafe "$r = []; h$forIn($1, function(n){$r.push(n);})"
672 js_propertyNames :: Object -> IO JSArray
624 js_propertyNames :: Object -> IO JSArray
673#else
625#else
674propertyNames this = copyPropertyNames this >>= propertyNamesList
626propertyNames this = copyPropertyNames this >>= propertyNamesList
675−{-# INLINE propertyNames #-}
676#endif
627#endif
677
628
678-- | Get a list containing references to all the properties present on a given object
629-- | Get a list containing references to all the properties present on a given object
@@ -690,7 +641,6 @@ objCallAsFunction :: MakeArgs args
690objCallAsFunction f this args exceptions = do
641objCallAsFunction f this args exceptions = do
691 rargs <- makeArgs args >>= liftIO . Array.fromListIO
642 rargs <- makeArgs args >>= liftIO . Array.fromListIO
692 liftIO $ js_apply f this rargs exceptions
643 liftIO $ js_apply f this rargs exceptions
693−{-# INLINE objCallAsFunction #-}
694foreign import javascript unsafe "try { $r = $1.apply($2, $3) } catch(e) { $4[0] = e }"
644foreign import javascript unsafe "try { $r = $1.apply($2, $3) } catch(e) { $4[0] = e }"
695 js_apply :: Object -> Object -> MutableJSArray -> MutableJSArray -> IO JSVal
645 js_apply :: Object -> Object -> MutableJSArray -> MutableJSArray -> IO JSVal
696#else
646#else
@@ -704,7 +654,6 @@ objCallAsFunction f this args exceptions = do
704 liftIO $ withArrayLen rargs' $ \ largs pargs ->
654 liftIO $ withArrayLen rargs' $ \ largs pargs ->
705 jsobjectcallasfunction gctxt rfunction rthis (fromIntegral largs) pargs exceptions
655 jsobjectcallasfunction gctxt rfunction rthis (fromIntegral largs) pargs exceptions
706 makeNewJSVal result
656 makeNewJSVal result
707−{-# INLINE objCallAsFunction #-}
708#endif
657#endif
709
658
710-- | Call a JavaScript object as a constructor. Consider using 'new'.
659-- | Call a JavaScript object as a constructor. Consider using 'new'.
src/Language/Javascript/JSaddle/Properties.hs−8
@@ -58,7 +58,6 @@ objGetPropertyByName :: ToJSString name
58 -> JSM JSVal -- ^ returns the property value.
58 -> JSM JSVal -- ^ returns the property value.
59#ifdef ghcjs_HOST_OS
59#ifdef ghcjs_HOST_OS
60objGetPropertyByName this name = liftIO . js_tryGetProp (toJSString name) this
60objGetPropertyByName this name = liftIO . js_tryGetProp (toJSString name) this
61−{-# INLINE objGetPropertyByName #-}
62foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
61foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
63 js_tryGetProp :: JSString -> Object -> MutableJSArray -> IO JSVal
62 js_tryGetProp :: JSString -> Object -> MutableJSArray -> IO JSVal
64#else
63#else
@@ -67,7 +66,6 @@ objGetPropertyByName this name exceptions = do
67 withObject this $ \rthis ->
66 withObject this $ \rthis ->
68 withJSString (toJSString name) $ \name' ->
67 withJSString (toJSString name) $ \name' ->
69 (liftIO $ jsobjectgetproperty gctxt rthis name' exceptions) >>= makeNewJSVal
68 (liftIO $ jsobjectgetproperty gctxt rthis name' exceptions) >>= makeNewJSVal
70−{-# INLINE objGetPropertyByName #-}
71#endif
69#endif
72
70
73-- | Get a property value given the object and the index of the property.
71-- | Get a property value given the object and the index of the property.
@@ -77,7 +75,6 @@ objGetPropertyAtIndex :: Object -- ^ object to find the property on.
77 -> JSM JSVal -- ^ returns the property value.
75 -> JSM JSVal -- ^ returns the property value.
78#ifdef ghcjs_HOST_OS
76#ifdef ghcjs_HOST_OS
79objGetPropertyAtIndex this index = liftIO . js_tryIndex index this
77objGetPropertyAtIndex this index = liftIO . js_tryIndex index this
80−{-# INLINE objGetPropertyAtIndex #-}
81foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
78foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
82 js_tryIndex :: Index -> Object -> MutableJSArray -> IO JSVal
79 js_tryIndex :: Index -> Object -> MutableJSArray -> IO JSVal
83#else
80#else
@@ -85,7 +82,6 @@ objGetPropertyAtIndex this index exceptions = do
85 gctxt <- ask
82 gctxt <- ask
86 withObject this $ \rthis ->
83 withObject this $ \rthis ->
87 (liftIO $ jsobjectgetpropertyatindex gctxt rthis index exceptions) >>= makeNewJSVal
84 (liftIO $ jsobjectgetpropertyatindex gctxt rthis index exceptions) >>= makeNewJSVal
88−{-# INLINE objGetPropertyAtIndex #-}
89#endif
85#endif
90
86
91-- | Set a property value given the object and the name of the property.
87-- | Set a property value given the object and the name of the property.
@@ -100,7 +96,6 @@ objSetPropertyByName :: (ToJSString name, ToJSVal val)
100objSetPropertyByName this name val attributes exceptions = do
96objSetPropertyByName this name val attributes exceptions = do
101 vref <- toJSVal val
97 vref <- toJSVal val
102 liftIO $ js_trySetProp (toJSString name) this vref exceptions
98 liftIO $ js_trySetProp (toJSString name) this vref exceptions
103−{-# INLINE objSetPropertyByName #-}
104foreign import javascript unsafe "try { $2[$1]=$3 } catch(e) { $4[0] = e }"
99foreign import javascript unsafe "try { $2[$1]=$3 } catch(e) { $4[0] = e }"
105 js_trySetProp :: JSString -> Object -> JSVal -> MutableJSArray -> IO ()
100 js_trySetProp :: JSString -> Object -> JSVal -> MutableJSArray -> IO ()
106#else
101#else
@@ -110,7 +105,6 @@ objSetPropertyByName this name val attributes exceptions = do
110 withJSString (toJSString name) $ \name' ->
105 withJSString (toJSString name) $ \name' ->
111 withToJSVal val $ \rval ->
106 withToJSVal val $ \rval ->
112 liftIO $ jsobjectsetproperty gctxt rthis name' rval attributes exceptions
107 liftIO $ jsobjectsetproperty gctxt rthis name' rval attributes exceptions
113−{-# INLINE objSetPropertyByName #-}
114#endif
108#endif
115
109
116-- | Set a property value given the object and the index of the property.
110-- | Set a property value given the object and the index of the property.
@@ -124,7 +118,6 @@ objSetPropertyAtIndex :: (ToJSVal val)
124objSetPropertyAtIndex this index val exceptions = do
118objSetPropertyAtIndex this index val exceptions = do
125 vref <- toJSVal val
119 vref <- toJSVal val
126 liftIO $ js_trySetAtIndex index this vref exceptions
120 liftIO $ js_trySetAtIndex index this vref exceptions
127−{-# INLINE objSetPropertyAtIndex #-}
128foreign import javascript unsafe "try { $2[$1]=$3 } catch(e) { $4[0] = e }"
121foreign import javascript unsafe "try { $2[$1]=$3 } catch(e) { $4[0] = e }"
129 js_trySetAtIndex :: Index -> Object -> JSVal -> MutableJSArray -> IO ()
122 js_trySetAtIndex :: Index -> Object -> JSVal -> MutableJSArray -> IO ()
130#else
123#else
@@ -133,6 +126,5 @@ objSetPropertyAtIndex this index val exceptions = do
133 withObject this $ \rthis ->
126 withObject this $ \rthis ->
134 withToJSVal val $ \rval ->
127 withToJSVal val $ \rval ->
135 liftIO $ jsobjectsetpropertyatindex gctxt rthis index rval exceptions
128 liftIO $ jsobjectsetpropertyatindex gctxt rthis index rval exceptions
136−{-# INLINE objSetPropertyAtIndex #-}
137#endif
129#endif
138
130
src/Language/Javascript/JSaddle/String.hs−2
@@ -54,7 +54,6 @@ strToText jsstring' = liftIO $ withJSString jsstring' $ \jsstring -> do
54 p <- jsstringgetcharactersptr jsstring
54 p <- jsstringgetcharactersptr jsstring
55 T.fromPtr (castPtr p) (fromIntegral l)
55 T.fromPtr (castPtr p) (fromIntegral l)
56#endif
56#endif
57−{-# INLINE strToText #-}
58
57
59-- | Convert a Haskell 'Text' to a JavaScript string
58-- | Convert a Haskell 'Text' to a JavaScript string
60textToStr :: Text -> JSString
59textToStr :: Text -> JSString
@@ -65,7 +64,6 @@ textToStr text = unsafePerformIO $
65 useAsPtr text $ \p l ->
64 useAsPtr text $ \p l ->
66 jsstringcreatewithcharacters (castPtr p) (fromIntegral l) >>= makeNewJSString
65 jsstringcreatewithcharacters (castPtr p) (fromIntegral l) >>= makeNewJSString
67#endif
66#endif
68−{-# INLINE textToStr #-}
69
67
70nullJSString :: JSString
68nullJSString :: JSString
71#ifdef ghcjs_HOST_OS
69#ifdef ghcjs_HOST_OS
src/Language/Javascript/JSaddle/Value.hs−49
@@ -170,7 +170,6 @@ valToBool value = do
170 withToJSVal value $ \rval ->
170 withToJSVal value $ \rval ->
171 liftIO $ jsvaluetoboolean gctxt rval
171 liftIO $ jsvaluetoboolean gctxt rval
172#endif
172#endif
173−{-# INLINE valToBool #-}
174
173
175-- | Given a JavaScript value get its numeric value.
174-- | Given a JavaScript value get its numeric value.
176-- May throw JSException.
175-- May throw JSException.
@@ -194,14 +193,12 @@ valToBool value = do
194valToNumber :: ToJSVal value => value -> JSM Double
193valToNumber :: ToJSVal value => value -> JSM Double
195#ifdef ghcjs_HOST_OS
194#ifdef ghcjs_HOST_OS
196valToNumber value = jsrefToNumber <$> toJSVal value
195valToNumber value = jsrefToNumber <$> toJSVal value
197−{-# INLINE valToNumber #-}
198foreign import javascript unsafe "$r = Number($1);" jsrefToNumber :: JSVal -> Double
196foreign import javascript unsafe "$r = Number($1);" jsrefToNumber :: JSVal -> Double
199#else
197#else
200valToNumber value = do
198valToNumber value = do
201 gctxt <- ask
199 gctxt <- ask
202 withToJSVal value $ \rval ->
200 withToJSVal value $ \rval ->
203 rethrow $ liftIO . jsvaluetonumber gctxt rval
201 rethrow $ liftIO . jsvaluetonumber gctxt rval
204−{-# INLINE valToNumber #-}
205#endif
202#endif
206
203
207-- | Given a JavaScript value get its string value (as a JavaScript string).
204-- | Given a JavaScript value get its string value (as a JavaScript string).
@@ -226,14 +223,12 @@ valToNumber value = do
226valToStr :: ToJSVal value => value -> JSM JSString
223valToStr :: ToJSVal value => value -> JSM JSString
227#ifdef ghcjs_HOST_OS
224#ifdef ghcjs_HOST_OS
228valToStr value = jsrefToString <$> toJSVal value
225valToStr value = jsrefToString <$> toJSVal value
229−{-# INLINE valToStr #-}
230foreign import javascript unsafe "$r = $1.toString();" jsrefToString :: JSVal -> JSString
226foreign import javascript unsafe "$r = $1.toString();" jsrefToString :: JSVal -> JSString
231#else
227#else
232valToStr value = do
228valToStr value = do
233 gctxt <- ask
229 gctxt <- ask
234 withToJSVal value $ \rval ->
230 withToJSVal value $ \rval ->
235 rethrow (liftIO . jsvaluetostringcopy gctxt rval) >>= wrapJSString
231 rethrow (liftIO . jsvaluetostringcopy gctxt rval) >>= wrapJSString
236−{-# INLINE valToStr #-}
237#endif
232#endif
238
233
239-- | Given a JavaScript value get its string value (as a Haskell 'Text').
234-- | Given a JavaScript value get its string value (as a Haskell 'Text').
@@ -257,7 +252,6 @@ valToStr value = do
257-- "1"
252-- "1"
258valToText :: ToJSVal value => value -> JSM Text
253valToText :: ToJSVal value => value -> JSM Text
259valToText jsvar = valToStr jsvar >>= strToText
254valToText jsvar = valToStr jsvar >>= strToText
260−{-# INLINE valToText #-}
261
255
262-- | Given a JavaScript value get a JSON string value.
256-- | Given a JavaScript value get a JSON string value.
263-- May throw JSException.
257-- May throw JSException.
@@ -283,14 +277,12 @@ valToText jsvar = valToStr jsvar >>= strToText
283valToJSON :: ToJSVal value => Word -> value -> JSM JSString
277valToJSON :: ToJSVal value => Word -> value -> JSM JSString
284#ifdef ghcjs_HOST_OS
278#ifdef ghcjs_HOST_OS
285valToJSON indent value = jsrefToJSON <$> toJSVal value
279valToJSON indent value = jsrefToJSON <$> toJSVal value
286−{-# INLINE valToJSON #-}
287foreign import javascript unsafe "$r = JSON.stringify($1);" jsrefToJSON :: JSVal -> JSString
280foreign import javascript unsafe "$r = JSON.stringify($1);" jsrefToJSON :: JSVal -> JSString
288#else
281#else
289valToJSON indent value = do
282valToJSON indent value = do
290 gctxt <- ask
283 gctxt <- ask
291 withToJSVal value $ \rval ->
284 withToJSVal value $ \rval ->
292 rethrow (liftIO . jsvaluecreatejsonstring gctxt rval (fromIntegral indent)) >>= wrapJSString
285 rethrow (liftIO . jsvaluecreatejsonstring gctxt rval (fromIntegral indent)) >>= wrapJSString
293−{-# INLINE valToJSON #-}
294#endif
286#endif
295
287
296-- | Given a JavaScript value get its object value.
288-- | Given a JavaScript value get its object value.
@@ -321,34 +313,28 @@ valToObject value = Object <$>
321 withToJSVal value $ \rval ->
313 withToJSVal value $ \rval ->
322 rethrow (liftIO . jsvaluetoobject gctxt rval) >>= makeNewJSVal
314 rethrow (liftIO . jsvaluetoobject gctxt rval) >>= makeNewJSVal
323#endif
315#endif
324−{-# INLINE valToObject #-}
325
316
326instance MakeObject JSVal where
317instance MakeObject JSVal where
327 makeObject = valToObject
318 makeObject = valToObject
328− {-# INLINE makeObject #-}
329
319
330-- | Convert to a JavaScript value (just an alias for 'toJSVal')
320-- | Convert to a JavaScript value (just an alias for 'toJSVal')
331val :: ToJSVal value
321val :: ToJSVal value
332 => value -- ^ value to convert to a JavaScript value
322 => value -- ^ value to convert to a JavaScript value
333 -> JSM JSVal
323 -> JSM JSVal
334val = toJSVal
324val = toJSVal
335−{-# INLINE val #-}
336
325
337-- | If we already have a JSVal we are fine
326-- | If we already have a JSVal we are fine
338instance ToJSVal JSVal where
327instance ToJSVal JSVal where
339 toJSVal = return
328 toJSVal = return
340− {-# INLINE toJSVal #-}
341
329
342-- | A single JSVal can be used as the argument list
330-- | A single JSVal can be used as the argument list
343instance MakeArgs JSVal where
331instance MakeArgs JSVal where
344 makeArgs arg = return [arg]
332 makeArgs arg = return [arg]
345− {-# INLINE makeArgs #-}
346
333
347-- | JSVal can be made by evaluating a function in 'JSM' as long
334-- | JSVal can be made by evaluating a function in 'JSM' as long
348-- as it returns something we can make into a JSVal.
335-- as it returns something we can make into a JSVal.
349instance ToJSVal v => ToJSVal (JSM v) where
336instance ToJSVal v => ToJSVal (JSM v) where
350 toJSVal v = v >>= toJSVal
337 toJSVal v = v >>= toJSVal
351− {-# INLINE toJSVal #-}
352
338
353----------- null ---------------
339----------- null ---------------
354-- | Make a @null@ JavaScript value
340-- | Make a @null@ JavaScript value
@@ -358,23 +344,19 @@ valMakeNull = return jsNull
358#else
344#else
359valMakeNull = ask >>= (liftIO . jsvaluemakenull) >>= makeNewJSVal
345valMakeNull = ask >>= (liftIO . jsvaluemakenull) >>= makeNewJSVal
360#endif
346#endif
361−{-# INLINE valMakeNull #-}
362
347
363-- | Makes a @null@ JavaScript value
348-- | Makes a @null@ JavaScript value
364instance ToJSVal JSNull where
349instance ToJSVal JSNull where
365 toJSVal = const valMakeNull
350 toJSVal = const valMakeNull
366− {-# INLINE toJSVal #-}
367
351
368-- | Makes an argument list with just a single @null@ JavaScript value
352-- | Makes an argument list with just a single @null@ JavaScript value
369instance MakeArgs JSNull where
353instance MakeArgs JSNull where
370 makeArgs _ = valMakeNull >>= (\ref -> return [ref])
354 makeArgs _ = valMakeNull >>= (\ref -> return [ref])
371− {-# INLINE makeArgs #-}
372
355
373-- | Makes a JSVal or @null@ JavaScript value
356-- | Makes a JSVal or @null@ JavaScript value
374instance ToJSVal a => ToJSVal (Maybe a) where
357instance ToJSVal a => ToJSVal (Maybe a) where
375 toJSVal Nothing = valMakeNull
358 toJSVal Nothing = valMakeNull
376 toJSVal (Just a) = toJSVal a
359 toJSVal (Just a) = toJSVal a
377− {-# INLINE toJSVal #-}
378
360
379-- | Test a JavaScript value to see if it is @null@
361-- | Test a JavaScript value to see if it is @null@
380valIsNull :: ToJSVal value => value -> JSM Bool
362valIsNull :: ToJSVal value => value -> JSM Bool
@@ -386,7 +368,6 @@ valIsNull value = do
386 withToJSVal value $ \rval ->
368 withToJSVal value $ \rval ->
387 liftIO $ jsvalueisnull gctxt rval
369 liftIO $ jsvalueisnull gctxt rval
388#endif
370#endif
389−{-# INLINE valIsNull #-}
390
371
391----------- undefined ---------------
372----------- undefined ---------------
392-- | Make an @undefined@ JavaScript value
373-- | Make an @undefined@ JavaScript value
@@ -396,12 +377,10 @@ valMakeUndefined = return jsUndefined
396#else
377#else
397valMakeUndefined = ask >>= (liftIO . jsvaluemakeundefined) >>= makeNewJSVal
378valMakeUndefined = ask >>= (liftIO . jsvaluemakeundefined) >>= makeNewJSVal
398#endif
379#endif
399−{-# INLINE valMakeUndefined #-}
400
380
401-- | Makes an @undefined@ JavaScript value
381-- | Makes an @undefined@ JavaScript value
402instance ToJSVal JSUndefined where
382instance ToJSVal JSUndefined where
403 toJSVal = const valMakeUndefined
383 toJSVal = const valMakeUndefined
404− {-# INLINE toJSVal #-}
405
384
406--We can't allow this if JSUndefined is () as () is no args not "(null)".
385--We can't allow this if JSUndefined is () as () is no args not "(null)".
407--Use [()] instead.
386--Use [()] instead.
@@ -411,7 +390,6 @@ instance ToJSVal JSUndefined where
411-- | This allows us to pass no arguments easily (altenative would be to use @[]::[JSVal]@).
390-- | This allows us to pass no arguments easily (altenative would be to use @[]::[JSVal]@).
412instance MakeArgs () where
391instance MakeArgs () where
413 makeArgs _ = return []
392 makeArgs _ = return []
414− {-# INLINE makeArgs #-}
415
393
416-- | Test a JavaScript value to see if it is @undefined@
394-- | Test a JavaScript value to see if it is @undefined@
417valIsUndefined :: ToJSVal value => value -> JSM Bool
395valIsUndefined :: ToJSVal value => value -> JSM Bool
@@ -423,7 +401,6 @@ valIsUndefined value = do
423 withToJSVal value $ \rval ->
401 withToJSVal value $ \rval ->
424 liftIO $ jsvalueisundefined gctxt rval
402 liftIO $ jsvalueisundefined gctxt rval
425#endif
403#endif
426−{-# INLINE valIsUndefined #-}
427
404
428-- | Convert a JSVal to a Maybe JSVal (converting null and undefined to Nothing)
405-- | Convert a JSVal to a Maybe JSVal (converting null and undefined to Nothing)
429maybeNullOrUndefined :: ToJSVal value => value -> JSM (Maybe JSVal)
406maybeNullOrUndefined :: ToJSVal value => value -> JSM (Maybe JSVal)
@@ -435,7 +412,6 @@ maybeNullOrUndefined value = do
435 valIsUndefined rval >>= \case
412 valIsUndefined rval >>= \case
436 True -> return Nothing
413 True -> return Nothing
437 _ -> return (Just rval)
414 _ -> return (Just rval)
438−{-# INLINE maybeNullOrUndefined #-}
439
415
440maybeNullOrUndefined' :: ToJSVal value => (JSVal -> JSM a) -> value -> JSM (Maybe a)
416maybeNullOrUndefined' :: ToJSVal value => (JSVal -> JSM a) -> value -> JSM (Maybe a)
441maybeNullOrUndefined' f value = do
417maybeNullOrUndefined' f value = do
@@ -446,7 +422,6 @@ maybeNullOrUndefined' f value = do
446 valIsUndefined rval >>= \case
422 valIsUndefined rval >>= \case
447 True -> return Nothing
423 True -> return Nothing
448 _ -> Just <$> f rval
424 _ -> Just <$> f rval
449−{-# INLINE maybeNullOrUndefined' #-}
450
425
451----------- booleans ---------------
426----------- booleans ---------------
452-- | Make a JavaScript boolean value
427-- | Make a JavaScript boolean value
@@ -458,17 +433,14 @@ valMakeBool b = do
458 gctxt <- ask
433 gctxt <- ask
459 liftIO (jsvaluemakeboolean gctxt b) >>= makeNewJSVal
434 liftIO (jsvaluemakeboolean gctxt b) >>= makeNewJSVal
460#endif
435#endif
461−{-# INLINE valMakeBool #-}
462
436
463-- | Make a JavaScript boolean value
437-- | Make a JavaScript boolean value
464instance ToJSVal Bool where
438instance ToJSVal Bool where
465 toJSVal = valMakeBool
439 toJSVal = valMakeBool
466− {-# INLINE toJSVal #-}
467
440
468-- | Makes an argument list with just a single JavaScript boolean value
441-- | Makes an argument list with just a single JavaScript boolean value
469instance MakeArgs Bool where
442instance MakeArgs Bool where
470 makeArgs b = valMakeBool b >>= (\ref -> return [ref])
443 makeArgs b = valMakeBool b >>= (\ref -> return [ref])
471− {-# INLINE makeArgs #-}
472
444
473----------- numbers ---------------
445----------- numbers ---------------
474-- | Make a JavaScript number
446-- | Make a JavaScript number
@@ -480,45 +452,35 @@ valMakeNumber n = do
480 gctxt <- ask
452 gctxt <- ask
481 liftIO (jsvaluemakenumber gctxt n) >>= makeNewJSVal
453 liftIO (jsvaluemakenumber gctxt n) >>= makeNewJSVal
482#endif
454#endif
483−{-# INLINE valMakeNumber #-}
484
455
485-- | Makes a JavaScript number
456-- | Makes a JavaScript number
486instance ToJSVal Double where
457instance ToJSVal Double where
487 toJSVal = valMakeNumber
458 toJSVal = valMakeNumber
488− {-# INLINE toJSVal #-}
489
459
490instance ToJSVal Float where
460instance ToJSVal Float where
491 toJSVal = valMakeNumber . realToFrac
461 toJSVal = valMakeNumber . realToFrac
492− {-# INLINE toJSVal #-}
493
462
494instance ToJSVal Word where
463instance ToJSVal Word where
495 toJSVal = valMakeNumber . fromIntegral
464 toJSVal = valMakeNumber . fromIntegral
496− {-# INLINE toJSVal #-}
497
465
498instance ToJSVal Word32 where
466instance ToJSVal Word32 where
499 toJSVal = valMakeNumber . fromIntegral
467 toJSVal = valMakeNumber . fromIntegral
500− {-# INLINE toJSVal #-}
501
468
502instance ToJSVal Word64 where
469instance ToJSVal Word64 where
503 toJSVal = valMakeNumber . fromIntegral
470 toJSVal = valMakeNumber . fromIntegral
504− {-# INLINE toJSVal #-}
505
471
506instance ToJSVal Int where
472instance ToJSVal Int where
507 toJSVal = valMakeNumber . fromIntegral
473 toJSVal = valMakeNumber . fromIntegral
508− {-# INLINE toJSVal #-}
509
474
510instance ToJSVal Int32 where
475instance ToJSVal Int32 where
511 toJSVal = valMakeNumber . fromIntegral
476 toJSVal = valMakeNumber . fromIntegral
512− {-# INLINE toJSVal #-}
513
477
514instance ToJSVal Int64 where
478instance ToJSVal Int64 where
515 toJSVal = valMakeNumber . fromIntegral
479 toJSVal = valMakeNumber . fromIntegral
516− {-# INLINE toJSVal #-}
517
480
518-- | Makes an argument list with just a single JavaScript number
481-- | Makes an argument list with just a single JavaScript number
519instance MakeArgs Double where
482instance MakeArgs Double where
520 makeArgs n = valMakeNumber n >>= (\ref -> return [ref])
483 makeArgs n = valMakeNumber n >>= (\ref -> return [ref])
521− {-# INLINE makeArgs #-}
522
484
523-- | Make a JavaScript string from `Text`
485-- | Make a JavaScript string from `Text`
524valMakeText :: Text -> JSM JSVal
486valMakeText :: Text -> JSM JSVal
@@ -530,7 +492,6 @@ valMakeText text = do
530 withJSString (textToStr text) $ \s ->
492 withJSString (textToStr text) $ \s ->
531 liftIO (jsvaluemakestring gctxt s) >>= makeNewJSVal
493 liftIO (jsvaluemakestring gctxt s) >>= makeNewJSVal
532#endif
494#endif
533−{-# INLINE valMakeText #-}
534
495
535-- | Make a JavaScript string from `JSString`
496-- | Make a JavaScript string from `JSString`
536valMakeString :: JSString -> JSM JSVal
497valMakeString :: JSString -> JSM JSVal
@@ -542,40 +503,32 @@ valMakeString str = do
542 withJSString str $ \s ->
503 withJSString str $ \s ->
543 liftIO (jsvaluemakestring gctxt s) >>= makeNewJSVal
504 liftIO (jsvaluemakestring gctxt s) >>= makeNewJSVal
544#endif
505#endif
545−{-# INLINE valMakeString #-}
546
506
547-- | Makes a JavaScript string
507-- | Makes a JavaScript string
548instance ToJSVal Text where
508instance ToJSVal Text where
549 toJSVal = valMakeText
509 toJSVal = valMakeText
550− {-# INLINE toJSVal #-}
551
510
552-- | Makes an argument list with just a single JavaScript string
511-- | Makes an argument list with just a single JavaScript string
553instance MakeArgs Text where
512instance MakeArgs Text where
554 makeArgs t = valMakeText t >>= (\ref -> return [ref])
513 makeArgs t = valMakeText t >>= (\ref -> return [ref])
555− {-# INLINE makeArgs #-}
556
514
557-- | Makes a JavaScript string
515-- | Makes a JavaScript string
558instance ToJSVal String where
516instance ToJSVal String where
559 toJSVal = valMakeText . T.pack
517 toJSVal = valMakeText . T.pack
560− {-# INLINE toJSVal #-}
561
518
562-- | Makes a JavaScript string
519-- | Makes a JavaScript string
563instance ToJSVal JSString where
520instance ToJSVal JSString where
564 toJSVal = valMakeString
521 toJSVal = valMakeString
565− {-# INLINE toJSVal #-}
566
522
567-- | If we already have a JSString we are fine
523-- | If we already have a JSString we are fine
568instance ToJSString JSString where
524instance ToJSString JSString where
569 toJSString = id
525 toJSString = id
570− {-# INLINE toJSString #-}
571
526
572instance ToJSString Text where
527instance ToJSString Text where
573 toJSString = textToStr
528 toJSString = textToStr
574− {-# INLINE toJSString #-}
575
529
576instance ToJSString String where
530instance ToJSString String where
577 toJSString = textToStr . T.pack
531 toJSString = textToStr . T.pack
578− {-# INLINE toJSString #-}
579
532
580-- | Derefernce a value reference.
533-- | Derefernce a value reference.
581--
534--
@@ -653,12 +606,10 @@ valMakeRef value =
653-- | Makes a JavaScript value from a 'JSValue' ADT.
606-- | Makes a JavaScript value from a 'JSValue' ADT.
654instance ToJSVal JSValue where
607instance ToJSVal JSValue where
655 toJSVal = valMakeRef
608 toJSVal = valMakeRef
656− {-# INLINE toJSVal #-}
657
609
658-- | Makes an argument list with just a single JavaScript value from a 'JSValue' ADT.
610-- | Makes an argument list with just a single JavaScript value from a 'JSValue' ADT.
659instance MakeArgs JSValue where
611instance MakeArgs JSValue where
660 makeArgs v = valMakeRef v >>= (\ref -> return [ref])
612 makeArgs v = valMakeRef v >>= (\ref -> return [ref])
661− {-# INLINE makeArgs #-}
662
613
663--instance MakeObjectRef JSNull where
614--instance MakeObjectRef JSNull where
664-- makeObjectRef _ = Object <$> valMakeNull
615-- makeObjectRef _ = Object <$> valMakeNull