0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-25 16:49:29 -05:00

feat: Add v8::Value::type_repr() (#1285)

This commit is contained in:
Bartek Iwańczuk 2023-07-21 17:42:18 +02:00 committed by GitHub
parent e1c403f384
commit e908964fc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -724,4 +724,92 @@ impl Value {
}
.unwrap()
}
/// Utility method that returns human readable representation of the
/// underlying value.
pub fn type_repr(&self) -> &'static str {
if self.is_module_namespace_object() {
"Module"
} else if self.is_wasm_module_object() {
"WASM module"
} else if self.is_wasm_memory_object() {
"WASM memory object"
} else if self.is_proxy() {
"Proxy"
} else if self.is_shared_array_buffer() {
"SharedArrayBuffer"
} else if self.is_data_view() {
"DataView"
} else if self.is_big_uint64_array() {
"BigUint64Array"
} else if self.is_big_int64_array() {
"BigInt64Array"
} else if self.is_float64_array() {
"Float64Array"
} else if self.is_float32_array() {
"Float32Array"
} else if self.is_int32_array() {
"Int32Array"
} else if self.is_uint32_array() {
"Uint32Array"
} else if self.is_int16_array() {
"Int16Array"
} else if self.is_uint16_array() {
"Uint16Array"
} else if self.is_int8_array() {
"Int8Array"
} else if self.is_uint8_clamped_array() {
"Uint8ClampedArray"
} else if self.is_uint8_array() {
"Uint8Array"
} else if self.is_typed_array() {
"TypedArray"
} else if self.is_array_buffer_view() {
"ArrayBufferView"
} else if self.is_array_buffer() {
"ArrayBuffer"
} else if self.is_weak_set() {
"WeakSet"
} else if self.is_weak_map() {
"WeakMap"
} else if self.is_set_iterator() {
"Set Iterator"
} else if self.is_map_iterator() {
"Map Iterator"
} else if self.is_set() {
"Set"
} else if self.is_map() {
"Map"
} else if self.is_promise() {
"Promise"
} else if self.is_generator_function() {
"Generator function"
} else if self.is_async_function() {
"Async function"
} else if self.is_reg_exp() {
"RegExp"
} else if self.is_date() {
"Date"
} else if self.is_number() {
"Number"
} else if self.is_boolean() {
"Boolean"
} else if self.is_big_int() {
"bigint"
} else if self.is_array() {
"array"
} else if self.is_function() {
"function"
} else if self.is_symbol() {
"symbol"
} else if self.is_string() {
"string"
} else if self.is_null() {
"null"
} else if self.is_undefined() {
"undefined"
} else {
"unknown"
}
}
}