Skip to content

Commit

Permalink
Fix reference mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
DelSkayn committed Jul 13, 2023
1 parent 6c734c9 commit 6af0926
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .gdb_history
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
r
bt
bt
r
bt
r
bt
r
gdb
bt
6 changes: 3 additions & 3 deletions core/src/context/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ unsafe impl<R> Send for WithFuture<'_, R> {}
/// // With the macro you can borrow the environment.
/// *some_var_ref += 1;
///
/// let delay = Function::new(ctx,Async(delay))
/// let delay = Function::new(ctx.clone(),Async(delay))
/// .unwrap()
/// .with_name("print")
/// .unwrap();
Expand Down Expand Up @@ -220,15 +220,15 @@ impl AsyncContext {
/// future.
pub async fn async_with<F, R>(&self, f: F) -> R
where
F: for<'a, 'js> FnOnce(&'a Ctx<'js>) -> Pin<Box<dyn Future<Output = R> + 'js + Send>>
F: for<'js> FnOnce(Ctx<'js>) -> Pin<Box<dyn Future<Output = R> + 'js + Send>>
+ ParallelSend,
R: ParallelSend,
{
let future = {
let guard = self.rt.inner.lock().await;
guard.update_stack_top();
let ctx = unsafe { Ctx::new_async(self) };
f(&ctx)
f(ctx)
};
WithFuture {
future,
Expand Down
5 changes: 2 additions & 3 deletions core/src/context/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ impl<'js> Ctx<'js> {
/// lifetime which can't be coerced to a lifetime outside the scope of the lock of to the
/// lifetime of another runtime.
pub unsafe fn from_ptr_invariant(ctx: NonNull<qjs::JSContext>, inv: Invariant<'js>) -> Self {
dbg!("a");
unsafe { qjs::JS_DupContext(ctx.as_ptr()) };
Ctx { ctx, _marker: inv }
}
Expand All @@ -99,7 +98,6 @@ impl<'js> Ctx<'js> {
}

pub(crate) unsafe fn from_ptr(ctx: *mut qjs::JSContext) -> Self {
dbg!("b");
unsafe { qjs::JS_DupContext(ctx) };
let ctx = NonNull::new_unchecked(ctx);
Ctx {
Expand All @@ -109,7 +107,7 @@ impl<'js> Ctx<'js> {
}

pub(crate) unsafe fn new(ctx: &'js Context) -> Self {
dbg!("c");
unsafe { qjs::JS_DupContext(ctx.ctx.as_ptr()) };
Ctx {
ctx: ctx.ctx,
_marker: Invariant::new(),
Expand All @@ -118,6 +116,7 @@ impl<'js> Ctx<'js> {

#[cfg(feature = "futures")]
pub(crate) unsafe fn new_async(ctx: &'js AsyncContext) -> Self {
unsafe { qjs::JS_DupContext(ctx.ctx.as_ptr()) };
Ctx {
ctx: ctx.ctx,
_marker: Invariant::new(),
Expand Down
6 changes: 3 additions & 3 deletions core/src/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ impl_outlive!(
/// # let rt = Runtime::new().unwrap();
/// # let ctx = Context::full(&rt).unwrap();
/// let func = ctx.with(|ctx| {
/// Persistent::save(ctx, ctx.eval::<Function, _>("a => a + 1").unwrap())
/// Persistent::save(&ctx, ctx.eval::<Function, _>("a => a + 1").unwrap())
/// });
/// let res: i32 = ctx.with(|ctx| {
/// let func = func.clone().restore(ctx).unwrap();
/// let func = func.clone().restore(&ctx).unwrap();
/// func.call((2,)).unwrap()
/// });
/// assert_eq!(res, 3);
/// let res: i32 = ctx.with(|ctx| {
/// let func = func.restore(ctx).unwrap();
/// let func = func.restore(&ctx).unwrap();
/// func.call((0,)).unwrap()
/// });
/// assert_eq!(res, 1);
Expand Down
2 changes: 1 addition & 1 deletion core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ impl<'js> CaughtError<'js> {
/// # ctx.with(|ctx|{
/// use rquickjs::CatchResultExt;
///
/// if let Err(CaughtError::Value(err)) = ctx.eval::<(),_>("throw 3").catch(ctx){
/// if let Err(CaughtError::Value(err)) = ctx.eval::<(),_>("throw 3").catch(&ctx){
/// assert_eq!(err.as_int(),Some(3));
/// # }else{
/// # panic!()
Expand Down
1 change: 1 addition & 0 deletions core/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl<'js> Value<'js> {
#[inline]
pub(crate) fn into_js_value(self) -> qjs::JSValue {
let value = self.value;
unsafe { qjs::JS_FreeContext(self.ctx.as_ptr()) };
mem::forget(self);
value
}
Expand Down

0 comments on commit 6af0926

Please sign in to comment.