[oden-js] Fix cross-platform conversions
Lots of places were assuming that bool and c int were interchangeable, but of course on windows a c int is 32 bits and that confused everybody. Tighten up the definitions in static-functions, which causes us to fix boolean conversion. Also add tests for boolean conversion, and also add better debug formatting of JS values.
This commit is contained in:
parent
0cb5944d0a
commit
6200ed31b6
5 changed files with 82 additions and 31 deletions
|
|
@ -7,9 +7,34 @@ include!("static-functions.rs");
|
|||
|
||||
use std::fmt;
|
||||
|
||||
fn tag_name(tag: i64) -> &'static str {
|
||||
match tag.try_into() {
|
||||
Ok(tag) => match tag {
|
||||
JS_TAG_BIG_DECIMAL => "JS_TAG_BIG_DECIMAL",
|
||||
JS_TAG_BIG_INT => "JS_TAG_BIG_INT",
|
||||
JS_TAG_BIG_FLOAT => "JS_TAG_BIG_FLOAT",
|
||||
JS_TAG_SYMBOL => "JS_TAG_SYMBOL",
|
||||
JS_TAG_MODULE => "JS_TAG_MODULE",
|
||||
JS_TAG_FUNCTION_BYTECODE => "JS_TAG_FUNCTION_BYTECODE",
|
||||
JS_TAG_STRING => "JS_TAG_STRING",
|
||||
JS_TAG_OBJECT => "JS_TAG_OBJECT",
|
||||
JS_TAG_INT => "JS_TAG_INT",
|
||||
JS_TAG_BOOL => "JS_TAG_BOOL",
|
||||
JS_TAG_NULL => "JS_TAG_NULL",
|
||||
JS_TAG_UNDEFINED => "JS_TAG_UNDEFINED",
|
||||
JS_TAG_UNINITIALIZED => "JS_TAG_UNINITIALIZED",
|
||||
JS_TAG_CATCH_OFFSET => "JS_TAG_CATCH_OFFSET",
|
||||
JS_TAG_EXCEPTION => "JS_TAG_EXCEPTION",
|
||||
JS_TAG_FLOAT64 => "JS_TAG_FLOAT64",
|
||||
_ => "???",
|
||||
},
|
||||
Err(_) => "???",
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for JSValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "JS[{}", self.tag)?;
|
||||
write!(f, "JS[{} ({})", tag_name(self.tag), self.tag)?;
|
||||
if self.tag < 0 {
|
||||
write!(f, " {:?}]", unsafe { self.u.ptr })
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue