jsaddle-0.9.7.0: Interface for JavaScript that works with GHCJS and GHC

Safe HaskellNone
LanguageHaskell2010

Language.Javascript.JSaddle.Value

Contents

Description

Deals with JavaScript values. These can be

  • null
  • undefined
  • true | false
  • a double precision floating point number
  • a string
  • an object
Synopsis

JavaScript value references

data JSVal Source #

Instances
NFData JSVal Source # 
Instance details

Defined in GHCJS.Prim.Internal

Methods

rnf :: JSVal -> () #

MakeArgs JSVal Source #

A single JSVal can be used as the argument list

Instance details

Defined in Language.Javascript.JSaddle.Value

Methods

makeArgs :: JSVal -> JSM [JSVal] Source #

MakeArgs JSCallAsFunction Source # 
Instance details

Defined in Language.Javascript.JSaddle.Object

MakeObject JSVal Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

FromJSVal JSVal Source # 
Instance details

Defined in GHCJS.Marshal

ToJSVal JSVal Source #

If we already have a JSVal we are fine

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal JSCallAsFunction Source #

A callback to Haskell can be used as a JavaScript value. This will create an anonymous JavaScript function object. Use function to create one with a name.

Instance details

Defined in Language.Javascript.JSaddle.Object

PFromJSVal JSVal Source # 
Instance details

Defined in GHCJS.Marshal.Pure

PToJSVal JSVal Source # 
Instance details

Defined in GHCJS.Marshal.Pure

Methods

pToJSVal :: JSVal -> JSVal Source #

class ToJSVal a where Source #

Minimal complete definition

Nothing

Methods

toJSVal :: a -> JSM JSVal Source #

toJSValListOf :: [a] -> JSM JSVal Source #

toJSVal :: (Generic a, GToJSVal (Rep a ())) => a -> JSM JSVal Source #

Instances
ToJSVal Bool Source #

Make a JavaScript boolean value

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Char Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Double Source #

Makes a JavaScript number

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Float Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Int Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Int8 Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Int16 Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Int32 Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Word Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Word8 Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Word16 Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Word32 Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Text Source #

Makes a JavaScript string

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Value Source #

Makes a JSON value

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal JSString Source #

Makes a JavaScript string

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal JSVal Source #

If we already have a JSVal we are fine

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Object Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal JSCallAsFunction Source #

A callback to Haskell can be used as a JavaScript value. This will create an anonymous JavaScript function object. Use function to create one with a name.

Instance details

Defined in Language.Javascript.JSaddle.Object

ToJSVal JSValue Source #

Makes a JavaScript value from a JSValue ADT.

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal JSUndefined Source #

Makes an undefined JavaScript value

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal JSNull Source #

Makes a null JavaScript value

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal Function Source # 
Instance details

Defined in Language.Javascript.JSaddle.Object

ToJSVal a => ToJSVal [a] Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

Methods

toJSVal :: [a] -> JSM JSVal Source #

toJSValListOf :: [[a]] -> JSM JSVal Source #

ToJSVal a => ToJSVal (Maybe a) Source #

Makes a JSVal or null JavaScript value

Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal v => ToJSVal (JSM v) Source #

JSVal can be made by evaluating a function in JSM as long as it returns something we can make into a JSVal.

Instance details

Defined in Language.Javascript.JSaddle.Value

(ToJSVal a, ToJSVal b) => ToJSVal (a, b) Source # 
Instance details

Defined in GHCJS.Marshal

Methods

toJSVal :: (a, b) -> JSM JSVal Source #

toJSValListOf :: [(a, b)] -> JSM JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c) => ToJSVal (a, b, c) Source # 
Instance details

Defined in GHCJS.Marshal

Methods

toJSVal :: (a, b, c) -> JSM JSVal Source #

toJSValListOf :: [(a, b, c)] -> JSM JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d) => ToJSVal (a, b, c, d) Source # 
Instance details

Defined in GHCJS.Marshal

Methods

toJSVal :: (a, b, c, d) -> JSM JSVal Source #

toJSValListOf :: [(a, b, c, d)] -> JSM JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d, ToJSVal e) => ToJSVal (a, b, c, d, e) Source # 
Instance details

Defined in GHCJS.Marshal

Methods

toJSVal :: (a, b, c, d, e) -> JSM JSVal Source #

toJSValListOf :: [(a, b, c, d, e)] -> JSM JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d, ToJSVal e, ToJSVal f) => ToJSVal (a, b, c, d, e, f) Source # 
Instance details

Defined in GHCJS.Marshal

Methods

toJSVal :: (a, b, c, d, e, f) -> JSM JSVal Source #

toJSValListOf :: [(a, b, c, d, e, f)] -> JSM JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d, ToJSVal e, ToJSVal f, ToJSVal g) => ToJSVal (a, b, c, d, e, f, g) Source # 
Instance details

Defined in GHCJS.Marshal

Methods

toJSVal :: (a, b, c, d, e, f, g) -> JSM JSVal Source #

toJSValListOf :: [(a, b, c, d, e, f, g)] -> JSM JSVal Source #

Haskell types for JavaScript values

data JSNull Source #

Constructors

JSNull

Type that represents a value that can only be null. Haskell of course has no null so we are adding this type.

Instances
MakeArgs JSNull Source #

Makes an argument list with just a single null JavaScript value

Instance details

Defined in Language.Javascript.JSaddle.Value

Methods

makeArgs :: JSNull -> JSM [JSVal] Source #

ToJSVal JSNull Source #

Makes a null JavaScript value

Instance details

Defined in Language.Javascript.JSaddle.Value

type JSUndefined Source #

Arguments

 = ()

A type that can only be undefined in JavaScript. Using () because functions in JavaScript that have no return, impicitly return undefined. type JSBool = Bool -- ^ JavaScript boolean values map the Bool haskell type. type JSNumber = Double -- ^ A number in JavaScript maps nicely to Double. type JSString = Text -- ^ JavaScript strings can be represented with the Haskell Text type.

data JSString Source #

A wrapper around a JavaScript string

Instances
IsList JSString Source # 
Instance details

Defined in Data.JSString

Associated Types

type Item JSString :: Type #

Eq JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

Data JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> JSString -> c JSString #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c JSString #

toConstr :: JSString -> Constr #

dataTypeOf :: JSString -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c JSString) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c JSString) #

gmapT :: (forall b. Data b => b -> b) -> JSString -> JSString #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> JSString -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> JSString -> r #

gmapQ :: (forall d. Data d => d -> u) -> JSString -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> JSString -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> JSString -> m JSString #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> JSString -> m JSString #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> JSString -> m JSString #

Ord JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

Read JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

Show JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

IsString JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

Semigroup JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

Monoid JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

ToJSON JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

FromJSON JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

NFData JSString Source # 
Instance details

Defined in Data.JSString.Internal.Type

Methods

rnf :: JSString -> () #

IsJSVal JSString Source # 
Instance details

Defined in GHCJS.Internal.Types

FromJSVal JSString Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSVal JSString Source #

Makes a JavaScript string

Instance details

Defined in Language.Javascript.JSaddle.Value

FromJSString JSString Source # 
Instance details

Defined in Language.Javascript.JSaddle.Value

ToJSString JSString Source #

If we already have a JSString we are fine

Instance details

Defined in Language.Javascript.JSaddle.Value

type Item JSString Source # 
Instance details

Defined in Data.JSString

data JSValue Source #

An algebraic data type that can represent a JavaScript value. Any JavaScriptCore JSVal can be converted into this type.

Constructors

ValNull

null

ValUndefined

undefined

ValBool Bool

true or false

ValNumber Double

a number

ValString Text

a string

ValObject Object

an object

Instances
MakeArgs JSValue Source #

Makes an argument list with just a single JavaScript value from a JSValue ADT.

Instance details

Defined in Language.Javascript.JSaddle.Value

Methods

makeArgs :: JSValue -> JSM [JSVal] Source #

ToJSVal JSValue Source #

Makes a JavaScript value from a JSValue ADT.

Instance details

Defined in Language.Javascript.JSaddle.Value

showJSValue :: JSValue -> String Source #

Show a JSValue but just say "object" if the value is a JavaScript object.

Converting JavaScript values

valToBool :: ToJSVal value => value -> JSM Bool Source #

Given a JavaScript value get its boolean value. All values in JavaScript convert to bool.

>>> testJSaddle $ valToBool JSNull
false
>>> testJSaddle $ valToBool ()
false
>>> testJSaddle $ valToBool True
true
>>> testJSaddle $ valToBool False
false
>>> testJSaddle $ valToBool (1.0 :: Double)
true
>>> testJSaddle $ valToBool (0.0 :: Double)
false
>>> testJSaddle $ valToBool ""
false
>>> testJSaddle $ valToBool "1"
true

valToNumber :: ToJSVal value => value -> JSM Double Source #

Given a JavaScript value get its numeric value. May throw JSException.

>>> testJSaddle $ show <$> valToNumber JSNull
0.0
>>> testJSaddle $ show <$> valToNumber ()
NaN
>>> testJSaddle $ show <$> valToNumber True
1.0
>>> testJSaddle $ show <$> valToNumber False
0.0
>>> testJSaddle $ show <$> valToNumber (1.0 :: Double)
1.0
>>> testJSaddle $ show <$> valToNumber (0.0 :: Double)
0.0
>>> testJSaddle $ show <$> valToNumber ""
0.0
>>> testJSaddle $ show <$> valToNumber "1"
1.0

valToStr :: ToJSVal value => value -> JSM JSString Source #

Given a JavaScript value get its string value (as a JavaScript string). May throw JSException.

>>> testJSaddle $ strToText <$> valToStr JSNull
null
>>> testJSaddle $ strToText <$> valToStr ()
undefined
>>> testJSaddle $ strToText <$> valToStr True
true
>>> testJSaddle $ strToText <$> valToStr False
false
>>> testJSaddle $ strToText <$> valToStr (1.0 :: Double)
1
>>> testJSaddle $ strToText <$> valToStr (0.0 :: Double)
0
>>> testJSaddle $ strToText <$> valToStr ""

>>> testJSaddle $ strToText <$> valToStr "1"
1

valToObject :: ToJSVal value => value -> JSM Object Source #

Given a JavaScript value get its object value. May throw JSException.

>>> testJSaddle $ (valToObject JSNull >>= valToText) `catch` \ (JSException e) -> valToText e
null
>>> testJSaddle $ (valToObject () >>= valToText) `catch` \ (JSException e) -> valToText e
undefined
>>> testJSaddle $ valToObject True
true
>>> testJSaddle $ valToObject False
false
>>> testJSaddle $ valToObject (1.0 :: Double)
1
>>> testJSaddle $ valToObject (0.0 :: Double)
0
>>> testJSaddle $ valToObject ""

>>> testJSaddle $ valToObject "1"
1

valToText :: ToJSVal value => value -> JSM Text Source #

Given a JavaScript value get its string value (as a Haskell Text). May throw JSException.

>>> testJSaddle $ show <$> valToText JSNull
"null"
>>> testJSaddle $ show <$> valToText ()
"undefined"
>>> testJSaddle $ show <$> valToText True
"true"
>>> testJSaddle $ show <$> valToText False
"false"
>>> testJSaddle $ show <$> valToText (1.0 :: Double)
"1"
>>> testJSaddle $ show <$> valToText (0.0 :: Double)
"0"
>>> testJSaddle $ show <$> valToText ""
""
>>> testJSaddle $ show <$> valToText "1"
"1"

valToJSON :: ToJSVal value => value -> JSM JSString Source #

Given a JavaScript value get a JSON string value. May throw JSException.

>>> testJSaddle $ strToText <$> valToJSON JSNull
null
>>> testJSaddle $ strToText <$> valToJSON ()

>>> testJSaddle $ strToText <$> valToJSON True
true
>>> testJSaddle $ strToText <$> valToJSON False
false
>>> testJSaddle $ strToText <$> valToJSON (1.0 :: Double)
1
>>> testJSaddle $ strToText <$> valToJSON (0.0 :: Double)
0
>>> testJSaddle $ strToText <$> valToJSON ""
""
>>> testJSaddle $ strToText <$> valToJSON "1"
"1"
>>> testJSaddle $ strToText <$> (obj >>= valToJSON)
{}

Make JavaScript values from Haskell ones

val Source #

Arguments

:: ToJSVal value 
=> value

value to convert to a JavaScript value

-> JSM JSVal 

Convert to a JavaScript value (just an alias for toJSVal)

valNull :: JSVal Source #

A null JavaScript value

valIsNull :: ToJSVal value => value -> JSM Bool Source #

Test a JavaScript value to see if it is null

valUndefined :: JSVal Source #

An undefined JavaScript value

valIsUndefined :: ToJSVal value => value -> JSM Bool Source #

Test a JavaScript value to see if it is undefined

maybeNullOrUndefined :: ToJSVal value => value -> JSM (Maybe JSVal) Source #

Convert a JSVal to a Maybe JSVal (converting null and undefined to Nothing)

maybeNullOrUndefined' :: ToJSVal value => (JSVal -> JSM a) -> value -> JSM (Maybe a) Source #

valBool :: Bool -> JSVal Source #

A JavaScript boolean value

valMakeNumber :: Double -> JSM JSVal Source #

Make a JavaScript number

valMakeString :: JSString -> JSM JSVal Source #

Make a JavaScript string from JSString

valMakeText :: Text -> JSM JSVal Source #

Make a JavaScript string from Text

valMakeJSON :: Value -> JSM JSVal Source #

Make a JavaScript string from AESON Value

Convert to and from JSValue

deRefVal :: ToJSVal value => value -> JSM JSValue Source #

Derefernce a value reference.

>>> testJSaddle $ showJSValue <$> deRefVal JSNull
null
>>> testJSaddle $ showJSValue <$> deRefVal ()
undefined
>>> testJSaddle $ showJSValue <$> deRefVal True
true
>>> testJSaddle $ showJSValue <$> deRefVal False
false
>>> testJSaddle $ showJSValue <$> deRefVal (1.0 :: Double)
1.0
>>> testJSaddle $ showJSValue <$> deRefVal (0.0 :: Double)
0.0
>>> testJSaddle $ showJSValue <$> deRefVal ""
""
>>> testJSaddle $ showJSValue <$> deRefVal "1"
"1"
>>> testJSaddle $ showJSValue <$> (valToObject True >>= deRefVal)
true
>>> testJSaddle $ showJSValue <$> (obj >>= deRefVal)
object

valMakeRef :: JSValue -> JSM JSVal Source #

Make a JavaScript value out of a JSValue ADT.

>>> testJSaddle $ valMakeRef ValNull
null
>>> testJSaddle $ valMakeRef ValUndefined
undefined
>>> testJSaddle $ valMakeRef (ValBool True)
true
>>> testJSaddle $ valMakeRef (ValNumber 1)
1
>>> testJSaddle $ valMakeRef (ValString $ T.pack "Hello")
Hello

strictEqual :: (ToJSVal a, ToJSVal b) => a -> b -> JSM Bool Source #

Determine if two values are equal (JavaScripts ===) >>> testJSaddle $ strictEqual True False false >>> testJSaddle $ strictEqual True True true >>> testJSaddle $ strictEqual Hello () false >>> testJSaddle $ strictEqual Hello Hello true

instanceOf :: (ToJSVal value, MakeObject constructor) => value -> constructor -> JSM Bool Source #

Determine if two values are equal (JavaScripts ===) >>> testJSaddle $ instanceOf obj (Object $ jsg Object) true

Orphan instances

MakeArgs Bool Source #

Makes an argument list with just a single JavaScript boolean value

Instance details

Methods

makeArgs :: Bool -> JSM [JSVal] Source #

MakeArgs Double Source #

Makes an argument list with just a single JavaScript number

Instance details

Methods

makeArgs :: Double -> JSM [JSVal] Source #

MakeArgs () Source #

This allows us to pass no arguments easily (altenative would be to use []::[JSVal]).

Instance details

Methods

makeArgs :: () -> JSM [JSVal] Source #

MakeArgs Text Source #

Makes an argument list with just a single JavaScript string

Instance details

Methods

makeArgs :: Text -> JSM [JSVal] Source #

MakeArgs Value Source #

Makes an argument list with just a single JSON value

Instance details

Methods

makeArgs :: Value -> JSM [JSVal] Source #

MakeArgs JSVal Source #

A single JSVal can be used as the argument list

Instance details

Methods

makeArgs :: JSVal -> JSM [JSVal] Source #

MakeObject JSVal Source # 
Instance details

FromJSVal Char Source # 
Instance details

FromJSVal Text Source # 
Instance details

FromJSVal JSString Source # 
Instance details

ToJSVal Bool Source #

Make a JavaScript boolean value

Instance details

ToJSVal Char Source # 
Instance details

ToJSVal Double Source #

Makes a JavaScript number

Instance details

ToJSVal Float Source # 
Instance details

ToJSVal Int Source # 
Instance details

ToJSVal Int8 Source # 
Instance details

ToJSVal Int16 Source # 
Instance details

ToJSVal Int32 Source # 
Instance details

ToJSVal Word Source # 
Instance details

ToJSVal Word8 Source # 
Instance details

ToJSVal Word16 Source # 
Instance details

ToJSVal Word32 Source # 
Instance details

ToJSVal Text Source #

Makes a JavaScript string

Instance details

ToJSVal Value Source #

Makes a JSON value

Instance details

ToJSVal JSString Source #

Makes a JavaScript string

Instance details

ToJSVal JSVal Source #

If we already have a JSVal we are fine

Instance details

ToJSVal Object Source # 
Instance details

ToJSVal JSUndefined Source #

Makes an undefined JavaScript value

Instance details

FromJSString Text Source # 
Instance details

FromJSString String Source # 
Instance details

FromJSString JSString Source # 
Instance details

ToJSString Text Source # 
Instance details

ToJSString String Source # 
Instance details

ToJSString JSString Source #

If we already have a JSString we are fine

Instance details

FromJSVal a => FromJSVal [a] Source # 
Instance details

FromJSVal a => FromJSVal (Maybe a) Source # 
Instance details

ToJSVal a => ToJSVal [a] Source # 
Instance details

Methods

toJSVal :: [a] -> JSM JSVal Source #

toJSValListOf :: [[a]] -> JSM JSVal Source #

ToJSVal a => ToJSVal (Maybe a) Source #

Makes a JSVal or null JavaScript value

Instance details

ToJSVal v => ToJSVal (JSM v) Source #

JSVal can be made by evaluating a function in JSM as long as it returns something we can make into a JSVal.

Instance details