[oden] Hot-reload script files
This commit is contained in:
parent
642ced45f8
commit
a850c3cc58
7 changed files with 241 additions and 9 deletions
|
|
@ -337,6 +337,42 @@ impl ValueRef {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialize this value into a byte array. Consume the byte array with
|
||||
/// `ContextRef::deserialize()`.
|
||||
///
|
||||
/// NOTE: The serialized value is only good for this exact version of
|
||||
/// QuickJS- do *not* expect to be able to save it to disk and
|
||||
/// re-load it. This is for more ephemeral usage: passing values
|
||||
/// between threads, etc.
|
||||
///
|
||||
/// NOTE: In theory if we wanted to just serialize a message we could
|
||||
/// avoid a memory copy; we copy here to avoid keeping the runtime
|
||||
/// alive, which we would have to do in order to free the buffer
|
||||
/// correctly. If we were willing to keep the runtime alive...
|
||||
///
|
||||
/// TODO: We do not have support for SharedArrayBuffers here, which would
|
||||
/// let us use this function to pass large buffers between Runtime
|
||||
/// instances, like on different threads, without copying. What a
|
||||
/// pity.
|
||||
pub fn serialize(&self, ctx: &ContextRef) -> Result<Vec<u8>> {
|
||||
unsafe {
|
||||
let mut size = 0;
|
||||
let data = sys::JS_WriteObject(
|
||||
ctx.ctx,
|
||||
&mut size,
|
||||
self.val,
|
||||
sys::JS_WRITE_OBJ_REFERENCE as i32,
|
||||
);
|
||||
if data.is_null() {
|
||||
Err(ctx.exception_error())
|
||||
} else {
|
||||
let result = std::slice::from_raw_parts(data, size).to_vec();
|
||||
sys::js_free(ctx.ctx, data as *mut std::ffi::c_void);
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ValueRef {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue