use crate::support::Maybe;
use crate::BigInt;
use crate::Context;
use crate::Int32;
use crate::Integer;
use crate::Local;
use crate::Number;
use crate::Object;
use crate::String;
use crate::ToLocal;
use crate::Uint32;
use crate::Value;
extern "C" {
fn v8__Value__IsUndefined(this: &Value) -> bool;
fn v8__Value__IsNull(this: &Value) -> bool;
fn v8__Value__IsNullOrUndefined(this: &Value) -> bool;
fn v8__Value__IsTrue(this: &Value) -> bool;
fn v8__Value__IsFalse(this: &Value) -> bool;
fn v8__Value__IsName(this: &Value) -> bool;
fn v8__Value__IsString(this: &Value) -> bool;
fn v8__Value__IsSymbol(this: &Value) -> bool;
fn v8__Value__IsFunction(this: &Value) -> bool;
fn v8__Value__IsArray(this: &Value) -> bool;
fn v8__Value__IsObject(this: &Value) -> bool;
fn v8__Value__IsBigInt(this: &Value) -> bool;
fn v8__Value__IsBoolean(this: &Value) -> bool;
fn v8__Value__IsNumber(this: &Value) -> bool;
fn v8__Value__IsExternal(this: &Value) -> bool;
fn v8__Value__IsInt32(this: &Value) -> bool;
fn v8__Value__IsUint32(this: &Value) -> bool;
fn v8__Value__IsDate(this: &Value) -> bool;
fn v8__Value__IsArgumentsObject(this: &Value) -> bool;
fn v8__Value__IsBigIntObject(this: &Value) -> bool;
fn v8__Value__IsBooleanObject(this: &Value) -> bool;
fn v8__Value__IsNumberObject(this: &Value) -> bool;
fn v8__Value__IsStringObject(this: &Value) -> bool;
fn v8__Value__IsSymbolObject(this: &Value) -> bool;
fn v8__Value__IsNativeError(this: &Value) -> bool;
fn v8__Value__IsRegExp(this: &Value) -> bool;
fn v8__Value__IsAsyncFunction(this: &Value) -> bool;
fn v8__Value__IsGeneratorFunction(this: &Value) -> bool;
fn v8__Value__IsGeneratorObject(this: &Value) -> bool;
fn v8__Value__IsPromise(this: &Value) -> bool;
fn v8__Value__IsMap(this: &Value) -> bool;
fn v8__Value__IsSet(this: &Value) -> bool;
fn v8__Value__IsMapIterator(this: &Value) -> bool;
fn v8__Value__IsSetIterator(this: &Value) -> bool;
fn v8__Value__IsWeakMap(this: &Value) -> bool;
fn v8__Value__IsWeakSet(this: &Value) -> bool;
fn v8__Value__IsArrayBuffer(this: &Value) -> bool;
fn v8__Value__IsArrayBufferView(this: &Value) -> bool;
fn v8__Value__IsTypedArray(this: &Value) -> bool;
fn v8__Value__IsUint8Array(this: &Value) -> bool;
fn v8__Value__IsUint8ClampedArray(this: &Value) -> bool;
fn v8__Value__IsInt8Array(this: &Value) -> bool;
fn v8__Value__IsUint16Array(this: &Value) -> bool;
fn v8__Value__IsInt16Array(this: &Value) -> bool;
fn v8__Value__IsUint32Array(this: &Value) -> bool;
fn v8__Value__IsInt32Array(this: &Value) -> bool;
fn v8__Value__IsFloat32Array(this: &Value) -> bool;
fn v8__Value__IsFloat64Array(this: &Value) -> bool;
fn v8__Value__IsBigInt64Array(this: &Value) -> bool;
fn v8__Value__IsBigUint64Array(this: &Value) -> bool;
fn v8__Value__IsDataView(this: &Value) -> bool;
fn v8__Value__IsSharedArrayBuffer(this: &Value) -> bool;
fn v8__Value__IsProxy(this: &Value) -> bool;
fn v8__Value__IsWasmModuleObject(this: &Value) -> bool;
fn v8__Value__IsModuleNamespaceObject(this: &Value) -> bool;
fn v8__Value__StrictEquals(this: &Value, that: &Value) -> bool;
fn v8__Value__SameValue(this: &Value, that: &Value) -> bool;
fn v8__Value__ToBigInt(this: &Value, context: Local<Context>) -> *mut BigInt;
fn v8__Value__ToNumber(this: &Value, context: Local<Context>) -> *mut Number;
fn v8__Value__ToString(this: &Value, context: Local<Context>) -> *mut String;
fn v8__Value__ToDetailString(
this: &Value,
context: Local<Context>,
) -> *mut String;
fn v8__Value__ToObject(this: &Value, context: Local<Context>) -> *mut Object;
fn v8__Value__ToInteger(
this: &Value,
context: Local<Context>,
) -> *mut Integer;
fn v8__Value__ToUint32(this: &Value, context: Local<Context>) -> *mut Uint32;
fn v8__Value__ToInt32(this: &Value, context: Local<Context>) -> *mut Int32;
fn v8__Value__NumberValue(
this: &Value,
context: Local<Context>,
out: *mut Maybe<f64>,
);
fn v8__Value__IntegerValue(
this: &Value,
context: Local<Context>,
out: *mut Maybe<i64>,
);
fn v8__Value__Uint32Value(
this: &Value,
context: Local<Context>,
out: *mut Maybe<u32>,
);
fn v8__Value__Int32Value(
this: &Value,
context: Local<Context>,
out: *mut Maybe<i32>,
);
}
impl Value {
pub fn is_undefined(&self) -> bool {
unsafe { v8__Value__IsUndefined(self) }
}
pub fn is_null(&self) -> bool {
unsafe { v8__Value__IsNull(self) }
}
pub fn is_null_or_undefined(&self) -> bool {
unsafe { v8__Value__IsNullOrUndefined(self) }
}
pub fn is_true(&self) -> bool {
unsafe { v8__Value__IsTrue(self) }
}
pub fn is_false(&self) -> bool {
unsafe { v8__Value__IsFalse(self) }
}
pub fn is_name(&self) -> bool {
unsafe { v8__Value__IsName(self) }
}
pub fn is_string(&self) -> bool {
unsafe { v8__Value__IsString(self) }
}
pub fn is_symbol(&self) -> bool {
unsafe { v8__Value__IsSymbol(self) }
}
pub fn is_function(&self) -> bool {
unsafe { v8__Value__IsFunction(self) }
}
pub fn is_array(&self) -> bool {
unsafe { v8__Value__IsArray(self) }
}
pub fn is_object(&self) -> bool {
unsafe { v8__Value__IsObject(self) }
}
pub fn is_big_int(&self) -> bool {
unsafe { v8__Value__IsBigInt(self) }
}
pub fn is_boolean(&self) -> bool {
unsafe { v8__Value__IsBoolean(self) }
}
pub fn is_number(&self) -> bool {
unsafe { v8__Value__IsNumber(self) }
}
pub fn is_external(&self) -> bool {
unsafe { v8__Value__IsExternal(self) }
}
pub fn is_int32(&self) -> bool {
unsafe { v8__Value__IsInt32(self) }
}
pub fn is_uint32(&self) -> bool {
unsafe { v8__Value__IsUint32(self) }
}
pub fn is_date(&self) -> bool {
unsafe { v8__Value__IsDate(self) }
}
pub fn is_arguments_object(&self) -> bool {
unsafe { v8__Value__IsArgumentsObject(self) }
}
pub fn is_big_int_object(&self) -> bool {
unsafe { v8__Value__IsBigIntObject(self) }
}
pub fn is_boolean_object(&self) -> bool {
unsafe { v8__Value__IsBooleanObject(self) }
}
pub fn is_number_object(&self) -> bool {
unsafe { v8__Value__IsNumberObject(self) }
}
pub fn is_string_object(&self) -> bool {
unsafe { v8__Value__IsStringObject(self) }
}
pub fn is_symbol_object(&self) -> bool {
unsafe { v8__Value__IsSymbolObject(self) }
}
pub fn is_native_error(&self) -> bool {
unsafe { v8__Value__IsNativeError(self) }
}
pub fn is_reg_exp(&self) -> bool {
unsafe { v8__Value__IsRegExp(self) }
}
pub fn is_async_function(&self) -> bool {
unsafe { v8__Value__IsAsyncFunction(self) }
}
pub fn is_generator_function(&self) -> bool {
unsafe { v8__Value__IsGeneratorFunction(self) }
}
pub fn is_promise(&self) -> bool {
unsafe { v8__Value__IsPromise(self) }
}
pub fn is_map(&self) -> bool {
unsafe { v8__Value__IsMap(self) }
}
pub fn is_set(&self) -> bool {
unsafe { v8__Value__IsSet(self) }
}
pub fn is_map_iterator(&self) -> bool {
unsafe { v8__Value__IsMapIterator(self) }
}
pub fn is_set_iterator(&self) -> bool {
unsafe { v8__Value__IsSetIterator(self) }
}
pub fn is_weak_map(&self) -> bool {
unsafe { v8__Value__IsWeakMap(self) }
}
pub fn is_weak_set(&self) -> bool {
unsafe { v8__Value__IsWeakSet(self) }
}
pub fn is_array_buffer(&self) -> bool {
unsafe { v8__Value__IsArrayBuffer(self) }
}
pub fn is_array_buffer_view(&self) -> bool {
unsafe { v8__Value__IsArrayBufferView(self) }
}
pub fn is_typed_array(&self) -> bool {
unsafe { v8__Value__IsTypedArray(self) }
}
pub fn is_uint8_array(&self) -> bool {
unsafe { v8__Value__IsUint8Array(self) }
}
pub fn is_uint8_clamped_array(&self) -> bool {
unsafe { v8__Value__IsUint8ClampedArray(self) }
}
pub fn is_int8_array(&self) -> bool {
unsafe { v8__Value__IsInt8Array(self) }
}
pub fn is_uint16_array(&self) -> bool {
unsafe { v8__Value__IsUint16Array(self) }
}
pub fn is_int16_array(&self) -> bool {
unsafe { v8__Value__IsInt16Array(self) }
}
pub fn is_uint32_array(&self) -> bool {
unsafe { v8__Value__IsUint32Array(self) }
}
pub fn is_int32_array(&self) -> bool {
unsafe { v8__Value__IsInt32Array(self) }
}
pub fn is_float32_array(&self) -> bool {
unsafe { v8__Value__IsFloat32Array(self) }
}
pub fn is_float64_array(&self) -> bool {
unsafe { v8__Value__IsFloat64Array(self) }
}
pub fn is_big_int64_array(&self) -> bool {
unsafe { v8__Value__IsBigInt64Array(self) }
}
pub fn is_big_uint64_array(&self) -> bool {
unsafe { v8__Value__IsBigUint64Array(self) }
}
pub fn is_data_view(&self) -> bool {
unsafe { v8__Value__IsDataView(self) }
}
pub fn is_shared_array_buffer(&self) -> bool {
unsafe { v8__Value__IsSharedArrayBuffer(self) }
}
pub fn is_proxy(&self) -> bool {
unsafe { v8__Value__IsProxy(self) }
}
pub fn is_wasm_module_object(&self) -> bool {
unsafe { v8__Value__IsWasmModuleObject(self) }
}
pub fn is_module_namespace_object(&self) -> bool {
unsafe { v8__Value__IsModuleNamespaceObject(self) }
}
pub fn strict_equals<'sc>(&self, that: Local<'sc, Value>) -> bool {
unsafe { v8__Value__StrictEquals(self, &that) }
}
pub fn same_value<'sc>(&self, that: Local<'sc, Value>) -> bool {
unsafe { v8__Value__SameValue(self, &that) }
}
pub fn to_big_int<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<Local<'sc, BigInt>> {
scope.get_current_context().and_then(|context| unsafe {
Local::from_raw(v8__Value__ToBigInt(self, context))
})
}
pub fn to_number<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<Local<'sc, Number>> {
scope.get_current_context().and_then(|context| unsafe {
Local::from_raw(v8__Value__ToNumber(self, context))
})
}
pub fn to_string<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<Local<'sc, String>> {
scope.get_current_context().and_then(|context| unsafe {
Local::from_raw(v8__Value__ToString(self, context))
})
}
pub fn to_detail_string<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<Local<'sc, String>> {
scope.get_current_context().and_then(|context| unsafe {
Local::from_raw(v8__Value__ToDetailString(self, context))
})
}
pub fn to_object<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<Local<'sc, Object>> {
scope.get_current_context().and_then(|context| unsafe {
Local::from_raw(v8__Value__ToObject(self, context))
})
}
pub fn to_integer<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<Local<'sc, Integer>> {
scope.get_current_context().and_then(|context| unsafe {
Local::from_raw(v8__Value__ToInteger(self, context))
})
}
pub fn to_uint32<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<Local<'sc, Uint32>> {
scope.get_current_context().and_then(|context| unsafe {
Local::from_raw(v8__Value__ToUint32(self, context))
})
}
pub fn to_int32<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<Local<'sc, Int32>> {
scope.get_current_context().and_then(|context| unsafe {
Local::from_raw(v8__Value__ToInt32(self, context))
})
}
pub fn number_value<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<f64> {
scope.get_current_context().and_then(|context| unsafe {
let mut out = Maybe::<f64>::default();
v8__Value__NumberValue(self, context, &mut out);
out.into()
})
}
pub fn integer_value<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<i64> {
scope.get_current_context().and_then(|context| unsafe {
let mut out = Maybe::<i64>::default();
v8__Value__IntegerValue(self, context, &mut out);
out.into()
})
}
pub fn uint32_value<'sc>(
&self,
scope: &mut impl ToLocal<'sc>,
) -> Option<u32> {
scope.get_current_context().and_then(|context| unsafe {
let mut out = Maybe::<u32>::default();
v8__Value__Uint32Value(self, context, &mut out);
out.into()
})
}
pub fn int32_value<'sc>(&self, scope: &mut impl ToLocal<'sc>) -> Option<i32> {
scope.get_current_context().and_then(|context| unsafe {
let mut out = Maybe::<i32>::default();
v8__Value__Int32Value(self, context, &mut out);
out.into()
})
}
}