From e908964fc43a643e76ece94942c0e6857e624e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 21 Jul 2023 17:42:18 +0200 Subject: [PATCH] feat: Add v8::Value::type_repr() (#1285) --- src/value.rs | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/value.rs b/src/value.rs index 1ad867e7..0fa8aee9 100644 --- a/src/value.rs +++ b/src/value.rs @@ -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" + } + } }