Skip to content

Commit

Permalink
Merge pull request #1008 from neon-bindings/kv/to-future-fix
Browse files Browse the repository at this point in the history
Avoid leaving a dangling future when handling a rejection in JsPromise::to_future
  • Loading branch information
kjvalencik authored Nov 27, 2023
2 parents 910a548 + f8cedab commit a6b4d13
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
5 changes: 1 addition & 4 deletions crates/neon/src/handle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ pub struct Handle<'a, V: Value + 'a> {

impl<'a, V: Value> Clone for Handle<'a, V> {
fn clone(&self) -> Self {
Self {
value: self.value,
phantom: PhantomData,
}
*self
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/neon/src/types_impl/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ unsafe fn maybe_external_deref<'a>(env: Env, local: raw::Local) -> Option<&'a Bo
// Custom `Clone` implementation since `T` might not be `Clone`
impl<T: 'static> Clone for JsBoxInner<T> {
fn clone(&self) -> Self {
Self {
local: self.local,
raw_data: self.raw_data,
}
*self
}
}

Expand Down
8 changes: 5 additions & 3 deletions crates/neon/src/types_impl/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ impl JsPromise {
+ 'static,
{
let then = self.get::<JsFunction, _, _>(cx, "then")?;
let catch = self.get::<JsFunction, _, _>(cx, "catch")?;

let (tx, rx) = oneshot::channel();
let take_state = {
Expand Down Expand Up @@ -235,8 +234,11 @@ impl JsPromise {
}
})?;

then.exec(cx, Handle::new_internal(Self(self.0)), [resolve.upcast()])?;
catch.exec(cx, Handle::new_internal(Self(self.0)), [reject.upcast()])?;
then.exec(
cx,
Handle::new_internal(Self(self.0)),
[resolve.upcast(), reject.upcast()],
)?;

Ok(JsFuture { rx })
}
Expand Down

0 comments on commit a6b4d13

Please sign in to comment.