Value

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

class Value : ObjectG {}

Constructors

this
this(JSCValue* jSCValue, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(Context context, PtrArray array)

Create a new #JSCValue referencing an array with the items from @array. If @array is %NULL or empty a new empty array will be created. Elements of @array should be pointers to a #JSCValue.

this
this(Context context, string[] strv)

Create a new #JSCValue referencing an array of strings with the items from @strv. If @array is %NULL or empty a new empty array will be created.

this
this(Context context, bool value)

Create a new #JSCValue from @value

this
this(Context context, string name, GCallback callback, void* userData, GDestroyNotify destroyNotify, GType returnType)

Create a function in @context. If @name is %NULL an anonymous function will be created. When the function is called by JavaScript or jsc_value_function_call(), @callback is called receiving an #GPtrArray of #JSCValue<!-- -->s with the arguments and then @user_data as last parameter. When the function is cleared in @context, @destroy_notify is called with @user_data as parameter.

this
this(Context context, string name, GCallback callback, void* userData, GDestroyNotify destroyNotify, GType returnType, GType[] parameterTypes)

Create a function in @context. If @name is %NULL an anonymous function will be created. When the function is called by JavaScript or jsc_value_function_call(), @callback is called receiving the function parameters and then @user_data as last parameter. When the function is cleared in @context, @destroy_notify is called with @user_data as parameter.

this
this(Context context)

Create a new #JSCValue referencing <function>null</function> in @context.

this
this(Context context, double number)

Create a new #JSCValue from @number.

this
this(Context context, void* instance_, Class jscClass)

Create a new #JSCValue 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 #GDestroyNotify passed to jsc_context_register_class().

this
this(Context context, string string_)

Create a new #JSCValue from @string. If you need to create a #JSCValue from a string containing null characters, use jsc_value_new_string_from_bytes() instead.

this
this(Context context, Bytes bytes)

Create a new #JSCValue from @bytes.

Members

Functions

constructorCallv
Value constructorCallv(Value[] parameters)

Invoke <function>new</function> with constructor referenced by @value. If @n_parameters is 0 no parameters will be passed to the constructor.

functionCallv
Value functionCallv(Value[] parameters)

Call function referenced by @value, passing the given @parameters. If @n_parameters is 0 no parameters will be passed to the function.

getContext
Context getContext()

Get the #JSCContext in which @value was created.

getStruct
void* getStruct()

the main Gtk struct as a void*

getValueStruct
JSCValue* getValueStruct(bool transferOwnership)

Get the main Gtk struct

isArray
bool isArray()

Get whether the value referenced by @value is an array.

isBoolean
bool isBoolean()

Get whether the value referenced by @value is a boolean.

isConstructor
bool isConstructor()

Get whether the value referenced by @value is a constructor.

isFunction
bool isFunction()

Get whether the value referenced by @value is a function

isNull
bool isNull()

Get whether the value referenced by @value is <function>null</function>.

isNumber
bool isNumber()

Get whether the value referenced by @value is a number.

isObject
bool isObject()

Get whether the value referenced by @value is an object.

isString
bool isString()

Get whether the value referenced by @value is a string

isUndefined
bool isUndefined()

Get whether the value referenced by @value is <function>undefined</function>.

objectDefinePropertyAccessor
void objectDefinePropertyAccessor(string propertyName, JSCValuePropertyFlags flags, GType propertyType, GCallback getter, GCallback setter, void* userData, GDestroyNotify destroyNotify)

Define or modify a property with @property_name in object referenced by @value. When the property value needs to be getted or set, @getter and @setter callbacks will be called. When the property is cleared in the #JSCClass context, @destroy_notify is called with @user_data as parameter. This is equivalent to JavaScript <function>Object.defineProperty()</function> when used with an accessor descriptor.

objectDefinePropertyData
void objectDefinePropertyData(string propertyName, JSCValuePropertyFlags flags, Value propertyValue)

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.

objectDeleteProperty
bool objectDeleteProperty(string name)

Try to delete property with @name from @value. This function will return %FALSE if the property was defined without %JSC_VALUE_PROPERTY_CONFIGURABLE flag.

objectEnumerateProperties
string[] objectEnumerateProperties()

Get the list of property names of @value. Only properties defined with %JSC_VALUE_PROPERTY_ENUMERABLE flag will be collected.

objectGetProperty
Value objectGetProperty(string name)

Get property with @name from @value.

objectGetPropertyAtIndex
Value objectGetPropertyAtIndex(uint index)

Get property at @index from @value.

objectHasProperty
bool objectHasProperty(string name)

Get whether @value has property with @name.

objectInvokeMethodv
Value objectInvokeMethodv(string name, Value[] parameters)

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.

objectIsInstanceOf
bool objectIsInstanceOf(string name)

Get whether the value referenced by @value is an instance of class @name.

objectSetProperty
void objectSetProperty(string name, Value property)

Set @property with @name on @value.

objectSetPropertyAtIndex
void objectSetPropertyAtIndex(uint index, Value property)

Set @property at @index on @value.

toBoolean
bool toBoolean()

Convert @value to a boolean.

toDouble
double toDouble()

Convert @value to a double.

toInt32
int toInt32()

Convert @value to a #gint32.

toJson
string toJson(uint indent)

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.

toString
string toString()

Convert @value to a string. Use jsc_value_to_string_as_bytes() instead, if you need to handle strings containing null characters.

toStringAsBytes
Bytes toStringAsBytes()

Convert @value to a string and return the results as #GBytes. This is needed to handle strings with null characters.

Static functions

getType
GType getType()
newJSON
Value newJSON(Context context, string json)

Create a new #JSCValue referencing a new value created by parsing @json.

newUndefined
Value newUndefined(Context context)

Create a new #JSCValue referencing <function>undefined</function> in @context.

Variables

jSCValue
JSCValue* jSCValue;

the main Gtk struct

Meta