javascriptcore.context

Module for [Context] class

Types 8

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 javascriptcore.context.Context.evaluate or javascriptcore.context.Context.evaluateWithSourceUri. It's also possible to register custom objects in the context with javascriptcore.context.Context.registerClass.

Fields
private Class[TypeInfo] classRegistry
private TypeInfo[string] classNameToType
Methods
GType _getGType() static nothrow
GType _gType() @property nothrow
Context self() nothrowReturns `this`, for use in `with` statements.
ContextGidBuilder builder() static nothrowGet builder for [javascriptcore.context.Context] Returns: New builder object
javascriptcore.virtual_machine.VirtualMachine virtualMachine() @property nothrowGet `virtualMachine` property. Returns: The #JSCVirtualMachine in which the context was created.
void registerFunction(T)(string name, T callback) nothrowRegister a D function/delegate as a JavaScript function.
void registerFunction(alias Func)() if (isFunction!Func) nothrowRegister with automatic name from the function symbol. Only works with function pointers/aliases, not runtime delegates.
Class registerClass(alias DClass, RegisterClassMode Mode = RegisterClassMode.UdaOnly)(string className = null) nothrowRegister a D class to a JSC Context.
Class getClass(T)() nothrowTemplate to get a JSC Class from a context. Params: T = The class type Returns: The JSC Class or null if none registered for the given D class type
Class getClass(string name) nothrowTemplate to get a JSC Class from a context by the name that it was registered with (the same as the D class name if not specified on registration). Params: name = The name of the JSC Class that was...
javascriptcore.context.Context newWithVirtualMachine(javascriptcore.virtual_machine.VirtualMachine vm) static nothrowCreate a new #JSCContext in virtual_machine.
javascriptcore.context.Context getCurrent() static nothrowGet the #JSCContext that is currently executing a function. This should only be called within a function or method callback, otherwise null will be returned. Returns: the #JSCContext that is curren...
javascriptcore.types.CheckSyntaxResult checkSyntax(string code, javascriptcore.types.CheckSyntaxMode mode, string uri, uint lineNumber, out javascriptcore.exception.ExceptionWrap exception) nothrowCheck the given code in context for syntax errors. The line_number is the starting line number in uri; the value is one-based so the first line is 1. uri and line_number are only used to fill the e...
void clearException() nothrowClear the uncaught exception in context if any.
javascriptcore.value.Value evaluate(string code) nothrowEvaluate code in context.
javascriptcore.value.Value evaluateInObject(string code, void * objectInstance, javascriptcore.class_.Class objectClass, string uri, uint lineNumber, out javascriptcore.value.Value object) nothrowEvaluate 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. Si...
javascriptcore.value.Value evaluateWithSourceUri(string code, string uri, uint lineNumber) nothrowEvaluate code in context using uri as the source URI. The line_number is the starting line number in uri; the value is one-based so the first line is 1. uri and line_number will be shown in excepti...
javascriptcore.exception.ExceptionWrap getException() nothrowGet the last unhandled exception thrown in context by API functions calls. Returns: a #JSCException or null if there isn't any unhandled exception in the #JSCContext.
javascriptcore.value.Value getGlobalObject() nothrowGet a #JSCValue referencing the context global object Returns: a #JSCValue
javascriptcore.value.Value getValue(string name) nothrowGet a property of context global object with name.
javascriptcore.virtual_machine.VirtualMachine getVirtualMachine() nothrowGet the #JSCVirtualMachine where context was created. Returns: the #JSCVirtualMachine where the #JSCContext was created.
void popExceptionHandler() nothrowRemove the last #JSCExceptionHandler previously pushed to context with [javascriptcore.context.Context.pushExceptionHandler].
void pushExceptionHandler(javascriptcore.types.ExceptionHandler handler) nothrowPush an exception handler in context. Whenever a JavaScript exception happens in the #JSCContext, the given handler will be called. The default #JSCExceptionHandler simply calls [javascriptcore.con...
javascriptcore.class_.Class registerClass(string name, javascriptcore.class_.Class parentClass, javascriptcore.types.ClassVTable vtable, glib.types.DestroyNotify destroyNotify = null) nothrowRegister a custom class in context using the given name. If the new class inherits from another #JSCClass, the parent should be passed as parent_class, otherwise null should be used. The optional v...
void setValue(string name, javascriptcore.value.Value value) nothrowSet a property of context global object with name and value.
void throw_(string errorMessage) nothrowThrow an exception to context using the given error message. The created #JSCException can be retrieved with [javascriptcore.context.Context.getException].
void throwException(javascriptcore.exception.ExceptionWrap exception) nothrowThrow exception to context.
void throwWithName(string errorName, string errorMessage) nothrowThrow an exception to context using the given error name and message. The created #JSCException can be retrieved with [javascriptcore.context.Context.getException].
Constructors
this(void * ptr, Flag!"Take" take)
this()Create a new #JSCContext. The context is created in a new #JSCVirtualMachine. Use [javascriptcore.context.Context.newWithVirtualMachine] to create a new #JSCContext in an existing #JSCVirtualMachin...
Nested Templates
getUDAName(alias Member, string defaultName)
findBestConstructor(alias DClass)
FindBestCtor(alias DClass)
isMethodExposable(alias Method, RegisterClassMode Mode)
PropertyPair(alias DClass, string propName, RegisterClassMode Mode)

Fluent builder implementation template for javascriptcore.context.Context

Methods
T virtualMachine(javascriptcore.virtual_machine.VirtualMachine propval) nothrowSet `virtualMachine` property. Params: propval = The #JSCVirtualMachine in which the context was created. Returns: Builder instance for fluent chaining
Methods
Context build() nothrowCreate object from builder. Returns: New object

Value used with registerClass template

UdaOnlyOnly add methods and members which are marked with @JsExpose
FullBind all public methods and public members as properties, first method which returns an instance is used (or the one marked @JsCtor)
ManualDon't do any automatic class registration, leaving it up to the caller to do all that

Attribute to mark a constructor method

structJsExpose

Attribute to mark a method or member variable (property) for exposing to javascriptcore

structJsName

Attribute to set the name of a method or member variable property

Fields
string name

Attribute to set a member variable property as read-only