@@ -20,8 +20,8 @@
2020-----------------------------------------------------------------------------
2121
2222module Language.Javascript.JSaddle.Object (
23− JSObjectRef
24− , MakeObjectRef(..)
23+ Object
24+ , MakeObject(..)
2525
2626 -- * Property lookup
2727 , (!)
@@ -76,21 +76,20 @@ module Language.Javascript.JSaddle.Object (
7676
7777import Prelude hiding ((!!))
7878import Language.Javascript.JSaddle.Types
79− (JSPropertyNameArrayRef, JSStringRef, JSObjectRef, JSValueRefRef,
80− JSValueRef, JSContextRef, Index, castRef)
79+ (JSPropertyNameArrayRef, JSStringRef, Object(..), JSValueRefRef,
80+ JSValueRef, JSContextRef, Index)
8181import Foreign.C.Types (CSize(..), CULong(..), CUInt(..), CULLong(..))
8282#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
83−import GHCJS.Types (nullRef)
84−import qualified JavaScript.Object.Internal as Object
85−import JavaScript.Object.Internal (Object(Object))
86−import GHCJS.Foreign.Callback (syncCallback2, OnBlocked(ThrowWouldBlock))
87−--import GHCJS.Foreign (newObj, toArray, fromArray, syncCallback2, ForeignRetention(..))
83+import GHCJS.Types (nullRef, jsval)
84+import GHCJS.Foreign.Callback (syncCallback2, OnBlocked(..), Callback)
85+import GHCJS.Marshal.Pure (pFromJSVal)
86+import JavaScript.Array (JSArray)
87+import qualified JavaScript.Array as Array (toListIO, fromListIO)
88+import JavaScript.Array.Internal (SomeJSArray(..))
89+import qualified JavaScript.Object as Object (create)
8890import Control.Monad (liftM)
8991import Control.Applicative ((<$>))
90−import qualified JavaScript.Array as Array
91−import JavaScript.Array (JSArray)
92−import GHCJS.Prim (JSRef)
93−import Data.JSString (JSString)
92+import Data.Coerce (coerce)
9493#else
9594import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSObjectRef
9695 (jsobjectmake, jspropertynamearraygetnameatindex,
@@ -112,7 +111,7 @@ import Language.Javascript.JSaddle.Value
112111import Language.Javascript.JSaddle.PropRef (JSPropRef(..))
113112import Language.Javascript.JSaddle.Classes
114113 (MakeValueRef(..), MakeStringRef(..), MakeArgRefs(..), MakePropRef(..),
115− MakeObjectRef(..))
114+ MakeObject(..))
116115import Language.Javascript.JSaddle.Monad
117116 (JSM)
118117import Control.Monad.Trans.Reader (runReaderT, ask)
@@ -126,23 +125,16 @@ import Control.Lens
126125 (IndexPreservingGetter, to, (^.))
127126import Language.Javascript.JSaddle.String (textToStr)
128127
129−objectToRef (Object r) = r
130−
131−foreign import javascript unsafe
132− "$r = $1" jsRefToJSSTring :: JSRef -> JSString
133−
134−foreign import javascript unsafe
135− "$r = $1" getJSArrayRef :: JSArray -> JSRef
136−
128+-- | If we already have a Object we are fine
129+instance MakeObject Object where
130+ makeObject = return
131+ {-# INLINE makeObject #-}
137132
138−-- | If we already have a JSObjectRef we are fine
139−instance MakeObjectRef JSObjectRef where
140− makeObjectRef = return
141−
142−-- | JSObjectRef can be made by evaluating a function in 'JSM' as long
143−-- as it returns something we can make into a JSObjectRef.
144−instance MakeObjectRef v => MakeObjectRef (JSM v) where
145− makeObjectRef v = v >>= makeObjectRef
133+-- | Object can be made by evaluating a function in 'JSM' as long
134+-- as it returns something we can make into a Object.
135+instance MakeObject v => MakeObject (JSM v) where
136+ makeObject v = v >>= makeObject
137+ {-# INLINE makeObject #-}
146138
147139-- | Lookup a property based on its name. This function just constructs a JSPropRef
148140-- the lookup is delayed until we use the JSPropRef. This makes it a bit lazy compared
@@ -151,15 +143,16 @@ instance MakeObjectRef v => MakeObjectRef (JSM v) where
151143-- >>> testJSaddle $ eval "'Hello World'.length"
152144-- >>> testJSaddle $ val "Hello World" ! "length"
153145-- 11
154−(!) :: (MakeObjectRef this, MakeStringRef name)
146+(!) :: (MakeObject this, MakeStringRef name)
155147 => this -- ^ Object to look on
156148 -> name -- ^ Name of the property to find
157149 -> JSM JSPropRef -- ^ Property reference
158150this ! name = do
159− rthis <- makeObjectRef this
151+ rthis <- makeObject this
160152 return (JSPropRef rthis rname)
161153 where
162154 rname = makeStringRef name
155+{-# INLINE (!) #-}
163156
164157-- | Lookup a property based on its index. This function just constructs a JSPropRef
165158-- the lookup is delayed until we use the JSPropRef. This makes it a bit lazy compared
@@ -168,13 +161,14 @@ this ! name = do
168161-- >>> testJSaddle $ eval "'Hello World'[6]"
169162-- >>> testJSaddle $ val "Hello World" !! 6
170163-- W
171−(!!) :: (MakeObjectRef this)
164+(!!) :: (MakeObject this)
172165 => this -- ^ Object to look on
173166 -> Index -- ^ Index of the property to lookup
174167 -> JSM JSPropRef -- ^ Property reference
175168this !! index = do
176− rthis <- makeObjectRef this
169+ rthis <- makeObject this
177170 return (JSPropIndexRef rthis index)
171+{-# INLINE (!!) #-}
178172
179173-- | Makes a getter for a particular property name.
180174--
@@ -183,13 +177,14 @@ this !! index = do
183177-- >>> testJSaddle $ eval "'Hello World'.length"
184178-- >>> testJSaddle $ val "Hello World" ^. js "length"
185179-- 11
186−js :: (MakeObjectRef s, MakeStringRef name)
180+js :: (MakeObject s, MakeStringRef name)
187181 => name -- ^ Name of the property to find
188182 -> IndexPreservingGetter s (JSM JSPropRef)
189183js name = to (!name)
184+{-# INLINE js #-}
190185
191186-- | Java script function applications have this type
192−type JSF = MakeObjectRef o => IndexPreservingGetter o (JSM JSValueRef)
187+type JSF = forall o . MakeObject o => IndexPreservingGetter o (JSM JSValueRef)
193188
194189-- | Handy way to call a function
195190--
@@ -201,6 +196,7 @@ jsf :: (MakeStringRef name, MakeArgRefs args) => name -> args -> JSF
201196jsf name args = function . to (# args)
202197 where
203198 function = js name
199+{-# INLINE jsf #-}
204200
205201-- | Handy way to call a function that expects no arguments
206202--
@@ -210,6 +206,7 @@ jsf name args = function . to (# args)
210206-- hello world
211207js0 :: (MakeStringRef name) => name -> JSF
212208js0 name = jsf name ()
209+{-# INLINE js0 #-}
213210
214211-- | Handy way to call a function that expects one argument
215212--
@@ -219,27 +216,32 @@ js0 name = jsf name ()
219216-- 6
220217js1 :: (MakeStringRef name, MakeValueRef a0) => name -> a0 -> JSF
221218js1 name a0 = jsf name [a0]
219+{-# INLINE js1 #-}
222220
223221-- | Handy way to call a function that expects two arguments
224222js2 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1) => name -> a0 -> a1 -> JSF
225223js2 name a0 a1 = jsf name (a0, a1)
224+{-# INLINE js2 #-}
226225
227226-- | Handy way to call a function that expects three arguments
228227js3 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2)
229228 => name -> a0 -> a1 -> a2 -> JSF
230229js3 name a0 a1 a2 = jsf name (a0, a1, a2)
230+{-# INLINE js3 #-}
231231
232232-- | Handy way to call a function that expects four arguments
233233js4 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2,
234234 MakeValueRef a3)
235235 => name -> a0 -> a1 -> a2 -> a3 -> JSF
236236js4 name a0 a1 a2 a3 = jsf name (a0, a1, a2, a3)
237+{-# INLINE js4 #-}
237238
238239-- | Handy way to call a function that expects five arguments
239240js5 :: (MakeStringRef name, MakeValueRef a0, MakeValueRef a1, MakeValueRef a2,
240241 MakeValueRef a3, MakeValueRef a4)
241242 => name -> a0 -> a1 -> a2 -> a3 -> a4 -> JSF
242243js5 name a0 a1 a2 a3 a4 = jsf name (a0, a1, a2, a3, a4)
244+{-# INLINE js5 #-}
243245
244246
245247-- | Handy way to get and hold onto a reference top level javascript
@@ -249,6 +251,7 @@ js5 name a0 a1 a2 a3 a4 = jsf name (a0, a1, a2, a3, a4)
249251-- 11
250252jsg :: MakeStringRef a => a -> JSM JSPropRef
251253jsg name = global ! name
254+{-# INLINE jsg #-}
252255
253256-- | Call a JavaScript function
254257--
@@ -261,7 +264,9 @@ infixr 2 #
261264prop # args = do
262265 rprop <- makePropRef prop
263266 (this, f) <- objGetProperty' rprop
264− rethrow $ objCallAsFunction (castRef f) this args
267+ f' <- valToObject f
268+ rethrow $ objCallAsFunction f' this args
269+{-# INLINE (#) #-}
265270
266271-- | Call a JavaScript function
267272--
@@ -277,6 +282,7 @@ prop <# val = do
277282 p <- makePropRef prop
278283 objSetProperty p val
279284 return p
285+{-# INLINE (<#) #-}
280286
281287-- | Use this to create a new JavaScript object
282288--
@@ -285,39 +291,42 @@ prop <# val = do
285291--
286292-- >>> testJSaddle $ new "Date" (2013, 1, 1)
287293-- Fri Feb 01 2013 00:00:00 GMT+1300 (NZDT)
288−new :: (MakeObjectRef constructor, MakeArgRefs args)
294+new :: (MakeObject constructor, MakeArgRefs args)
289295 => constructor
290296 -> args
291297 -> JSM JSValueRef
292298new constructor args = do
293− f <- makeObjectRef constructor
299+ f <- makeObject constructor
294300 rethrow $ objCallAsConstructor f args
301+{-# INLINE new #-}
295302
296303-- | Call function with a given @this@. In most cases you should use '#'.
297304--
298305-- >>> testJSaddle $ eval "(function(){return this;}).apply('Hello', [])"
299306-- >>> testJSaddle $ do { test <- eval "(function(){return this;})"; call test (val "Hello") () }
300307-- Hello
301−call :: (MakeObjectRef function, MakeObjectRef this, MakeArgRefs args)
308+call :: (MakeObject function, MakeObject this, MakeArgRefs args)
302309 => function -> this -> args -> JSM JSValueRef
303310call function this args = do
304− rfunction <- makeObjectRef function
305− rthis <- makeObjectRef this
311+ rfunction <- makeObject function
312+ rthis <- makeObject this
306313 rethrow $ objCallAsFunction rfunction rthis args
314+{-# INLINE call #-}
307315
308316-- | Make an empty object using the default constuctor
309317--
310318-- >>> testJSaddle $ eval "var a = {}; a.x = 'Hello'; a.x"
311319-- >>> testJSaddle $ do { a <- obj; a ^. js "x" <# "Hello"; a ^. js "x" }
312320-- Hello
313−obj :: JSM JSObjectRef
321+obj :: JSM Object
314322#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
315−obj = liftIO (castRef . objectToRef <$> Object.create)
323+obj = liftIO Object.create
316324#else
317325obj = do
318326 gctxt <- ask
319− liftIO $ jsobjectmake gctxt nullPtr nullPtr
327+ liftIO $ Object <$> jsobjectmake gctxt nullPtr nullPtr
320328#endif
329+{-# INLINE obj #-}
321330
322331-- | Type used for Haskell functions called from JavaScript.
323332type JSCallAsFunction = JSValueRef -- ^ Function object
@@ -338,81 +347,79 @@ type JSCallAsFunction = JSValueRef -- ^ Function object
338347-- undefined
339348fun :: JSCallAsFunction -> JSCallAsFunction
340349fun = id
350+{-# INLINE fun #-}
341351
342352#if (!defined(ghcjs_HOST_OS) || !defined(USE_JAVASCRIPTFFI)) && defined(USE_WEBKIT)
343353foreign import ccall "wrapper"
344354 mkJSObjectCallAsFunctionCallback :: JSObjectCallAsFunctionCallback' -> IO JSObjectCallAsFunctionCallback
345355#endif
346356
347−fromArray :: JSArray -> IO [JSStringRef]
348−fromArray a = fmap jsRefToJSSTring <$> Array.toListIO a
349−toArray :: [JSValueRef] -> IO JSArray
350−toArray a = Array.fromListIO (fmap castRef a)
351−
352357-- ^ Make a JavaScript function object that wraps a Haskell function.
353358function :: MakeStringRef name
354359 => name -- ^ Name of the function
355360 -> JSCallAsFunction -- ^ Haskell function to call
356− -> JSM JSObjectRef -- ^ Returns a JavaScript function object that will
361+ -> JSM Object -- ^ Returns a JavaScript function object that will
357362 -- call the Haskell one when it is called
358−-- #if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
359−-- function name f = liftIO $ do
360−-- callback <- syncCallback2 ThrowWouldBlock True $ \this args -> do
361−-- rargs <- fromArray args
362−-- runReaderT (f this this rargs) () -- TODO pass function object through
363−-- makeFunctionWithCallback (makeStringRef name) callback
364−-- foreign import javascript unsafe "$r = function () { $2(this, arguments); }"
365−-- makeFunctionWithCallback :: JSStringRef -> JSFun (JSValueRef -> JSValueRefRef -> IO ()) -> IO JSObjectRef
366−-- #elif defined(USE_WEBKIT)
367−-- function name f = do
368−-- gctxt <- ask
369−-- callback <- liftIO $ mkJSObjectCallAsFunctionCallback wrap
370−-- liftIO $ jsobjectmakefunctionwithcallback gctxt (makeStringRef name) callback
371−-- where
372−-- wrap ctx fobj this argc argv exception = do
373−-- args <- peekArray (fromIntegral argc) argv
374−-- (`runReaderT` ctx) $
375−-- f fobj this args >>= makeValueRef
376−-- `E.catch` \(e :: SomeException) -> do
377−-- str <- runReaderT (makeValueRef . T.pack $ show e) ctx
378−-- poke exception str
379−-- jsvaluemakeundefined ctx
380−-- #else
381−-- function = undefined
382−-- #endif
383−
384−function = undefined
363+#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
364+function name f = liftIO $ do
365+ callback <- syncCallback2 ContinueAsync $ \this args -> do
366+ rargs <- Array.toListIO (coerce args)
367+ runReaderT (f this this rargs) () -- TODO pass function object through
368+ makeFunctionWithCallback (makeStringRef name) callback
369+foreign import javascript unsafe "$r = function () { $2(this, arguments); }"
370+ makeFunctionWithCallback :: JSStringRef -> Callback (JSValueRef -> JSValueRef -> IO ()) -> IO Object
371+#elif defined(USE_WEBKIT)
372+function name f = do
373+ gctxt <- ask
374+ callback <- liftIO $ mkJSObjectCallAsFunctionCallback wrap
375+ liftIO $ Object <$> jsobjectmakefunctionwithcallback gctxt (makeStringRef name) callback
376+ where
377+ wrap ctx fobj this argc argv exception = do
378+ args <- peekArray (fromIntegral argc) argv
379+ (`runReaderT` ctx) $
380+ f fobj this args >>= makeValueRef
381+ `E.catch` \(e :: SomeException) -> do
382+ str <- runReaderT (makeValueRef . T.pack $ show e) ctx
383+ poke exception str
384+ jsvaluemakeundefined ctx
385+#else
386+function = undefined
387+#endif
385388
386389-- | A callback to Haskell can be used as a JavaScript value. This will create
387390-- an anonymous JavaScript function object. Use 'function' to create one with
388391-- a name.
389392instance MakeValueRef JSCallAsFunction where
390393#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
391− makeValueRef a = castRef <$> function (jsRefToJSSTring nullRef :: JSStringRef) a
394+ makeValueRef f = jsval <$> function (pFromJSVal nullRef :: JSStringRef) f
392395#else
393− makeValueRef a = castRef <$> function (jsRefToJSSTring nullPtr :: JSStringRef) a
396+ makeValueRef f = function (nullPtr :: JSStringRef) f >>= makeValueRef
394397#endif
398+ {-# INLINE makeValueRef #-}
395399
396400instance MakeArgRefs JSCallAsFunction where
397401 makeArgRefs f = do
398402#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
399− rarg <- function (jsRefToJSSTring nullRef :: JSStringRef) f
403+ rarg <- jsval <$> function (pFromJSVal nullRef :: JSStringRef) f
400404#else
401− rarg <- function (jsRefToJSSTring nullPtr :: JSStringRef) f
405+ rarg <- function (nullPtr:: JSStringRef) f >>= makeValueRef
402406#endif
403− return [castRef rarg]
407+ return [rarg]
408+ {-# INLINE makeArgRefs #-}
404409
405−makeArray :: MakeArgRefs args => args -> JSValueRefRef -> JSM JSObjectRef
410+makeArray :: MakeArgRefs args => args -> JSValueRefRef -> JSM Object
406411#if (defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)) || !defined(USE_WEBKIT)
407−--makeArray args exceptions = makeArgRefs args >>= liftIO . toArray
408−makeArray args exceptions = makeArgRefs args >>= liftM (castRef . getJSArrayRef) . liftIO . toArray
412+makeArray args exceptions = do
413+ rargs <- makeArgRefs args
414+ liftIO $ Object . jsval <$> Array.fromListIO rargs
409415#else
410416makeArray args exceptions = do
411417 gctxt <- ask
412418 rargs <- makeArgRefs args
413419 liftIO $ withArrayLen rargs $ \ len ptr ->
414− jsobjectmakearray gctxt (fromIntegral len) ptr exceptions
420+ Object <$> jsobjectmakearray gctxt (fromIntegral len) ptr exceptions
415421#endif
422+{-# INLINE makeArray #-}
416423
417424-- | Make an JavaScript array from a list of values
418425--
@@ -422,79 +429,89 @@ makeArray args exceptions = do
422429-- >>> testJSaddle $ eval "['Hello', null, undefined, true, 1]"
423430-- >>> testJSaddle $ array ("Hello", JSNull, (), True, 1.0::Double)
424431-- Hello,,,true,1
425−array :: MakeArgRefs args => args -> JSM JSObjectRef
432+array :: MakeArgRefs args => args -> JSM Object
426433array = rethrow . makeArray
427434
428435-- | JavaScript's global object
429−global :: JSM JSObjectRef
436+global :: JSM Object
430437#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
431438global = liftIO js_window
439+{-# INLINE global #-}
432440foreign import javascript unsafe "$r = window"
433− js_window :: IO JSObjectRef
441+ js_window :: IO Object
434442#elif defined(USE_WEBKIT)
435−global = ask >>= (liftIO . jscontextgetglobalobject)
443+global = ask >>= (liftIO . fmap Object . jscontextgetglobalobject)
444+{-# INLINE global #-}
436445#else
437446global = undefined
438447#endif
439448
440449-- | Get an array containing the property names present on a given object
441450#if (!defined(ghcjs_HOST_OS) || !defined(USE_JAVASCRIPTFFI)) && defined(USE_WEBKIT)
442−copyPropertyNames :: MakeObjectRef this => this -> JSM JSPropertyNameArrayRef
451+copyPropertyNames :: MakeObject this => this -> JSM JSPropertyNameArrayRef
443452copyPropertyNames this = do
444453 gctxt <- ask
445− rthis <- makeObjectRef this
454+ Object rthis <- makeObject this
446455 liftIO $ jsobjectcopypropertynames gctxt rthis
456+{-# INLINE copyPropertyNames #-}
447457
448458-- | Get the number of names in a property name array
449459propertyNamesCount :: MonadIO m => JSPropertyNameArrayRef -> m CSize
450460propertyNamesCount names = liftIO $ jspropertynamearraygetcount names
461+{-# INLINE propertyNamesCount #-}
451462
452463-- | Get a name out of a property name array
453464propertyNamesAt :: MonadIO m => JSPropertyNameArrayRef -> CSize -> m JSStringRef
454465propertyNamesAt names index = liftIO $ jspropertynamearraygetnameatindex names index
466+{-# INLINE propertyNamesAt #-}
455467
456468-- | Convert property array to a list
457469propertyNamesList :: MonadIO m => JSPropertyNameArrayRef -> m [JSStringRef]
458470propertyNamesList names = do
459471 count <- propertyNamesCount names
460472 mapM (propertyNamesAt names) $ enumFromTo 0 (count - 1)
473+{-# INLINE propertyNamesList #-}
461474#endif
462475
463476-- | Get a list containing the property names present on a given object
464−propertyNames :: MakeObjectRef this => this -> JSM [JSStringRef]
477+propertyNames :: MakeObject this => this -> JSM [JSStringRef]
465478#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
466−propertyNames this = makeObjectRef this >>= liftIO . js_propertyNames >>= liftIO . fromArray
479+propertyNames this = makeObject this >>= liftIO . js_propertyNames >>= liftIO . (fmap (map pFromJSVal)) . Array.toListIO
480+{-# INLINE propertyNames #-}
467481foreign import javascript unsafe "$r = []; h$forIn($1, function(n){$r.push(n);})"
468− js_propertyNames :: JSObjectRef -> IO JSArray
482+ js_propertyNames :: Object -> IO JSArray
469483#elif defined(USE_WEBKIT)
470484propertyNames this = copyPropertyNames this >>= propertyNamesList
485+{-# INLINE propertyNames #-}
471486#else
472487propertyNames = undefined
473488#endif
474489
475490-- | Get a list containing references to all the properties present on a given object
476−properties :: MakeObjectRef this => this -> JSM [JSPropRef]
491+properties :: MakeObject this => this -> JSM [JSPropRef]
477492properties this = propertyNames this >>= mapM (this !)
478493
479494-- | Call a JavaScript object as function. Consider using '#'.
480495objCallAsFunction :: MakeArgRefs args
481− => JSObjectRef
482− -> JSObjectRef
496+ => Object
497+ -> Object
483498 -> args
484499 -> JSValueRefRef
485500 -> JSM JSValueRef
486501#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
487502objCallAsFunction function this args exceptions = do
488− rargs <- (makeArgRefs args >>= liftIO . toArray) >>= (liftIO . Array.thaw)
503+ rargs <- makeArgRefs args >>= liftIO . Array.fromListIO
489504 liftIO $ js_apply function this rargs exceptions
505+{-# INLINE objCallAsFunction #-}
490506foreign import javascript unsafe "try { $r = $1.apply($2, $3) } catch(e) { $4[0] = e }"
491− js_apply :: JSObjectRef -> JSObjectRef -> JSValueRefRef -> JSValueRefRef -> IO JSValueRef
507+ js_apply :: Object -> Object -> JSValueRefRef -> JSValueRefRef -> IO JSValueRef
492508#elif defined(USE_WEBKIT)
493−objCallAsFunction function this args exceptions = do
509+objCallAsFunction (Object function) (Object this) args exceptions = do
494510 gctxt <- ask
495511 rargs <- makeArgRefs args
496512 liftIO $ withArrayLen rargs $ \ largs pargs ->
497513 jsobjectcallasfunction gctxt function this (fromIntegral largs) pargs exceptions
514+{-# INLINE objCallAsFunction #-}
498515#else
499516objCallAsFunction = undefined
500517#endif
@@ -504,13 +521,13 @@ objCallAsFunction = undefined
504521-- If you pass more than 7 arguments to a constructor for a built in
505522-- JavaScript type (like Date) then this function will fail.
506523objCallAsConstructor :: MakeArgRefs args
507− => JSObjectRef
524+ => Object
508525 -> args
509526 -> JSValueRefRef
510527 -> JSM JSValueRef
511528#if defined(ghcjs_HOST_OS) && defined(USE_JAVASCRIPTFFI)
512529objCallAsConstructor function args exceptions = do
513− rargs <- (makeArgRefs args >>= liftIO . toArray) >>= (liftIO . Array.thaw)
530+ rargs <- makeArgRefs args >>= liftIO . Array.fromListIO
514531 liftIO $ js_new function rargs exceptions
515532foreign import javascript unsafe "\
516533 try {\
@@ -539,9 +556,9 @@ foreign import javascript unsafe "\
539556 catch(e) {\
540557 $3[0] = e;\
541558 }"
542− js_new :: JSObjectRef -> JSValueRefRef -> JSValueRefRef -> IO JSValueRef
559+ js_new :: Object -> JSValueRefRef -> JSValueRefRef -> IO JSValueRef
543560#elif defined(USE_WEBKIT)
544−objCallAsConstructor function args exceptions = do
561+objCallAsConstructor (Object function) args exceptions = do
545562 gctxt <- ask
546563 rargs <- makeArgRefs args
547564 liftIO $ withArrayLen rargs $ \ largs pargs ->