[oden] Grab my incomplete QuickJS wrapper

This commit is contained in:
John Doty 2023-06-17 20:44:09 -07:00
parent aa70df41a3
commit 898b1fe129
114 changed files with 244181 additions and 0 deletions

47
oden-js/src/runtime.rs Normal file
View file

@ -0,0 +1,47 @@
use oden_js_sys as sys;
#[derive(Debug)]
pub struct Runtime {
pub(crate) rt: *mut sys::JSRuntime,
}
impl Runtime {
pub fn new() -> Runtime {
let rt = unsafe { sys::JS_NewRuntime() };
Runtime { rt }
}
pub fn set_memory_limit(&mut self, limit: usize) {
unsafe {
sys::JS_SetMemoryLimit(self.rt, limit);
}
}
pub fn set_gc_threshold(&mut self, threshold: usize) {
unsafe {
sys::JS_SetGCThreshold(self.rt, threshold);
}
}
/// Pass in 0 to disable the maximum size check.
pub fn set_max_stack_size(&mut self, max_stack: usize) {
unsafe {
sys::JS_SetMaxStackSize(self.rt, max_stack);
}
}
pub fn run_gc(&mut self) {
unsafe {
sys::JS_RunGC(self.rt);
}
}
}
impl Drop for Runtime {
fn drop(&mut self) {
unsafe {
sys::JS_RunGC(self.rt);
sys::JS_FreeRuntime(self.rt);
}
}
}