Documentation ¶
Index ¶
- Constants
- Variables
- func GetMajorVersion() uint
- func GetMicroVersion() uint
- func GetMinorVersion() uint
- func OptionsForEach(function OptionsFunc)
- func OptionsGetBoolean(option string) (value, ok bool)
- func OptionsGetDouble(option string) (float64, bool)
- func OptionsGetInt(option string) (int, bool)
- func OptionsGetOptionGroup() *glib.OptionGroup
- func OptionsGetRangeString(option string) (string, bool)
- func OptionsGetSize(option string) (uint, bool)
- func OptionsGetString(option string) (string, bool)
- func OptionsGetUint(option string) (uint, bool)
- func OptionsSetBoolean(option string, value bool) bool
- func OptionsSetDouble(option string, value float64) bool
- func OptionsSetInt(option string, value int) bool
- func OptionsSetRangeString(option, value string) bool
- func OptionsSetSize(option string, value uint) bool
- func OptionsSetString(option, value string) bool
- func OptionsSetUint(option string, value uint) bool
- type CheckSyntaxMode
- type CheckSyntaxResult
- type Class
- type ClassVTable
- type Context
- func (context *Context) CheckSyntax(code string, length int, mode CheckSyntaxMode, uri string, lineNumber uint) (*Exception, CheckSyntaxResult)
- func (context *Context) ClearException()
- func (context *Context) Evaluate(code string, length int) *Value
- func (context *Context) EvaluateInObject(code string, length int, objectInstance unsafe.Pointer, objectClass *Class, ...) (object, value *Value)
- func (context *Context) EvaluateWithSourceURI(code string, length int, uri string, lineNumber uint) *Value
- func (context *Context) Exception() *Exception
- func (context *Context) GlobalObject() *Value
- func (context *Context) PopExceptionHandler()
- func (context *Context) PushExceptionHandler(handler ExceptionHandler)
- func (context *Context) SetValue(name string, value *Value)
- func (context *Context) Throw(errorMessage string)
- func (context *Context) ThrowException(exception *Exception)
- func (context *Context) ThrowWithName(errorName, errorMessage string)
- func (context *Context) Value(name string) *Value
- func (context *Context) VirtualMachine() *VirtualMachine
- type ContextClass
- type ContextOverrides
- type Exception
- func (exception *Exception) BacktraceString() string
- func (exception *Exception) ColumnNumber() uint
- func (exception *Exception) LineNumber() uint
- func (exception *Exception) Message() string
- func (exception *Exception) Name() string
- func (exception *Exception) Report() string
- func (exception *Exception) SourceURI() string
- func (exception *Exception) String() string
- type ExceptionClass
- type ExceptionHandler
- type ExceptionOverrides
- type OptionType
- type OptionsFunc
- type TypedArrayType
- type Value
- func NewValueArrayFromStrv(context *Context, strv []string) *Value
- func NewValueBoolean(context *Context, value bool) *Value
- func NewValueFromJson(context *Context, json string) *Value
- func NewValueNull(context *Context) *Value
- func NewValueNumber(context *Context, number float64) *Value
- func NewValueObject(context *Context, instance unsafe.Pointer, jscClass *Class) *Value
- func NewValueString(context *Context, str string) *Value
- func NewValueStringFromBytes(context *Context, bytes *glib.Bytes) *Value
- func NewValueTypedArray(context *Context, typ TypedArrayType, length uint) *Value
- func NewValueUndefined(context *Context) *Value
- func (value *Value) ArrayBufferGetData(size *uint) unsafe.Pointer
- func (value *Value) ArrayBufferGetSize() uint
- func (value *Value) ConstructorCall(parameters []*Value) *Value
- func (value *Value) Context() *Context
- func (value *Value) FunctionCall(parameters []*Value) *Value
- func (value *Value) IsArray() bool
- func (value *Value) IsArrayBuffer() bool
- func (value *Value) IsBoolean() bool
- func (value *Value) IsConstructor() bool
- func (value *Value) IsFunction() bool
- func (value *Value) IsNull() bool
- func (value *Value) IsNumber() bool
- func (value *Value) IsObject() bool
- func (value *Value) IsString() bool
- func (value *Value) IsTypedArray() bool
- func (value *Value) IsUndefined() bool
- func (arrayBuffer *Value) NewTypedArrayWithBuffer(typ TypedArrayType, offset uint, length int) *Value
- func (value *Value) ObjectDefinePropertyData(propertyName string, flags ValuePropertyFlags, propertyValue *Value)
- func (value *Value) ObjectDeleteProperty(name string) bool
- func (value *Value) ObjectEnumerateProperties() []string
- func (value *Value) ObjectGetProperty(name string) *Value
- func (value *Value) ObjectGetPropertyAtIndex(index uint) *Value
- func (value *Value) ObjectHasProperty(name string) bool
- func (value *Value) ObjectInvokeMethod(name string, parameters []*Value) *Value
- func (value *Value) ObjectIsInstanceOf(name string) bool
- func (value *Value) ObjectSetProperty(name string, property *Value)
- func (value *Value) ObjectSetPropertyAtIndex(index uint, property *Value)
- func (value *Value) String() string
- func (value *Value) ToBoolean() bool
- func (value *Value) ToDouble() float64
- func (value *Value) ToInt32() int32
- func (value *Value) ToJson(indent uint) string
- func (value *Value) ToStringAsBytes() *glib.Bytes
- func (value *Value) TypedArrayGetBuffer() *Value
- func (value *Value) TypedArrayGetData() (uint, unsafe.Pointer)
- func (value *Value) TypedArrayGetLength() uint
- func (value *Value) TypedArrayGetOffset() uint
- func (value *Value) TypedArrayGetSize() uint
- func (value *Value) TypedArrayGetType() TypedArrayType
- type ValueClass
- type ValueOverrides
- type ValuePropertyFlags
- type VirtualMachine
- type VirtualMachineClass
- type VirtualMachineOverrides
- type WeakValue
- type WeakValueClass
- type WeakValueOverrides
Constants ¶
const MAJOR_VERSION = 2
MAJOR_VERSION: like jsc_get_major_version(), but from the headers used at application compile time, rather than from the library linked against at application run time.
const MICRO_VERSION = 4
MICRO_VERSION: like jsc_get_micro_version(), but from the headers used at application compile time, rather than from the library linked against at application run time.
const MINOR_VERSION = 42
MINOR_VERSION: like jsc_get_minor_version(), but from the headers used at application compile time, rather than from the library linked against at application run time.
const OPTIONS_USE_DFG = "useDFGJIT"
OPTIONS_USE_DFG allows the DFG JIT to be used if TRUE. Option type: JSC_OPTION_BOOLEAN Default value: TRUE.
const OPTIONS_USE_FTL = "useFTLJIT"
OPTIONS_USE_FTL allows the FTL JIT to be used if TRUE. Option type: JSC_OPTION_BOOLEAN Default value: TRUE.
const OPTIONS_USE_JIT = "useJIT"
OPTIONS_USE_JIT allows the executable pages to be allocated for JIT and thunks if TRUE. Option type: JSC_OPTION_BOOLEAN Default value: TRUE.
const OPTIONS_USE_LLINT = "useLLInt"
OPTIONS_USE_LLINT allows the LLINT to be used if TRUE. Option type: JSC_OPTION_BOOLEAN Default value: TRUE.
Variables ¶
var (
GTypeClass = coreglib.Type(C.jsc_class_get_type())
)
GType values.
var (
GTypeContext = coreglib.Type(C.jsc_context_get_type())
)
GType values.
var (
GTypeException = coreglib.Type(C.jsc_exception_get_type())
)
GType values.
var (
GTypeValue = coreglib.Type(C.jsc_value_get_type())
)
GType values.
var (
GTypeVirtualMachine = coreglib.Type(C.jsc_virtual_machine_get_type())
)
GType values.
var (
GTypeWeakValue = coreglib.Type(C.jsc_weak_value_get_type())
)
GType values.
Functions ¶
func GetMajorVersion ¶
func GetMajorVersion() uint
GetMajorVersion returns the major version number of the JavaScriptCore library. (e.g. in JavaScriptCore version 1.8.3 this is 1.)
This function is in the library, so it represents the JavaScriptCore library your code is running against. Contrast with the C_MAJOR_VERSION macro, which represents the major version of the JavaScriptCore headers you have included when compiling your code.
The function returns the following values:
- guint: major version number of the JavaScriptCore library.
func GetMicroVersion ¶
func GetMicroVersion() uint
GetMicroVersion returns the micro version number of the JavaScriptCore library. (e.g. in JavaScriptCore version 1.8.3 this is 3.)
This function is in the library, so it represents the JavaScriptCore library your code is running against. Contrast with the C_MICRO_VERSION macro, which represents the micro version of the JavaScriptCore headers you have included when compiling your code.
The function returns the following values:
- guint: micro version number of the JavaScriptCore library.
func GetMinorVersion ¶
func GetMinorVersion() uint
GetMinorVersion returns the minor version number of the JavaScriptCore library. (e.g. in JavaScriptCore version 1.8.3 this is 8.)
This function is in the library, so it represents the JavaScriptCore library your code is running against. Contrast with the C_MINOR_VERSION macro, which represents the minor version of the JavaScriptCore headers you have included when compiling your code.
The function returns the following values:
- guint: minor version number of the JavaScriptCore library.
func OptionsForEach ¶
func OptionsForEach(function OptionsFunc)
OptionsForEach iterates all available options calling function for each one. Iteration can stop early if function returns FALSE.
The function takes the following parameters:
- function: COptionsFunc callback.
func OptionsGetBoolean ¶
OptionsGetBoolean: get option as a #gboolean value.
The function takes the following parameters:
- option identifier.
The function returns the following values:
- value: return location for the option value.
- ok: TRUE if value has been set or FALSE if the option doesn't exist.
func OptionsGetDouble ¶
OptionsGetDouble: get option as a #gdouble value.
The function takes the following parameters:
- option identifier.
The function returns the following values:
- value: return location for the option value.
- ok: TRUE if value has been set or FALSE if the option doesn't exist.
func OptionsGetInt ¶
OptionsGetInt: get option as a #gint value.
The function takes the following parameters:
- option identifier.
The function returns the following values:
- value: return location for the option value.
- ok: TRUE if value has been set or FALSE if the option doesn't exist.
func OptionsGetOptionGroup ¶
func OptionsGetOptionGroup() *glib.OptionGroup
OptionsGetOptionGroup: create a Group to handle JSCOptions as command line arguments. The options will be exposed as command line arguments with the form <emphasis>--jsc-<option>=<value></emphasis>. Each entry in the returned Group is configured to apply the corresponding option during command line parsing. Applications only need to pass the returned group to g_option_context_add_group(), and the rest will be taken care for automatically.
The function returns the following values:
- optionGroup for the JSCOptions.
func OptionsGetRangeString ¶
OptionsGetRangeString: get option as a range string. The string must be in the format <emphasis>[!]<low>[:<high>]</emphasis> where low and high are #guint values. Values between low and high (both included) will be considered in the range, unless <emphasis>!</emphasis> is used to invert the range.
The function takes the following parameters:
- option identifier.
The function returns the following values:
- value: return location for the option value.
- ok: TRUE if value has been set or FALSE if the option doesn't exist.
func OptionsGetSize ¶
OptionsGetSize: get option as a #gsize value.
The function takes the following parameters:
- option identifier.
The function returns the following values:
- value: return location for the option value.
- ok: TRUE if value has been set or FALSE if the option doesn't exist.
func OptionsGetString ¶
OptionsGetString: get option as a string.
The function takes the following parameters:
- option identifier.
The function returns the following values:
- value: return location for the option value.
- ok: TRUE if value has been set or FALSE if the option doesn't exist.
func OptionsGetUint ¶
OptionsGetUint: get option as a #guint value.
The function takes the following parameters:
- option identifier.
The function returns the following values:
- value: return location for the option value.
- ok: TRUE if value has been set or FALSE if the option doesn't exist.
func OptionsSetBoolean ¶
OptionsSetBoolean: set option as a #gboolean value.
The function takes the following parameters:
- option identifier.
- value to set.
The function returns the following values:
- ok: TRUE if option was correctly set or FALSE otherwise.
func OptionsSetDouble ¶
OptionsSetDouble: set option as a #gdouble value.
The function takes the following parameters:
- option identifier.
- value to set.
The function returns the following values:
- ok: TRUE if option was correctly set or FALSE otherwise.
func OptionsSetInt ¶
OptionsSetInt: set option as a #gint value.
The function takes the following parameters:
- option identifier.
- value to set.
The function returns the following values:
- ok: TRUE if option was correctly set or FALSE otherwise.
func OptionsSetRangeString ¶
OptionsSetRangeString: set option as a range string. The string must be in the format <emphasis>[!]<low>[:<high>]</emphasis> where low and high are #guint values. Values between low and high (both included) will be considered in the range, unless <emphasis>!</emphasis> is used to invert the range.
The function takes the following parameters:
- option identifier.
- value to set.
The function returns the following values:
- ok: TRUE if option was correctly set or FALSE otherwise.
func OptionsSetSize ¶
OptionsSetSize: set option as a #gsize value.
The function takes the following parameters:
- option identifier.
- value to set.
The function returns the following values:
- ok: TRUE if option was correctly set or FALSE otherwise.
func OptionsSetString ¶
OptionsSetString: set option as a string.
The function takes the following parameters:
- option identifier.
- value to set.
The function returns the following values:
- ok: TRUE if option was correctly set or FALSE otherwise.
func OptionsSetUint ¶
OptionsSetUint: set option as a #guint value.
The function takes the following parameters:
- option identifier.
- value to set.
The function returns the following values:
- ok: TRUE if option was correctly set or FALSE otherwise.
Types ¶
type CheckSyntaxMode ¶
CheckSyntaxMode: enum values to specify a mode to check for syntax errors in jsc_context_check_syntax().
const ( // CheckSyntaxModeScript: mode to check syntax of a script. CheckSyntaxModeScript CheckSyntaxMode = iota // CheckSyntaxModeModule: mode to check syntax of a module. CheckSyntaxModeModule )
func (CheckSyntaxMode) String ¶
func (c CheckSyntaxMode) String() string
String returns the name in string for CheckSyntaxMode.
type CheckSyntaxResult ¶
CheckSyntaxResult: enum values to specify the result of jsc_context_check_syntax().
const ( // CheckSyntaxResultSuccess: no errors. CheckSyntaxResultSuccess CheckSyntaxResult = iota // CheckSyntaxResultRecoverableError: recoverable syntax error. CheckSyntaxResultRecoverableError // CheckSyntaxResultIrrecoverableError: irrecoverable syntax error. CheckSyntaxResultIrrecoverableError // CheckSyntaxResultUnterminatedLiteralError: unterminated literal error. CheckSyntaxResultUnterminatedLiteralError // CheckSyntaxResultOutOfMemoryError: out of memory error. CheckSyntaxResultOutOfMemoryError // CheckSyntaxResultStackOverflowError: stack overflow error. CheckSyntaxResultStackOverflowError )
func (CheckSyntaxResult) String ¶
func (c CheckSyntaxResult) String() string
String returns the name in string for CheckSyntaxResult.
type Class ¶
Class represents a custom JavaScript class registered by the user in a CContext. It allows to create new JavaScripts objects whose instances are created by the user using this API. It's possible to add constructors, properties and methods for a JSSClass by providing #GCallback<!-- -->s to implement them.
type ClassVTable ¶
type ClassVTable struct {
// contains filtered or unexported fields
}
ClassVTable: virtual table for a JSCClass. This can be optionally used when registering a CClass in a CContext to provide a custom implementation for the class. All virtual functions are optional and can be set to NULL to fallback to the default implementation.
An instance of this type is always passed by reference.
type Context ¶
Context 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 jsc_context_evaluate() or jsc_context_evaluate_with_source_uri(). It's also possible to register custom objects in the context with jsc_context_register_class().
func ContextGetCurrent ¶
func ContextGetCurrent() *Context
ContextGetCurrent: get the CContext that is currently executing a function. This should only be called within a function or method callback, otherwise NULL will be returned.
The function returns the following values:
- context (optional) that is currently executing.
func NewContext ¶
func NewContext() *Context
NewContext: create a new CContext. The context is created in a new CVirtualMachine. Use jsc_context_new_with_virtual_machine() to create a new CContext in an existing CVirtualMachine.
The function returns the following values:
- context: newly created CContext.
func NewContextWithVirtualMachine ¶
func NewContextWithVirtualMachine(vm *VirtualMachine) *Context
NewContextWithVirtualMachine: create a new CContext in virtual_machine.
The function takes the following parameters:
- vm: CVirtualMachine.
The function returns the following values:
- context: newly created CContext.
func (*Context) CheckSyntax ¶
func (context *Context) CheckSyntax(code string, length int, mode CheckSyntaxMode, uri string, lineNumber uint) (*Exception, CheckSyntaxResult)
CheckSyntax: check 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 exception. In case of errors exception will be set to a new CException with the details. You can pass NULL to exception to ignore the error details.
The function takes the following parameters:
- code: javaScript script to check.
- length of code, or -1 if code is a nul-terminated string.
- mode: CCheckSyntaxMode.
- uri: source URI.
- lineNumber: starting line number.
The function returns the following values:
- exception (optional): return location for a CException, or NULL to ignore.
- checkSyntaxResult: CCheckSyntaxResult.
func (*Context) ClearException ¶
func (context *Context) ClearException()
ClearException: clear the uncaught exception in context if any.
func (*Context) Evaluate ¶
Evaluate code in context.
The function takes the following parameters:
- code: javaScript script to evaluate.
- length of code, or -1 if code is a nul-terminated string.
The function returns the following values:
- value representing the last value generated by the script.
func (*Context) EvaluateInObject ¶
func (context *Context) EvaluateInObject(code string, length int, objectInstance unsafe.Pointer, objectClass *Class, uri string, lineNumber uint) (object, value *Value)
EvaluateInObject: 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 jsc_value_new_object() works, if object_instance is not NULL object_class must be provided too. 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 exceptions and they don't affect the behavior of the script.
The function takes the following parameters:
- code: javaScript script to evaluate.
- length of code, or -1 if code is a nul-terminated string.
- objectInstance (optional): object instance.
- objectClass (optional) or NULL to use the default.
- uri: source URI.
- lineNumber: starting line number.
The function returns the following values:
- object: return location for a CValue.
- value representing the last value generated by the script.
func (*Context) EvaluateWithSourceURI ¶
func (context *Context) EvaluateWithSourceURI(code string, length int, uri string, lineNumber uint) *Value
EvaluateWithSourceURI: evaluate 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 exceptions and they don't affect the behavior of the script.
The function takes the following parameters:
- code: javaScript script to evaluate.
- length of code, or -1 if code is a nul-terminated string.
- uri: source URI.
- lineNumber: starting line number.
The function returns the following values:
- value representing the last value generated by the script.
func (*Context) Exception ¶
Exception: get the last unhandled exception thrown in context by API functions calls.
The function returns the following values:
- exception (optional) or NULL if there isn't any unhandled exception in the CContext.
func (*Context) GlobalObject ¶
GlobalObject: get a CValue referencing the context global object.
The function returns the following values:
- value: CValue.
func (*Context) PopExceptionHandler ¶
func (context *Context) PopExceptionHandler()
PopExceptionHandler: remove the last CExceptionHandler previously pushed to context with jsc_context_push_exception_handler().
func (*Context) PushExceptionHandler ¶
func (context *Context) PushExceptionHandler(handler ExceptionHandler)
PushExceptionHandler: push an exception handler in context. Whenever a JavaScript exception happens in the CContext, the given handler will be called. The default CExceptionHandler simply calls jsc_context_throw_exception() to throw the exception to the CContext. If you don't want to catch the exception, but only get notified about it, call jsc_context_throw_exception() in handler like the default one does. The last exception handler pushed is the only one used by the CContext, use jsc_context_pop_exception_handler() to remove it and set the previous one. When handler is removed from the context, destroy_notify i called with user_data as parameter.
The function takes the following parameters:
- handler: CExceptionHandler.
func (*Context) SetValue ¶
SetValue: set a property of context global object with name and value.
The function takes the following parameters:
- name: value name.
- value: CValue.
func (*Context) Throw ¶
Throw an exception to context using the given error message. The created CException can be retrieved with jsc_context_get_exception().
The function takes the following parameters:
- errorMessage: error message.
func (*Context) ThrowException ¶
ThrowException: throw exception to context.
The function takes the following parameters:
- exception: CException.
func (*Context) ThrowWithName ¶
ThrowWithName: throw an exception to context using the given error name and message. The created CException can be retrieved with jsc_context_get_exception().
The function takes the following parameters:
- errorName: error name.
- errorMessage: error message.
func (*Context) Value ¶
Value: get a property of context global object with name.
The function takes the following parameters:
- name: value name.
The function returns the following values:
- value: CValue.
func (*Context) VirtualMachine ¶
func (context *Context) VirtualMachine() *VirtualMachine
VirtualMachine: get the CVirtualMachine where context was created.
The function returns the following values:
- virtualMachine where the CContext was created.
type ContextClass ¶
type ContextClass struct {
// contains filtered or unexported fields
}
ContextClass: instance of this type is always passed by reference.
type ContextOverrides ¶
type ContextOverrides struct { }
ContextOverrides contains methods that are overridable.
type Exception ¶
Exception represents a JavaScript exception.
func NewException ¶
NewException: create a new CException in context with message.
The function takes the following parameters:
- context: CContext.
- message: error message.
The function returns the following values:
- exception: new CException.
func NewExceptionWithName ¶
NewExceptionWithName: create a new CException in context with name and message.
The function takes the following parameters:
- context: CContext.
- name: error name.
- message: error message.
The function returns the following values:
- exception: new CException.
func (*Exception) BacktraceString ¶
BacktraceString: get a string with the exception backtrace.
The function returns the following values:
- utf8 (optional): exception backtrace string or NULL.
func (*Exception) ColumnNumber ¶
ColumnNumber: get the column number at which exception happened.
The function returns the following values:
- guint: column number of exception.
func (*Exception) LineNumber ¶
LineNumber: get the line number at which exception happened.
The function returns the following values:
- guint: line number of exception.
func (*Exception) Message ¶
Message: get the error message of exception.
The function returns the following values:
- utf8: exception error message.
func (*Exception) Name ¶
Name: get the error name of exception.
The function returns the following values:
- utf8: exception error name.
func (*Exception) Report ¶
Report: return a report message of exception, containing all the possible details such us source URI, line, column and backtrace, and formatted to be printed.
The function returns the following values:
- utf8: new string with the exception report.
type ExceptionClass ¶
type ExceptionClass struct {
// contains filtered or unexported fields
}
ExceptionClass: instance of this type is always passed by reference.
type ExceptionHandler ¶
ExceptionHandler: function used to handle JavaScript exceptions in a CContext.
type ExceptionOverrides ¶
type ExceptionOverrides struct { }
ExceptionOverrides contains methods that are overridable.
type OptionType ¶
OptionType: enum values for options types.
const ( // OptionBoolean option type. OptionBoolean OptionType = iota // OptionInt option type. OptionInt // OptionUint option type. OptionUint // OptionSize options type. OptionSize // OptionDouble options type. OptionDouble // OptionString: string option type. OptionString // OptionRangeString: range string option type. OptionRangeString )
func (OptionType) String ¶
func (o OptionType) String() string
String returns the name in string for OptionType.
type OptionsFunc ¶
type OptionsFunc func(option string, typ OptionType, description string) (ok bool)
OptionsFunc: function used to iterate options.
Not that description string is not localized.
type TypedArrayType ¶
TypedArrayType: possible types of the elements contained in a typed array.
const ( // TypedArrayNone: not a typed array, or type unsupported. TypedArrayNone TypedArrayType = iota // TypedArrayInt8: array elements are 8-bit signed integers (int8_t). TypedArrayInt8 // TypedArrayInt16: array elements are 16-bit signed integers (int16_t). TypedArrayInt16 // TypedArrayInt32: array elements are 32-bit signed integers (int32_t). TypedArrayInt32 // TypedArrayInt64: array elements are 64-bit signed integers (int64_t). TypedArrayInt64 // TypedArrayUint8: array elements are 8-bit unsigned integers (uint8_t). TypedArrayUint8 // TypedArrayUint8Clamped: array elements are 8-bit unsigned integers // (uint8_t). TypedArrayUint8Clamped // TypedArrayUint16: array elements are 16-bit unsigned integers (uint16_t). TypedArrayUint16 // TypedArrayUint32: array elements are 32-bit unsigned integers (uint32_t). TypedArrayUint32 // TypedArrayUint64: array elements are 64-bit unsigned integers (uint64_t). TypedArrayUint64 // TypedArrayFloat32: array elements are 32-bit floating point numbers // (float). TypedArrayFloat32 // TypedArrayFloat64: array elements are 64-bit floating point numbers // (double). TypedArrayFloat64 )
func (TypedArrayType) String ¶
func (t TypedArrayType) String() string
String returns the name in string for TypedArrayType.
type Value ¶
Value represents a reference to a value in a CContext. The JSCValue protects the referenced value from being garbage collected.
func NewValueArrayFromStrv ¶
NewValueArrayFromStrv: create a new CValue referencing an array of strings with the items from strv. If array is NULL or empty a new empty array will be created.
The function takes the following parameters:
- context: CContext.
- strv: NULL-terminated array of strings.
The function returns the following values:
- value: CValue.
func NewValueBoolean ¶
NewValueBoolean: create a new CValue from value.
The function takes the following parameters:
- context: CContext.
- value: #gboolean.
The function returns the following values:
- ret: CValue.
func NewValueFromJson ¶
NewValueFromJson: create a new CValue referencing a new value created by parsing json.
The function takes the following parameters:
- context: CContext.
- json: JSON string to be parsed.
The function returns the following values:
- value: CValue.
func NewValueNull ¶
NewValueNull: create a new CValue referencing <function>null</function> in context.
The function takes the following parameters:
- context: CContext.
The function returns the following values:
- value: CValue.
func NewValueNumber ¶
NewValueNumber: create a new CValue from number.
The function takes the following parameters:
- context: CContext.
- number: number.
The function returns the following values:
- value: CValue.
func NewValueObject ¶
NewValueObject: create a new CValue from instance. If instance is NULL a new empty object is created. When instance is provided, jsc_class must be provided too. jsc_class takes ownership of instance that will be freed by the Notify passed to jsc_context_register_class().
The function takes the following parameters:
- context: CContext.
- instance (optional): object instance or NULL.
- jscClass (optional) of instance.
The function returns the following values:
- value: CValue.
func NewValueString ¶
NewValueString: create a new CValue from string. If you need to create a CValue from a string containing null characters, use jsc_value_new_string_from_bytes() instead.
The function takes the following parameters:
- context: CContext.
- str (optional): null-terminated string.
The function returns the following values:
- value: CValue.
func NewValueStringFromBytes ¶
NewValueStringFromBytes: create a new CValue from bytes.
The function takes the following parameters:
- context: CContext.
- bytes (optional): #GBytes.
The function returns the following values:
- value: CValue.
func NewValueTypedArray ¶
func NewValueTypedArray(context *Context, typ TypedArrayType, length uint) *Value
NewValueTypedArray: create a new typed array containing a given amount of elements.
Create a CValue referencing a new typed array with space for length elements of a given type. As all typed arrays must have an associated ArrayBuffer, a new one of suitable size will be allocated to store the elements, which will be initialized to zero.
The type must *not* be JSC_TYPED_ARRAY_NONE.
The function takes the following parameters:
- context: CContext.
- typ: type of array elements.
- length: number of elements in the array.
The function returns the following values:
- value: CValue.
func NewValueUndefined ¶
NewValueUndefined: create a new CValue referencing <function>undefined</function> in context.
The function takes the following parameters:
- context: CContext.
The function returns the following values:
- value: CValue.
func (*Value) ArrayBufferGetData ¶
ArrayBufferGetData gets a pointer to memory that contains the array buffer data.
Obtains a pointer to the memory region that holds the contents of the ArrayBuffer; modifications done to the data will be visible to JavaScript code. If size is not NULL, the size in bytes of the memory region will also be stored in the pointed location.
Note that the pointer returned by this function is not guaranteed to remain the same after calls to other JSC API functions. If you plan to access the data of the ArrayBuffer later, you can keep a reference to the value and obtain the data pointer at a later point. Keep in mind that if JavaScript code has a chance to run, for example due to main loop events that result in JSC being called, the contents of the memory region might be modified in the meantime. Consider taking a copy of the data and using the copy instead in asynchronous code.
The function takes the following parameters:
- size (optional): location where to store the size of the memory region.
The function returns the following values:
- gpointer (optional): pointer to memory.
func (*Value) ArrayBufferGetSize ¶
ArrayBufferGetSize gets the size in bytes of the array buffer.
Obtains the size in bytes of the memory region that holds the contents of an ArrayBuffer.
The function returns the following values:
- gsize: size, in bytes.
func (*Value) ConstructorCall ¶
ConstructorCall: invoke <function>new</function> with constructor referenced by value. If n_parameters is 0 no parameters will be passed to the constructor.
The function takes the following parameters:
- parameters (optional) -->s to pass as parameters to the constructor, or NULL.
The function returns the following values:
- ret referencing the newly created object instance.
func (*Value) Context ¶
Context: get the CContext in which value was created.
The function returns the following values:
- context: CValue context.
func (*Value) FunctionCall ¶
FunctionCall: call function referenced by value, passing the given parameters. If n_parameters is 0 no parameters will be passed to the function.
This function always returns a CValue, in case of void functions a CValue referencing <function>undefined</function> is returned.
The function takes the following parameters:
- parameters (optional) -->s to pass as parameters to the function, or NULL.
The function returns the following values:
- ret with the return value of the function.
func (*Value) IsArray ¶
IsArray: get whether the value referenced by value is an array.
The function returns the following values:
- ok: whether the value is an array.
func (*Value) IsArrayBuffer ¶
IsArrayBuffer: check whether the value is an ArrayBuffer.
The function returns the following values:
- ok: whether the value is an ArrayBuffer.
func (*Value) IsBoolean ¶
IsBoolean: get whether the value referenced by value is a boolean.
The function returns the following values:
- ok: whether the value is a boolean.
func (*Value) IsConstructor ¶
IsConstructor: get whether the value referenced by value is a constructor.
The function returns the following values:
- ok: whether the value is a constructor.
func (*Value) IsFunction ¶
IsFunction: get whether the value referenced by value is a function.
The function returns the following values:
- ok: whether the value is a function.
func (*Value) IsNull ¶
IsNull: get whether the value referenced by value is <function>null</function>.
The function returns the following values:
- ok: whether the value is null.
func (*Value) IsNumber ¶
IsNumber: get whether the value referenced by value is a number.
The function returns the following values:
- ok: whether the value is a number.
func (*Value) IsObject ¶
IsObject: get whether the value referenced by value is an object.
The function returns the following values:
- ok: whether the value is an object.
func (*Value) IsString ¶
IsString: get whether the value referenced by value is a string.
The function returns the following values:
- ok: whether the value is a string.
func (*Value) IsTypedArray ¶
IsTypedArray determines whether a value is a typed array.
The function returns the following values:
- ok: whether value is a typed array.
func (*Value) IsUndefined ¶
IsUndefined: get whether the value referenced by value is <function>undefined</function>.
The function returns the following values:
- ok: whether the value is undefined.
func (*Value) NewTypedArrayWithBuffer ¶
func (arrayBuffer *Value) NewTypedArrayWithBuffer(typ TypedArrayType, offset uint, length int) *Value
NewTypedArrayWithBuffer: create a new typed array value with elements from an array buffer.
Create a CValue referencing a new typed array value containing elements of the given type, where the elements are stored at the memory region represented by the array_buffer.
The type must *not* be JSC_TYPED_ARRAY_NONE.
The offset and length parameters can be used to indicate which part of the array buffer can be accessed through the typed array. If both are omitted (passing zero as offset, and -1 as length), the whole array_buffer is exposed through the typed array. Omitting the length with a non-zero offset will expose the remainder of the array_buffer starting at the indicated offset.
The function takes the following parameters:
- typ: type of array elements.
- offset: offset, in bytes.
- length: number of array elements, or -1.
The function returns the following values:
- value: CValue.
func (*Value) ObjectDefinePropertyData ¶
func (value *Value) ObjectDefinePropertyData(propertyName string, flags ValuePropertyFlags, propertyValue *Value)
ObjectDefinePropertyData: define or modify a property with property_name in object referenced by value. This is equivalent to JavaScript <function>Object.defineProperty()</function> when used with a data descriptor.
The function takes the following parameters:
- propertyName: name of the property to define.
- flags: CValuePropertyFlags.
- propertyValue (optional): default property value.
func (*Value) ObjectDeleteProperty ¶
ObjectDeleteProperty: try to delete property with name from value. This function will return FALSE if the property was defined without JSC_VALUE_PROPERTY_CONFIGURABLE flag.
The function takes the following parameters:
- name: property name.
The function returns the following values:
- ok: TRUE if the property was deleted, or FALSE otherwise.
func (*Value) ObjectEnumerateProperties ¶
ObjectEnumerateProperties: get the list of property names of value. Only properties defined with JSC_VALUE_PROPERTY_ENUMERABLE flag will be collected.
The function returns the following values:
- utf8s (optional): NULL-terminated array of strings containing the property names, or NULL if value doesn't have enumerable properties. Use g_strfreev() to free.
func (*Value) ObjectGetProperty ¶
ObjectGetProperty: get property with name from value.
The function takes the following parameters:
- name: property name.
The function returns the following values:
- ret: property CValue.
func (*Value) ObjectGetPropertyAtIndex ¶
ObjectGetPropertyAtIndex: get property at index from value.
The function takes the following parameters:
- index: property index.
The function returns the following values:
- ret: property CValue.
func (*Value) ObjectHasProperty ¶
ObjectHasProperty: get whether value has property with name.
The function takes the following parameters:
- name: property name.
The function returns the following values:
- ok: TRUE if value has a property with name, or FALSE otherwise.
func (*Value) ObjectInvokeMethod ¶
ObjectInvokeMethod: invoke method with name on object referenced by value, passing the given parameters. If n_parameters is 0 no parameters will be passed to the method. The object instance will be handled automatically even when the method is a custom one registered with jsc_class_add_method(), so it should never be passed explicitly as parameter of this function.
This function always returns a CValue, in case of void methods a CValue referencing <function>undefined</function> is returned.
The function takes the following parameters:
- name: method name.
- parameters (optional) -->s to pass as parameters to the method, or NULL.
The function returns the following values:
- ret with the return value of the method.
func (*Value) ObjectIsInstanceOf ¶
ObjectIsInstanceOf: get whether the value referenced by value is an instance of class name.
The function takes the following parameters:
- name class name.
The function returns the following values:
- ok: whether the value is an object instance of class name.
func (*Value) ObjectSetProperty ¶
ObjectSetProperty: set property with name on value.
The function takes the following parameters:
- name: property name.
- property to set.
func (*Value) ObjectSetPropertyAtIndex ¶
ObjectSetPropertyAtIndex: set property at index on value.
The function takes the following parameters:
- index: property index.
- property to set.
func (*Value) String ¶
String: convert value to a string. Use jsc_value_to_string_as_bytes() instead, if you need to handle strings containing null characters.
The function returns the following values:
- utf8: null-terminated string result of the conversion.
func (*Value) ToBoolean ¶
ToBoolean: convert value to a boolean.
The function returns the following values:
- ok result of the conversion.
func (*Value) ToDouble ¶
ToDouble: convert value to a double.
The function returns the following values:
- gdouble result of the conversion.
func (*Value) ToInt32 ¶
ToInt32: convert value to a #gint32.
The function returns the following values:
- gint32 result of the conversion.
func (*Value) ToJson ¶
ToJson: create a JSON string of value serialization. If indent is 0, the resulting JSON will not contain newlines. The size of the indent is clamped to 10 spaces.
The function takes the following parameters:
- indent: number of spaces to indent when nesting.
The function returns the following values:
- utf8: null-terminated JSON string with serialization of value.
func (*Value) ToStringAsBytes ¶
func (value *Value) ToStringAsBytes() *glib.Bytes
ToStringAsBytes: convert value to a string and return the results as #GBytes. This is needed to handle strings with null characters.
The function returns the following values:
- bytes with the result of the conversion.
func (*Value) TypedArrayGetBuffer ¶
TypedArrayGetBuffer: obtain the ArrayBuffer for the memory region of the typed array elements.
The function returns the following values:
- ret: CValue.
func (*Value) TypedArrayGetData ¶
TypedArrayGetData obtains a pointer to the memory region that holds the elements of the typed array; modifications done to them will be visible to JavaScript code. If length is not NULL, the number of elements contained in the typed array are also stored in the pointed location.
The returned pointer needs to be casted to the appropriate type (see CTypedArrayType), and has the offset over the underlying array buffer data applied—that is, points to the first element of the typed array:
if (jsc_value_typed_array_get_type(value) != JSC_TYPED_ARRAY_UINT32) g_error ("Only arrays of uint32_t are supported"); gsize count = 0; uint32_t *elements = jsc_value_typed_array_get_contents (value, &count); for (gsize i = 0; i < count; i++) g_print ("index zu, value %" PRIu32 "\n", i, elements[i]);
Note that the pointer returned by this function is not guaranteed to remain the same after calls to other JSC API functions. See jsc_value_array_buffer_get_data() for details.
The function returns the following values:
- length (optional): location to return the number of elements contained.
- gpointer (optional): pointer to memory.
func (*Value) TypedArrayGetLength ¶
TypedArrayGetLength gets the number of elements in a typed array.
The function returns the following values:
- gsize: number of elements.
func (*Value) TypedArrayGetOffset ¶
TypedArrayGetOffset gets the offset over the underlying array buffer data.
The function returns the following values:
- gsize: offset, in bytes.
func (*Value) TypedArrayGetSize ¶
TypedArrayGetSize gets the size of a typed array.
The function returns the following values:
- gsize: size, in bytes.
func (*Value) TypedArrayGetType ¶
func (value *Value) TypedArrayGetType() TypedArrayType
TypedArrayGetType gets the type of elements contained in a typed array.
The function returns the following values:
- typedArrayType: type of the elements, or JSC_TYPED_ARRAY_NONE if value is not a typed array.
type ValueClass ¶
type ValueClass struct {
// contains filtered or unexported fields
}
ValueClass: instance of this type is always passed by reference.
type ValueOverrides ¶
type ValueOverrides struct { }
ValueOverrides contains methods that are overridable.
type ValuePropertyFlags ¶
ValuePropertyFlags flags used when defining properties with jsc_value_object_define_property_data() and jsc_value_object_define_property_accessor().
const ( // ValuePropertyConfigurable: type of the property descriptor may be changed // and the property may be deleted from the corresponding object. ValuePropertyConfigurable ValuePropertyFlags = 0b1 // ValuePropertyEnumerable: property shows up during enumeration of the // properties on the corresponding object. ValuePropertyEnumerable ValuePropertyFlags = 0b10 // ValuePropertyWritable: value associated with the property may be changed // with an assignment operator. This doesn't have any effect when passed to // jsc_value_object_define_property_accessor(). ValuePropertyWritable ValuePropertyFlags = 0b100 )
func (ValuePropertyFlags) Has ¶
func (v ValuePropertyFlags) Has(other ValuePropertyFlags) bool
Has returns true if v contains other.
func (ValuePropertyFlags) String ¶
func (v ValuePropertyFlags) String() string
String returns the names in string for ValuePropertyFlags.
type VirtualMachine ¶
VirtualMachine represents a group of JSCContext<!-- -->s. It allows concurrent JavaScript execution by creating a different instance of JSCVirtualMachine in each thread.
To create a group of JSCContext<!-- -->s pass the same JSCVirtualMachine instance to every JSCContext constructor.
func NewVirtualMachine ¶
func NewVirtualMachine() *VirtualMachine
NewVirtualMachine: create a new CVirtualMachine.
The function returns the following values:
- virtualMachine: newly created CVirtualMachine.
type VirtualMachineClass ¶
type VirtualMachineClass struct {
// contains filtered or unexported fields
}
VirtualMachineClass: instance of this type is always passed by reference.
type VirtualMachineOverrides ¶
type VirtualMachineOverrides struct { }
VirtualMachineOverrides contains methods that are overridable.
type WeakValue ¶
WeakValue represents a weak reference to a value in a CContext. It can be used to keep a reference to a JavaScript value without protecting it from being garbage collected and without referencing the CContext either.
func NewWeakValue ¶
NewWeakValue: create a new CWeakValue for the JavaScript value referenced by value.
The function takes the following parameters:
- value: CValue.
The function returns the following values:
- weakValue: new CWeakValue.
func (*WeakValue) ConnectCleared ¶
func (weakValue *WeakValue) ConnectCleared(f func()) coreglib.SignalHandle
ConnectCleared: this signal is emitted when the JavaScript value is destroyed.
type WeakValueClass ¶
type WeakValueClass struct {
// contains filtered or unexported fields
}
WeakValueClass: instance of this type is always passed by reference.
type WeakValueOverrides ¶
type WeakValueOverrides struct { }
WeakValueOverrides contains methods that are overridable.