mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 09:41:33 +00:00
Implement Debug for JsValue
This commit is contained in:
28
src/lib.rs
28
src/lib.rs
@ -17,6 +17,7 @@ extern crate serde_json;
|
||||
extern crate wasm_bindgen_macro;
|
||||
|
||||
use core::cell::UnsafeCell;
|
||||
use core::fmt;
|
||||
use core::ops::Deref;
|
||||
use core::ptr;
|
||||
|
||||
@ -363,6 +364,33 @@ impl Clone for JsValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for JsValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(n) = self.as_f64() {
|
||||
return n.fmt(f)
|
||||
}
|
||||
#[cfg(feature = "std")]
|
||||
{
|
||||
if let Some(n) = self.as_string() {
|
||||
return n.fmt(f)
|
||||
}
|
||||
}
|
||||
if let Some(n) = self.as_bool() {
|
||||
return n.fmt(f)
|
||||
}
|
||||
if self.is_null() {
|
||||
return fmt::Display::fmt("null", f)
|
||||
}
|
||||
if self.is_undefined() {
|
||||
return fmt::Display::fmt("undefined", f)
|
||||
}
|
||||
if self.is_symbol() {
|
||||
return fmt::Display::fmt("Symbol(..)", f)
|
||||
}
|
||||
fmt::Display::fmt("[object]", f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for JsValue {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
Reference in New Issue
Block a user