Skip to content

Commit

Permalink
Fix misuse of mozjs_sys::Handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Arshia001 committed Feb 28, 2024
1 parent 0531122 commit 5882c4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions runtime/src/event_loop/microtasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ffi::c_void;
use mozjs::glue::JobQueueTraps;
use mozjs::jsapi::{CurrentGlobalOrNull, Handle, JobQueueIsEmpty, JobQueueMayNotBeEmpty, JSContext, JSFunction, JSObject};

use ion::{Context, ErrorReport, Function, Object, TracedHeap};
use ion::{Context, ErrorReport, Function, Local, Object, TracedHeap};

use crate::ContextExt;

Expand Down Expand Up @@ -85,7 +85,10 @@ unsafe extern "C" fn enqueue_promise_job(
let event_loop = unsafe { &mut cx.get_private().event_loop };
let microtasks = event_loop.microtasks.as_mut().unwrap();
if !job.is_null() {
microtasks.enqueue(cx, Microtask::Promise(TracedHeap::new(job.get())))
microtasks.enqueue(
cx,
Microtask::Promise(TracedHeap::from_local(unsafe { &Local::from_raw_handle(job) })),
)
} else {
microtasks.enqueue(cx, Microtask::None)
};
Expand Down
5 changes: 3 additions & 2 deletions runtime/src/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::task::Poll;
use futures::future::poll_fn;
use mozjs::jsapi::{Handle, JSContext, JSObject, PromiseRejectionHandlingState};

use ion::{Context, ErrorReport, Promise, TracedHeap};
use ion::{Context, ErrorReport, Local, Promise, TracedHeap};
use ion::format::{Config, format_value};

use crate::ContextExt;
Expand Down Expand Up @@ -90,8 +90,9 @@ pub(crate) unsafe extern "C" fn promise_rejection_tracker_callback(
) {
let cx = unsafe { &Context::new_unchecked(cx) };
let unhandled = &mut unsafe { cx.get_private() }.event_loop.unhandled_rejections;
let promise = unsafe { Local::from_raw_handle(promise) };
match state {
PromiseRejectionHandlingState::Unhandled => unhandled.push_back(TracedHeap::new(promise.get())),
PromiseRejectionHandlingState::Unhandled => unhandled.push_back(TracedHeap::from_local(&promise)),
PromiseRejectionHandlingState::Handled => {
let idx = unhandled.iter().position(|unhandled| unhandled.get() == promise.get());
if let Some(idx) = idx {
Expand Down

0 comments on commit 5882c4a

Please sign in to comment.