[oden-js] ArrayBuffer values

This commit is contained in:
John Doty 2023-06-30 06:26:53 -07:00
parent b77e7eba3e
commit f7ed78ce3b
2 changed files with 42 additions and 0 deletions

View file

@ -323,6 +323,20 @@ impl ValueRef {
))
}
}
/// Get the underlying bytes for a an ArrayBuffer object. Obviously it
/// only works if this is an un-detached ArrayBuffer value.
pub fn get_array_buffer<'a>(&'a self, ctx: &ContextRef) -> Result<&'a [u8]> {
unsafe {
let mut size: usize = 0;
let buffer = sys::JS_GetArrayBuffer(ctx.ctx, &mut size as *mut usize, self.val);
if buffer.is_null() {
Err(ctx.exception_error())
} else {
Ok(std::slice::from_raw_parts(buffer, size))
}
}
}
}
impl fmt::Debug for ValueRef {