Skip to content

Commit

Permalink
refactor: dont save a ref to js runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mayant15 authored and amitksingh1490 committed May 4, 2024
1 parent 7036e0a commit 5b9dce3
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/cli/javascript/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ use super::request_filter::{Command, Event};
use super::JsRequest;
use crate::{blueprint, WorkerIO};

struct LocalRuntime {
context: Context,

// NOTE: This doesn't need to be accessed directly right now but context holds a
// reference to it, so make sure that this is not dropped
_js_runtime: rquickjs::Runtime,
}
struct LocalRuntime(Context);

thread_local! {
// Practically only one JS runtime is created because CHANNEL_RUNTIME is single threaded.
Expand Down Expand Up @@ -57,7 +51,7 @@ impl LocalRuntime {
})?;

tracing::debug!("JS Runtime created: {:?}", thread::current().name());
Ok(Self { context, _js_runtime: js_runtime })
Ok(Self(context))
}
}

Expand Down Expand Up @@ -110,7 +104,7 @@ fn call(name: String, event: Event) -> anyhow::Result<Option<Command>> {
let runtime = cell
.get_mut()
.ok_or(anyhow::anyhow!("JS runtime not initialized"))?;
runtime.context.with(|ctx| match event {
runtime.0.with(|ctx| match event {
Event::Request(req) => {
let fn_as_value = ctx
.globals()
Expand Down

0 comments on commit 5b9dce3

Please sign in to comment.