Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid leaving a dangling future when handling a rejection in JsPromise::to_future #1008

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
dherman marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
dherman marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
Loading