javascriptcore

package
v0.0.0-...-dee1973 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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

View Source
var (
	GTypeClass = coreglib.Type(C.jsc_class_get_type())
)

GType values.

View Source
var (
	GTypeContext = coreglib.Type(C.jsc_context_get_type())
)

GType values.

View Source
var (
	GTypeException = coreglib.Type(C.jsc_exception_get_type())
)

GType values.

View Source
var (
	GTypeValue = coreglib.Type(C.jsc_value_get_type())
)

GType values.

View Source
var (
	GTypeVirtualMachine = coreglib.Type(C.jsc_virtual_machine_get_type())
)

GType values.

View Source
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

func OptionsGetBoolean(option string) (value, ok bool)

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

func OptionsGetDouble(option string) (float64, bool)

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

func OptionsGetInt(option string) (int, bool)

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-&lt;option&gt;=&lt;value&gt;</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

func OptionsGetRangeString(option string) (string, bool)

OptionsGetRangeString: get option as a range string. The string must be in the format <emphasis>[!]&lt;low&gt;[:&lt;high&gt;]</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

func OptionsGetSize(option string) (uint, bool)

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

func OptionsGetString(option string) (string, bool)

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

func OptionsGetUint(option string) (uint, bool)

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

func OptionsSetBoolean(option string, value bool) bool

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

func OptionsSetDouble(option string, value float64) bool

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

func OptionsSetInt(option string, value int) bool

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

func OptionsSetRangeString(option, value string) bool

OptionsSetRangeString: set option as a range string. The string must be in the format <emphasis>[!]&lt;low&gt;[:&lt;high&gt;]</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

func OptionsSetSize(option string, value uint) bool

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

func OptionsSetString(option, value string) bool

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

func OptionsSetUint(option string, value uint) bool

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

type CheckSyntaxMode C.gint

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

type CheckSyntaxResult C.gint

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

type Class struct {
	*coreglib.Object
	// contains filtered or unexported fields
}

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.

func (*Class) Name

func (jscClass *Class) Name() string

Name: get the class name of jsc_class.

The function returns the following values:

  • utf8: name of jsc_class.

func (*Class) Parent

func (jscClass *Class) Parent() *Class

Parent: get the parent class of jsc_class.

The function returns the following values:

  • class: parent class of jsc_class.

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

type Context struct {
	*coreglib.Object
	// contains filtered or unexported fields
}

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

func (context *Context) Evaluate(code string, length int) *Value

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

func (context *Context) Exception() *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

func (context *Context) GlobalObject() *Value

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

func (context *Context) SetValue(name string, value *Value)

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

func (context *Context) Throw(errorMessage string)

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

func (context *Context) ThrowException(exception *Exception)

ThrowException: throw exception to context.

The function takes the following parameters:

  • exception: CException.

func (*Context) ThrowWithName

func (context *Context) ThrowWithName(errorName, errorMessage string)

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

func (context *Context) Value(name string) *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

type Exception struct {
	*coreglib.Object
	// contains filtered or unexported fields
}

Exception represents a JavaScript exception.

func NewException

func NewException(context *Context, message string) *Exception

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

func NewExceptionWithName(context *Context, name, message string) *Exception

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

func (exception *Exception) BacktraceString() string

BacktraceString: get a string with the exception backtrace.

The function returns the following values:

  • utf8 (optional): exception backtrace string or NULL.

func (*Exception) ColumnNumber

func (exception *Exception) ColumnNumber() uint

ColumnNumber: get the column number at which exception happened.

The function returns the following values:

  • guint: column number of exception.

func (*Exception) LineNumber

func (exception *Exception) LineNumber() uint

LineNumber: get the line number at which exception happened.

The function returns the following values:

  • guint: line number of exception.

func (*Exception) Message

func (exception *Exception) Message() string

Message: get the error message of exception.

The function returns the following values:

  • utf8: exception error message.

func (*Exception) Name

func (exception *Exception) Name() string

Name: get the error name of exception.

The function returns the following values:

  • utf8: exception error name.

func (*Exception) Report

func (exception *Exception) Report() string

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.

func (*Exception) SourceURI

func (exception *Exception) SourceURI() string

SourceURI: get the source URI of exception.

The function returns the following values:

  • utf8 (optional): the source URI of exception, or NULL.

func (*Exception) String

func (exception *Exception) String() string

String: get the string representation of exception error.

The function returns the following values:

  • utf8: string representation of exception.

type ExceptionClass

type ExceptionClass struct {
	// contains filtered or unexported fields
}

ExceptionClass: instance of this type is always passed by reference.

type ExceptionHandler

type ExceptionHandler func(context *Context, exception *Exception)

ExceptionHandler: function used to handle JavaScript exceptions in a CContext.

type ExceptionOverrides

type ExceptionOverrides struct {
}

ExceptionOverrides contains methods that are overridable.

type OptionType

type OptionType C.gint

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

type TypedArrayType C.gint

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

type Value struct {
	*coreglib.Object
	// contains filtered or unexported fields
}

Value represents a reference to a value in a CContext. The JSCValue protects the referenced value from being garbage collected.

func NewValueArrayFromStrv

func NewValueArrayFromStrv(context *Context, strv []string) *Value

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

func NewValueBoolean(context *Context, value bool) *Value

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

func NewValueFromJson(context *Context, json string) *Value

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

func NewValueNull(context *Context) *Value

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

func NewValueNumber(context *Context, number float64) *Value

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

func NewValueObject(context *Context, instance unsafe.Pointer, jscClass *Class) *Value

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

func NewValueString(context *Context, str string) *Value

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

func NewValueStringFromBytes(context *Context, bytes *glib.Bytes) *Value

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

func NewValueUndefined(context *Context) *Value

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

func (value *Value) ArrayBufferGetData(size *uint) unsafe.Pointer

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

func (value *Value) ArrayBufferGetSize() uint

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

func (value *Value) ConstructorCall(parameters []*Value) *Value

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

func (value *Value) Context() *Context

Context: get the CContext in which value was created.

The function returns the following values:

  • context: CValue context.

func (*Value) FunctionCall

func (value *Value) FunctionCall(parameters []*Value) *Value

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

func (value *Value) IsArray() bool

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

func (value *Value) IsArrayBuffer() bool

IsArrayBuffer: check whether the value is an ArrayBuffer.

The function returns the following values:

  • ok: whether the value is an ArrayBuffer.

func (*Value) IsBoolean

func (value *Value) IsBoolean() bool

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

func (value *Value) IsConstructor() bool

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

func (value *Value) IsFunction() bool

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

func (value *Value) IsNull() bool

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

func (value *Value) IsNumber() bool

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

func (value *Value) IsObject() bool

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

func (value *Value) IsString() bool

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

func (value *Value) IsTypedArray() bool

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

func (value *Value) IsUndefined() bool

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

func (value *Value) ObjectDeleteProperty(name string) bool

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

func (value *Value) ObjectEnumerateProperties() []string

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

func (value *Value) ObjectGetProperty(name string) *Value

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

func (value *Value) ObjectGetPropertyAtIndex(index uint) *Value

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

func (value *Value) ObjectHasProperty(name string) bool

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

func (value *Value) ObjectInvokeMethod(name string, parameters []*Value) *Value

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

func (value *Value) ObjectIsInstanceOf(name string) bool

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

func (value *Value) ObjectSetProperty(name string, property *Value)

ObjectSetProperty: set property with name on value.

The function takes the following parameters:

  • name: property name.
  • property to set.

func (*Value) ObjectSetPropertyAtIndex

func (value *Value) ObjectSetPropertyAtIndex(index uint, property *Value)

ObjectSetPropertyAtIndex: set property at index on value.

The function takes the following parameters:

  • index: property index.
  • property to set.

func (*Value) String

func (value *Value) String() 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

func (value *Value) ToBoolean() bool

ToBoolean: convert value to a boolean.

The function returns the following values:

  • ok result of the conversion.

func (*Value) ToDouble

func (value *Value) ToDouble() float64

ToDouble: convert value to a double.

The function returns the following values:

  • gdouble result of the conversion.

func (*Value) ToInt32

func (value *Value) ToInt32() int32

ToInt32: convert value to a #gint32.

The function returns the following values:

  • gint32 result of the conversion.

func (*Value) ToJson

func (value *Value) ToJson(indent uint) string

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

func (value *Value) TypedArrayGetBuffer() *Value

TypedArrayGetBuffer: obtain the ArrayBuffer for the memory region of the typed array elements.

The function returns the following values:

  • ret: CValue.

func (*Value) TypedArrayGetData

func (value *Value) TypedArrayGetData() (uint, unsafe.Pointer)

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

func (value *Value) TypedArrayGetLength() uint

TypedArrayGetLength gets the number of elements in a typed array.

The function returns the following values:

  • gsize: number of elements.

func (*Value) TypedArrayGetOffset

func (value *Value) TypedArrayGetOffset() uint

TypedArrayGetOffset gets the offset over the underlying array buffer data.

The function returns the following values:

  • gsize: offset, in bytes.

func (*Value) TypedArrayGetSize

func (value *Value) TypedArrayGetSize() uint

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

type ValuePropertyFlags C.guint

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

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

type VirtualMachine struct {
	*coreglib.Object
	// contains filtered or unexported fields
}

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

type WeakValue struct {
	*coreglib.Object
	// contains filtered or unexported fields
}

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

func NewWeakValue(value *Value) *WeakValue

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.

func (*WeakValue) Value

func (weakValue *WeakValue) Value() *Value

Value: get a CValue referencing the JavaScript value of weak_value.

The function returns the following values:

  • value: new CValue or NULL if weak_value was cleared.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL