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

Catch panics in tasks and convert to rejections #813

Merged
merged 8 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove unnecessary transmute
  • Loading branch information
kjvalencik committed Oct 5, 2021
commit f8f556a1b67350f3f76a07c2d0a99c43b18ef927
6 changes: 6 additions & 0 deletions src/context/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ pub struct Env(raw::Isolate);
#[derive(Clone, Copy)]
pub struct Env(raw::Env);

impl From<raw::Env> for Env {
fn from(env: raw::Env) -> Self {
Self(env)
}
}

thread_local! {
#[allow(unused)]
pub(crate) static IS_RUNNING: RefCell<bool> = RefCell::new(false);
Expand Down
8 changes: 2 additions & 6 deletions src/event/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ where
O: Send + 'static,
D: FnOnce(&mut TaskContext, O) -> NeonResult<()> + Send + 'static,
{
let env = unsafe { std::mem::transmute(env) };

TaskContext::with_context(env, move |mut cx| {
TaskContext::with_context(env.into(), move |mut cx| {
let _ = callback(&mut cx, output);
});
}
Expand Down Expand Up @@ -146,9 +144,7 @@ where
for<'b> D: FnOnce(&mut TaskContext<'b>, O) -> JsResult<'b, V> + Send + 'static,
V: Value,
{
let env = unsafe { std::mem::transmute(env) };

TaskContext::with_context(env, move |mut cx| {
TaskContext::with_context(env.into(), move |mut cx| {
match cx.try_catch_internal(move |cx| complete(cx, output)) {
Ok(value) => deferred.resolve(&mut cx, value),
Err(err) => deferred.reject(&mut cx, err),
Expand Down