[oden][oden-js] Rework modules

Damn this is a lot
This commit is contained in:
John Doty 2023-06-24 08:45:39 -07:00
parent aa90cea4a3
commit db8a5f8eed
12 changed files with 280 additions and 105 deletions

View file

@ -13,7 +13,7 @@ mod value;
pub use atom::{Atom, AtomRef};
pub use class::{Class, ClassID};
pub use context::{Context, ContextRef, EvalFlags, EvalType};
pub use context::{Context, ContextRef, EvalFlags};
pub use conversion::*;
pub use runtime::Runtime;
pub use value::{Value, ValueRef, ValueType};
@ -43,6 +43,8 @@ pub enum Error {
Exception(Value, String),
#[error("out of memory")]
OutOfMemory,
#[error("an io error occurred: {0}")]
IOError(std::io::Error),
}
impl From<NulError> for Error {
@ -51,10 +53,26 @@ impl From<NulError> for Error {
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::IOError(e)
}
}
pub type Result<T> = core::result::Result<T, Error>;
pub type ValueResult = core::result::Result<Value, Error>;
pub fn throw_string(context: &ContextRef, message: String) -> sys::JSValue {
pub(crate) fn throw_error(context: &ContextRef, error: Error) -> sys::JSValue {
match error {
Error::Exception(v, _) => unsafe {
sys::JS_DupValue(context.ctx, v.val);
sys::JS_Throw(context.ctx, v.val)
},
other => throw_string(context, other.to_string()),
}
}
pub(crate) fn throw_string(context: &ContextRef, message: String) -> sys::JSValue {
let ctx = context.ctx;
match context.new_string(&message) {
Ok(e) => unsafe {