Starting to mess with promises
Going to want async IO, I think. And it's a fun detail that I guess I'm in charge of deciding when to run promise completion functions. :D
This commit is contained in:
parent
c1d86676c3
commit
5be0ffa08f
7 changed files with 251 additions and 74 deletions
|
|
@ -310,14 +310,16 @@ impl ValueRef {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn call(&self, ctx: &ContextRef) -> Result<Value> {
|
||||
pub fn call(&self, ctx: &ContextRef, args: &[&ValueRef]) -> Result<Value> {
|
||||
// TODO: There *must* be a way to avoid this allocation.
|
||||
let mut args: Vec<sys::JSValue> = args.iter().map(|v| v.val).collect();
|
||||
unsafe {
|
||||
ctx.check_exception(sys::JS_Call(
|
||||
ctx.ctx,
|
||||
self.val,
|
||||
sys::JS_MakeUndefined(),
|
||||
0,
|
||||
std::ptr::null_mut(),
|
||||
args.len() as i32,
|
||||
args.as_mut_ptr(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
@ -345,9 +347,16 @@ impl Value {
|
|||
/// the runtime of the specified context, if not the context itself. This
|
||||
/// function makes no attempt to validate this.
|
||||
pub(crate) fn from_raw(val: sys::JSValue, ctx: &ContextRef) -> Self {
|
||||
Value::from_raw_rt(
|
||||
val,
|
||||
Runtime::from_raw(unsafe { sys::JS_GetRuntime(ctx.ctx) }),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn from_raw_rt(val: sys::JSValue, rt: Runtime) -> Self {
|
||||
Value {
|
||||
value: ValueRef::from_raw(val),
|
||||
rt: Runtime::from_raw(unsafe { sys::JS_GetRuntime(ctx.ctx) }),
|
||||
rt,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -394,6 +403,15 @@ impl fmt::Debug for Value {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clone for Value {
|
||||
fn clone(&self) -> Self {
|
||||
unsafe {
|
||||
sys::JS_DupValueRT(self.rt.rt, self.val);
|
||||
}
|
||||
Value::from_raw_rt(self.val, self.rt.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue