[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

@ -1,6 +1,6 @@
use crate::{AtomRef, ContextRef, Error, Result, Runtime, RustFunction};
use oden_js_sys as sys;
use std::ffi::{CStr, CString};
use std::ffi::CStr;
use std::fmt;
use std::ops::{Deref, DerefMut};
@ -312,21 +312,6 @@ impl ValueRef {
Ok(result)
}
pub fn get_module_export(&self, ctx: &ContextRef, export: &str) -> Result<Value> {
if self.value_type() != ValueType::Module {
return Err(Error::InvalidType {
expected: ValueType::Bool,
found: self.value_type(),
});
}
let c_value = CString::new(export)?;
unsafe {
let module = sys::JS_VALUE_GET_PTR(self.val) as *mut sys::JSModuleDef;
ctx.check_exception(sys::JS_GetModuleExport(ctx.ctx, module, c_value.as_ptr()))
}
}
pub fn call(&self, ctx: &ContextRef) -> Result<Value> {
unsafe {
ctx.check_exception(sys::JS_Call(
@ -414,7 +399,7 @@ impl fmt::Debug for Value {
#[cfg(test)]
mod tests {
use super::*;
use crate::{Context, EvalFlags, EvalType, Runtime};
use crate::{Context, EvalFlags, Runtime};
#[test]
fn value_type() {
@ -438,9 +423,7 @@ mod tests {
];
for (expr, expected) in tests.into_iter() {
let val = ctx
.eval(expr, "script", EvalType::Global, EvalFlags::STRICT)
.unwrap();
let val = ctx.eval(expr, "script", EvalFlags::STRICT).unwrap();
assert_eq!(*expected, val.value_type(), "for {}", expr);
}