use crate::{Context, TypedArrayType, ValuePropertyFlags};
use glib::translate::*;
use std::fmt;
glib::wrapper! {
#[doc(alias = "JSCValue")]
pub struct Value(Object<ffi::JSCValue, ffi::JSCValueClass>);
match fn {
type_ => || ffi::jsc_value_get_type(),
}
}
impl Value {
#[doc(alias = "jsc_value_new_array_from_garray")]
pub fn new_array_from_garray(context: &Context, array: &[Value]) -> Value {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::jsc_value_new_array_from_garray(
context.to_glib_none().0,
array.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_new_array_from_strv")]
pub fn new_array_from_strv(context: &Context, strv: &[&str]) -> Value {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::jsc_value_new_array_from_strv(
context.to_glib_none().0,
strv.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_new_boolean")]
pub fn new_boolean(context: &Context, value: bool) -> Value {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::jsc_value_new_boolean(
context.to_glib_none().0,
value.into_glib(),
))
}
}
#[doc(alias = "jsc_value_new_from_json")]
#[doc(alias = "new_from_json")]
pub fn from_json(context: &Context, json: &str) -> Value {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::jsc_value_new_from_json(
context.to_glib_none().0,
json.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_new_null")]
pub fn new_null(context: &Context) -> Value {
skip_assert_initialized!();
unsafe { from_glib_full(ffi::jsc_value_new_null(context.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_new_number")]
pub fn new_number(context: &Context, number: f64) -> Value {
skip_assert_initialized!();
unsafe { from_glib_full(ffi::jsc_value_new_number(context.to_glib_none().0, number)) }
}
#[doc(alias = "jsc_value_new_string")]
pub fn new_string(context: &Context, string: Option<&str>) -> Value {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::jsc_value_new_string(
context.to_glib_none().0,
string.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_new_string_from_bytes")]
pub fn new_string_from_bytes(context: &Context, bytes: Option<&glib::Bytes>) -> Value {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::jsc_value_new_string_from_bytes(
context.to_glib_none().0,
bytes.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_new_typed_array")]
pub fn new_typed_array(context: &Context, type_: TypedArrayType, length: usize) -> Value {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::jsc_value_new_typed_array(
context.to_glib_none().0,
type_.into_glib(),
length,
))
}
}
#[doc(alias = "jsc_value_new_undefined")]
pub fn new_undefined(context: &Context) -> Value {
skip_assert_initialized!();
unsafe { from_glib_full(ffi::jsc_value_new_undefined(context.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_array_buffer_get_size")]
pub fn array_buffer_get_size(&self) -> usize {
unsafe { ffi::jsc_value_array_buffer_get_size(self.to_glib_none().0) }
}
#[doc(alias = "jsc_value_constructor_callv")]
#[must_use]
pub fn constructor_callv(&self, parameters: &[Value]) -> Option<Value> {
let n_parameters = parameters.len() as _;
unsafe {
from_glib_full(ffi::jsc_value_constructor_callv(
self.to_glib_none().0,
n_parameters,
parameters.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_function_callv")]
#[must_use]
pub fn function_callv(&self, parameters: &[Value]) -> Option<Value> {
let n_parameters = parameters.len() as _;
unsafe {
from_glib_full(ffi::jsc_value_function_callv(
self.to_glib_none().0,
n_parameters,
parameters.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_get_context")]
#[doc(alias = "get_context")]
pub fn context(&self) -> Option<Context> {
unsafe { from_glib_none(ffi::jsc_value_get_context(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_array")]
pub fn is_array(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_array(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_array_buffer")]
pub fn is_array_buffer(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_array_buffer(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_boolean")]
pub fn is_boolean(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_boolean(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_constructor")]
pub fn is_constructor(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_constructor(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_function")]
pub fn is_function(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_function(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_null")]
pub fn is_null(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_null(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_number")]
pub fn is_number(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_number(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_object")]
pub fn is_object(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_object(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_string")]
pub fn is_string(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_string(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_typed_array")]
pub fn is_typed_array(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_typed_array(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_is_undefined")]
pub fn is_undefined(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_is_undefined(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_new_typed_array_with_buffer")]
#[must_use]
pub fn new_typed_array_with_buffer(
&self,
type_: TypedArrayType,
offset: usize,
length: isize,
) -> Option<Value> {
unsafe {
from_glib_full(ffi::jsc_value_new_typed_array_with_buffer(
self.to_glib_none().0,
type_.into_glib(),
offset,
length,
))
}
}
#[doc(alias = "jsc_value_object_define_property_data")]
pub fn object_define_property_data(
&self,
property_name: &str,
flags: ValuePropertyFlags,
property_value: Option<&Value>,
) {
unsafe {
ffi::jsc_value_object_define_property_data(
self.to_glib_none().0,
property_name.to_glib_none().0,
flags.into_glib(),
property_value.to_glib_none().0,
);
}
}
#[doc(alias = "jsc_value_object_delete_property")]
pub fn object_delete_property(&self, name: &str) -> bool {
unsafe {
from_glib(ffi::jsc_value_object_delete_property(
self.to_glib_none().0,
name.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_object_enumerate_properties")]
pub fn object_enumerate_properties(&self) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::jsc_value_object_enumerate_properties(
self.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_object_get_property")]
#[must_use]
pub fn object_get_property(&self, name: &str) -> Option<Value> {
unsafe {
from_glib_full(ffi::jsc_value_object_get_property(
self.to_glib_none().0,
name.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_object_get_property_at_index")]
#[must_use]
pub fn object_get_property_at_index(&self, index: u32) -> Option<Value> {
unsafe {
from_glib_full(ffi::jsc_value_object_get_property_at_index(
self.to_glib_none().0,
index,
))
}
}
#[doc(alias = "jsc_value_object_has_property")]
pub fn object_has_property(&self, name: &str) -> bool {
unsafe {
from_glib(ffi::jsc_value_object_has_property(
self.to_glib_none().0,
name.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_object_invoke_methodv")]
#[must_use]
pub fn object_invoke_methodv(&self, name: &str, parameters: &[Value]) -> Option<Value> {
let n_parameters = parameters.len() as _;
unsafe {
from_glib_full(ffi::jsc_value_object_invoke_methodv(
self.to_glib_none().0,
name.to_glib_none().0,
n_parameters,
parameters.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_object_is_instance_of")]
pub fn object_is_instance_of(&self, name: &str) -> bool {
unsafe {
from_glib(ffi::jsc_value_object_is_instance_of(
self.to_glib_none().0,
name.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_value_object_set_property")]
pub fn object_set_property(&self, name: &str, property: &Value) {
unsafe {
ffi::jsc_value_object_set_property(
self.to_glib_none().0,
name.to_glib_none().0,
property.to_glib_none().0,
);
}
}
#[doc(alias = "jsc_value_object_set_property_at_index")]
pub fn object_set_property_at_index(&self, index: u32, property: &Value) {
unsafe {
ffi::jsc_value_object_set_property_at_index(
self.to_glib_none().0,
index,
property.to_glib_none().0,
);
}
}
#[doc(alias = "jsc_value_to_boolean")]
pub fn to_boolean(&self) -> bool {
unsafe { from_glib(ffi::jsc_value_to_boolean(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_to_double")]
pub fn to_double(&self) -> f64 {
unsafe { ffi::jsc_value_to_double(self.to_glib_none().0) }
}
#[doc(alias = "jsc_value_to_int32")]
pub fn to_int32(&self) -> i32 {
unsafe { ffi::jsc_value_to_int32(self.to_glib_none().0) }
}
#[doc(alias = "jsc_value_to_json")]
pub fn to_json(&self, indent: u32) -> Option<glib::GString> {
unsafe { from_glib_full(ffi::jsc_value_to_json(self.to_glib_none().0, indent)) }
}
#[doc(alias = "jsc_value_to_string")]
#[doc(alias = "to_string")]
pub fn to_str(&self) -> glib::GString {
unsafe { from_glib_full(ffi::jsc_value_to_string(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_to_string_as_bytes")]
pub fn to_string_as_bytes(&self) -> Option<glib::Bytes> {
unsafe { from_glib_full(ffi::jsc_value_to_string_as_bytes(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_typed_array_get_buffer")]
#[must_use]
pub fn typed_array_get_buffer(&self) -> Option<Value> {
unsafe { from_glib_full(ffi::jsc_value_typed_array_get_buffer(self.to_glib_none().0)) }
}
#[doc(alias = "jsc_value_typed_array_get_length")]
pub fn typed_array_get_length(&self) -> usize {
unsafe { ffi::jsc_value_typed_array_get_length(self.to_glib_none().0) }
}
#[doc(alias = "jsc_value_typed_array_get_offset")]
pub fn typed_array_get_offset(&self) -> usize {
unsafe { ffi::jsc_value_typed_array_get_offset(self.to_glib_none().0) }
}
#[doc(alias = "jsc_value_typed_array_get_size")]
pub fn typed_array_get_size(&self) -> usize {
unsafe { ffi::jsc_value_typed_array_get_size(self.to_glib_none().0) }
}
#[doc(alias = "jsc_value_typed_array_get_type")]
pub fn typed_array_get_type(&self) -> TypedArrayType {
unsafe { from_glib(ffi::jsc_value_typed_array_get_type(self.to_glib_none().0)) }
}
}
impl fmt::Display for Value {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_str())
}
}