Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
JSCContext represents a JavaScript execution context, where all operations take place and where the values will be associated.
When a new context is created, a global object is allocated and the built-in JavaScript
objects (Object, Function, String, Array) are populated. You can execute JavaScript in
the context by using contextEvaluate
or contextEvaluateWithSourceUri
.
It's also possible to register custom objects in the context with contextRegisterClass
.
Synopsis
- newtype Context = Context (ManagedPtr Context)
- class (GObject o, IsDescendantOf Context o) => IsContext o
- toContext :: (MonadIO m, IsContext o) => o -> m Context
- contextCheckSyntax :: (HasCallStack, MonadIO m, IsContext a) => a -> Text -> Int64 -> CheckSyntaxMode -> Text -> Word32 -> m (CheckSyntaxResult, Exception)
- contextClearException :: (HasCallStack, MonadIO m, IsContext a) => a -> m ()
- contextEvaluate :: (HasCallStack, MonadIO m, IsContext a) => a -> Text -> Int64 -> m Value
- contextEvaluateInObject :: (HasCallStack, MonadIO m, IsContext a, IsClass b) => a -> Text -> Int64 -> Ptr () -> Maybe b -> Text -> Word32 -> m (Value, Value)
- contextEvaluateWithSourceUri :: (HasCallStack, MonadIO m, IsContext a) => a -> Text -> Int64 -> Text -> Word32 -> m Value
- contextGetCurrent :: (HasCallStack, MonadIO m) => m (Maybe Context)
- contextGetException :: (HasCallStack, MonadIO m, IsContext a) => a -> m (Maybe Exception)
- contextGetGlobalObject :: (HasCallStack, MonadIO m, IsContext a) => a -> m Value
- contextGetValue :: (HasCallStack, MonadIO m, IsContext a) => a -> Text -> m Value
- contextGetVirtualMachine :: (HasCallStack, MonadIO m, IsContext a) => a -> m VirtualMachine
- contextNew :: (HasCallStack, MonadIO m) => m Context
- contextNewWithVirtualMachine :: (HasCallStack, MonadIO m, IsVirtualMachine a) => a -> m Context
- contextPopExceptionHandler :: (HasCallStack, MonadIO m, IsContext a) => a -> m ()
- contextPushExceptionHandler :: (HasCallStack, MonadIO m, IsContext a) => a -> ExceptionHandler -> m ()
- contextRegisterClass :: (HasCallStack, MonadIO m, IsContext a, IsClass b) => a -> Text -> Maybe b -> Maybe ClassVTable -> Maybe DestroyNotify -> m Class
- contextSetValue :: (HasCallStack, MonadIO m, IsContext a, IsValue b) => a -> Text -> b -> m ()
- contextThrow :: (HasCallStack, MonadIO m, IsContext a) => a -> Text -> m ()
- contextThrowException :: (HasCallStack, MonadIO m, IsContext a, IsException b) => a -> b -> m ()
- contextThrowWithName :: (HasCallStack, MonadIO m, IsContext a) => a -> Text -> Text -> m ()
- constructContextVirtualMachine :: (IsContext o, MonadIO m, IsVirtualMachine a) => a -> m (GValueConstruct o)
- getContextVirtualMachine :: (MonadIO m, IsContext o) => o -> m VirtualMachine
Exported types
Memory-managed wrapper type.
Instances
Eq Context Source # | |
GObject Context Source # | |
Defined in GI.JavaScriptCore.Objects.Context | |
ManagedPtrNewtype Context Source # | |
Defined in GI.JavaScriptCore.Objects.Context toManagedPtr :: Context -> ManagedPtr Context | |
TypedObject Context Source # | |
Defined in GI.JavaScriptCore.Objects.Context | |
HasParentTypes Context Source # | |
Defined in GI.JavaScriptCore.Objects.Context | |
IsGValue (Maybe Context) Source # | Convert |
Defined in GI.JavaScriptCore.Objects.Context gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe Context -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe Context) | |
type ParentTypes Context Source # | |
Defined in GI.JavaScriptCore.Objects.Context type ParentTypes Context = '[Object] |
class (GObject o, IsDescendantOf Context o) => IsContext o Source #
Instances
(GObject o, IsDescendantOf Context o) => IsContext o Source # | |
Defined in GI.JavaScriptCore.Objects.Context |
Methods
Click to display all available methods, including inherited ones
Methods
bindProperty, bindPropertyFull, checkSyntax, clearException, evaluate, evaluateInObject, evaluateWithSourceUri, forceFloating, freezeNotify, getv, isFloating, notify, notifyByPspec, popExceptionHandler, pushExceptionHandler, ref, refSink, registerClass, runDispose, stealData, stealQdata, thawNotify, throw, throwException, throwWithName, unref, watchClosure.
Getters
getData, getException, getGlobalObject, getProperty, getQdata, getValue, getVirtualMachine.
Setters
checkSyntax
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> Text |
|
-> Int64 |
|
-> CheckSyntaxMode |
|
-> Text |
|
-> Word32 |
|
-> m (CheckSyntaxResult, Exception) | Returns: a |
Check the given code
in context
for syntax errors. The lineNumber
is the starting line number in uri
;
the value is one-based so the first line is 1. uri
and lineNumber
are only used to fill the exception
.
In case of errors exception
will be set to a new Exception
with the details. You can pass Nothing
to
exception
to ignore the error details.
clearException
contextClearException Source #
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> m () |
Clear the uncaught exception in context
if any.
evaluate
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> Text |
|
-> Int64 |
|
-> m Value | Returns: a |
Evaluate code
in context
.
evaluateInObject
contextEvaluateInObject Source #
:: (HasCallStack, MonadIO m, IsContext a, IsClass b) | |
=> a |
|
-> Text |
|
-> Int64 |
|
-> Ptr () |
|
-> Maybe b | |
-> Text |
|
-> Word32 |
|
-> m (Value, Value) | Returns: a |
Evaluate code
and create an new object where symbols defined in code
will be added as properties,
instead of being added to context
global object. The new object is returned as object
parameter.
Similar to how valueNewObject
works, if objectInstance
is not Nothing
objectClass
must be provided too.
The lineNumber
is the starting line number in uri
; the value is one-based so the first line is 1.
uri
and lineNumber
will be shown in exceptions and they don't affect the behavior of the script.
evaluateWithSourceUri
contextEvaluateWithSourceUri Source #
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> Text |
|
-> Int64 |
|
-> Text |
|
-> Word32 |
|
-> m Value | Returns: a |
Evaluate code
in context
using uri
as the source URI. The lineNumber
is the starting line number
in uri
; the value is one-based so the first line is 1. uri
and lineNumber
will be shown in exceptions and
they don't affect the behavior of the script.
getCurrent
:: (HasCallStack, MonadIO m) | |
=> m (Maybe Context) | Returns: the |
getException
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> m (Maybe Exception) | Returns: a |
Get the last unhandled exception thrown in context
by API functions calls.
getGlobalObject
contextGetGlobalObject Source #
Get a Value
referencing the context
global object
getValue
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> Text |
|
-> m Value | Returns: a |
Get a property of context
global object with name
.
getVirtualMachine
contextGetVirtualMachine Source #
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> m VirtualMachine | Returns: the |
Get the VirtualMachine
where context
was created.
new
:: (HasCallStack, MonadIO m) | |
=> m Context | Returns: the newly created |
Create a new Context
. The context is created in a new VirtualMachine
.
Use contextNewWithVirtualMachine
to create a new Context
in an
existing VirtualMachine
.
newWithVirtualMachine
contextNewWithVirtualMachine Source #
:: (HasCallStack, MonadIO m, IsVirtualMachine a) | |
=> a |
|
-> m Context | Returns: the newly created |
Create a new Context
in virtualMachine
.
popExceptionHandler
contextPopExceptionHandler Source #
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> m () |
Remove the last ExceptionHandler
previously pushed to context
with
contextPushExceptionHandler
.
pushExceptionHandler
contextPushExceptionHandler Source #
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> ExceptionHandler |
|
-> m () |
Push an exception handler in context
. Whenever a JavaScript exception happens in
the Context
, the given handler
will be called. The default ExceptionHandler
simply calls contextThrowException
to throw the exception to the Context
.
If you don't want to catch the exception, but only get notified about it, call
contextThrowException
in handler
like the default one does.
The last exception handler pushed is the only one used by the Context
, use
contextPopExceptionHandler
to remove it and set the previous one. When handler
is removed from the context, destroyNotify
i called with userData
as parameter.
registerClass
:: (HasCallStack, MonadIO m, IsContext a, IsClass b) | |
=> a |
|
-> Text |
|
-> Maybe b | |
-> Maybe ClassVTable |
|
-> Maybe DestroyNotify |
|
-> m Class | Returns: a |
Register a custom class in context
using the given name
. If the new class inherits from
another Class
, the parent should be passed as parentClass
, otherwise Nothing
should be
used. The optional vtable
parameter allows to provide a custom implementation for handling
the class, for example, to handle external properties not added to the prototype.
When an instance of the Class
is cleared in the context, destroyNotify
is called with
the instance as parameter.
setValue
:: (HasCallStack, MonadIO m, IsContext a, IsValue b) | |
=> a |
|
-> Text |
|
-> b |
|
-> m () |
Set a property of context
global object with name
and value
.
throw
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> Text |
|
-> m () |
Throw an exception to context
using the given error message. The created Exception
can be retrieved with contextGetException
.
throwException
contextThrowException Source #
:: (HasCallStack, MonadIO m, IsContext a, IsException b) | |
=> a |
|
-> b |
|
-> m () |
Throw exception
to context
.
throwWithName
:: (HasCallStack, MonadIO m, IsContext a) | |
=> a |
|
-> Text |
|
-> Text |
|
-> m () |
Throw an exception to context
using the given error name and message. The created Exception
can be retrieved with contextGetException
.
Properties
virtualMachine
The VirtualMachine
in which the context was created.
constructContextVirtualMachine :: (IsContext o, MonadIO m, IsVirtualMachine a) => a -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “virtual-machine
” property. This is rarely needed directly, but it is used by new
.
getContextVirtualMachine :: (MonadIO m, IsContext o) => o -> m VirtualMachine Source #
Get the value of the “virtual-machine
” property.
When overloading is enabled, this is equivalent to
get
context #virtualMachine