-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Wrapper for the QuickJS Javascript Engine -- -- This library is a wrapper for the QuickJS Javascript Engine. -- -- To get started, see the ReadMe below. @package quickjs-hs @version 0.1 module Quickjs.Types data JSValue JSValue :: {-# UNPACK #-} !CDouble -> {-# UNPACK #-} !CLong -> JSValue [u] :: JSValue -> {-# UNPACK #-} !CDouble [tag] :: JSValue -> {-# UNPACK #-} !CLong type JSValueConst = JSValue newtype JSRuntime JSRuntime :: CUChar -> JSRuntime [_unusedRuntime] :: JSRuntime -> CUChar newtype JSContext JSContext :: CUChar -> JSContext [_unusedContext] :: JSContext -> CUChar type JSBool = CInt type JSAtom = CUInt data JSPropertyEnum JSPropertyEnum :: {-# UNPACK #-} !JSBool -> {-# UNPACK #-} !JSAtom -> JSPropertyEnum [is_enumerable] :: JSPropertyEnum -> {-# UNPACK #-} !JSBool [atom] :: JSPropertyEnum -> {-# UNPACK #-} !JSAtom data JSRefCountHeader JSRefCountHeader :: {-# UNPACK #-} !CInt -> JSRefCountHeader [ref_count] :: JSRefCountHeader -> {-# UNPACK #-} !CInt class ToCType ty cty toCType :: ToCType ty cty => ty -> cty class FromCType ty cty fromCType :: FromCType ty cty => cty -> Maybe ty data JSTagEnum JSTagFirst :: JSTagEnum JSTagBigDecimal :: JSTagEnum JSTagBigInt :: JSTagEnum JSTagBigFloat :: JSTagEnum JSTagSymbol :: JSTagEnum JSTagString :: JSTagEnum JSTagModule :: JSTagEnum JSTagFunctionBytecode :: JSTagEnum JSTagObject :: JSTagEnum JSTagInt :: JSTagEnum JSTagBool :: JSTagEnum JSTagNull :: JSTagEnum JSTagUndefined :: JSTagEnum JSTagUninitialized :: JSTagEnum JSTagCatchOffset :: JSTagEnum JSTagException :: JSTagEnum JSTagFloat64 :: JSTagEnum data JSTypeEnum JSTypeFromTag :: JSTagEnum -> JSTypeEnum JSIsNumber :: JSTypeEnum JSIsArray :: JSTypeEnum JSIsDate :: JSTypeEnum JSIsError :: JSTypeEnum data JSEvalType Global :: JSEvalType Module :: JSEvalType newtype JSGPNMask JSGPNMask :: CInt -> JSGPNMask [unJSGPNMask] :: JSGPNMask -> CInt jsGPNStringMask :: JSGPNMask jsGPNSymbolMask :: JSGPNMask jsGPNPrivateMask :: JSGPNMask jsGPNEnumOnly :: JSGPNMask jsGPNSetEnum :: JSGPNMask quickjsCtx :: Context quickjsTypesTable :: Map TypeSpecifier TypeQ instance GHC.Classes.Eq Quickjs.Types.JSValue instance GHC.Show.Show Quickjs.Types.JSValue instance GHC.Classes.Eq Quickjs.Types.JSPropertyEnum instance GHC.Show.Show Quickjs.Types.JSPropertyEnum instance GHC.Classes.Eq Quickjs.Types.JSRefCountHeader instance GHC.Show.Show Quickjs.Types.JSRefCountHeader instance GHC.Classes.Eq Quickjs.Types.JSTagEnum instance GHC.Show.Show Quickjs.Types.JSTagEnum instance GHC.Show.Show Quickjs.Types.JSTypeEnum instance Data.Bits.Bits Quickjs.Types.JSGPNMask instance GHC.Classes.Eq Quickjs.Types.JSGPNMask instance GHC.Num.Num a => Quickjs.Types.ToCType Quickjs.Types.JSEvalType a instance GHC.Num.Num a => Quickjs.Types.ToCType Quickjs.Types.JSTagEnum a instance (GHC.Classes.Eq a, GHC.Num.Num a) => Quickjs.Types.FromCType Quickjs.Types.JSTagEnum a instance Foreign.Storable.Storable Quickjs.Types.JSRefCountHeader instance Foreign.Storable.Storable Quickjs.Types.JSPropertyEnum instance Foreign.Storable.Storable Quickjs.Types.JSValue module Quickjs.Error data SomeJSRuntimeException SomeJSRuntimeException :: e -> SomeJSRuntimeException jsRuntimeExceptionToException :: Exception e => e -> SomeException jsRuntimeExceptionFromException :: Exception e => SomeException -> Maybe e newtype JSRuntimeException e JSRuntimeException :: e -> JSRuntimeException e data UnknownJSTag UnknownJSTag :: !CLong -> UnknownJSTag [$sel:raw_tag:UnknownJSTag] :: UnknownJSTag -> !CLong data UnsupportedTypeTag UnsupportedTypeTag :: JSTagEnum -> UnsupportedTypeTag [$sel:_tag:UnsupportedTypeTag] :: UnsupportedTypeTag -> JSTagEnum data JSException JSException :: Text -> Text -> JSException [$sel:location:JSException] :: JSException -> Text [$sel:message:JSException] :: JSException -> Text data JSValueUndefined JSValueUndefined :: Text -> JSValueUndefined [$sel:value:JSValueUndefined] :: JSValueUndefined -> Text data JSValueIncorrectType JSValueIncorrectType :: Text -> JSTypeEnum -> JSTypeEnum -> JSValueIncorrectType [$sel:name:JSValueIncorrectType] :: JSValueIncorrectType -> Text [$sel:expected:JSValueIncorrectType] :: JSValueIncorrectType -> JSTypeEnum [$sel:found:JSValueIncorrectType] :: JSValueIncorrectType -> JSTypeEnum data InternalError InternalError :: Text -> InternalError [$sel:message:InternalError] :: InternalError -> Text instance GHC.Show.Show e => GHC.Show.Show (Quickjs.Error.JSRuntimeException e) instance GHC.Generics.Generic (Quickjs.Error.JSRuntimeException e) instance GHC.Exception.Type.Exception Quickjs.Error.UnknownJSTag instance GHC.Generics.Generic Quickjs.Error.UnknownJSTag instance GHC.Exception.Type.Exception Quickjs.Error.UnsupportedTypeTag instance GHC.Generics.Generic Quickjs.Error.UnsupportedTypeTag instance GHC.Exception.Type.Exception Quickjs.Error.JSException instance GHC.Generics.Generic Quickjs.Error.JSException instance GHC.Exception.Type.Exception Quickjs.Error.JSValueUndefined instance GHC.Generics.Generic Quickjs.Error.JSValueUndefined instance GHC.Exception.Type.Exception Quickjs.Error.JSValueIncorrectType instance GHC.Generics.Generic Quickjs.Error.JSValueIncorrectType instance GHC.Exception.Type.Exception Quickjs.Error.InternalError instance GHC.Generics.Generic Quickjs.Error.InternalError instance GHC.Show.Show Quickjs.Error.InternalError instance GHC.Show.Show Quickjs.Error.JSValueIncorrectType instance GHC.Show.Show Quickjs.Error.JSValueUndefined instance GHC.Show.Show Quickjs.Error.JSException instance GHC.Show.Show Quickjs.Error.UnsupportedTypeTag instance GHC.Show.Show Quickjs.Error.UnknownJSTag instance (GHC.Show.Show e, Data.Typeable.Internal.Typeable e) => GHC.Exception.Type.Exception (Quickjs.Error.JSRuntimeException e) instance GHC.Show.Show Quickjs.Error.SomeJSRuntimeException instance GHC.Exception.Type.Exception Quickjs.Error.SomeJSRuntimeException instance Data.Aeson.Types.ToJSON.ToJSON Foreign.C.Types.CLong -- | This is a very basic wrapper for the QuickJS . -- -- The current functionality includes evaluating JS code, calling a JS -- function in the global scope and marshalling Values to and from -- JSValues. module Quickjs data JSValue type JSContextPtr = Ptr JSContext -- | This function initialises a new JS runtime and performs the given -- computation within this context. -- -- For example, we can evaluate an expression: -- --
-- quickjs $ do -- res <- eval "1+2" -- liftIO $ print res ---- -- Declare a function and call it on an argument: -- --
-- quickjs $ do -- _ <- eval_ "f = (x) => x+1" -- res <- eval "f(2)" -- liftIO $ print res ---- -- Pass a Haskell value to the JS runtime: -- --
-- quickjs $ do -- _ <- eval_ "f = (x) => x+1" -- res <- withJSValue (3::Int) $ \x -> call "f" [x] -- liftIO $ print res --quickjs :: MonadIO m => ReaderT (Ptr JSContext) m b -> m b -- | This env differs from regular quickjs, in that it wraps the -- computation in the runInBoundThread function. This is needed -- when running the Haskell program mutithreaded (e.g. when using the -- testing framework Tasty), since quickjs does not like being called -- from an OS thread other than the one it was started in. Because -- Haskell uses lightweight threads, this might happen if threaded mode -- is enabled, as is the case in Tasty. This problem does not occur when -- running via Main.hs, if compiled as single threaded... For more info -- see the paper Extending the Haskell Foreign Function Interface with -- Concurrency quickjsMultithreaded :: MonadUnliftIO m => ReaderT (Ptr JSContext) m b -> m b call :: (MonadMask m, MonadReader JSContextPtr m, MonadIO m) => ByteString -> [JSValue] -> m Value -- | Evaluates the given string and returns a Value (if the result -- can be converted). eval :: (MonadMask m, MonadReader JSContextPtr m, MonadIO m) => ByteString -> m Value -- | More efficient than eval if we don't care about the value of -- the expression, e.g. if we are evaluating a function definition or -- performing other side-effects such as printing to console/modifying -- state. eval_ :: (MonadThrow m, MonadReader JSContextPtr m, MonadIO m) => ByteString -> m () -- | Takes a value with a defined ToJSON instance. This value is -- marshalled to a JSValue and passed as an argument to the -- callback function, provided as the second argument to -- withJSValue withJSValue :: (MonadMask m, MonadReader JSContextPtr m, MonadIO m, ToJSON a) => a -> (JSValue -> m b) -> m b fromJSValue_ :: (MonadCatch m, MonadReader JSContextPtr m, MonadIO m) => JSValue -> m Value