summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-03-08 22:21:14 +0530
committerGitHub <noreply@github.com>2023-03-08 22:21:14 +0530
commit0cce9c2bcc9667935a571d30847e66ef5d01a196 (patch)
tree3e188f47a7c8350a3f48fe5ec3a0b256351d41b9 /core/runtime.rs
parent06a12341c66e0a44436e1178603e0f398bfae10c (diff)
feat(core): prevent isolate drop for CLI main worker (#18059)
``` Benchmark 1: deno run -A ../empty.js Time (mean ± σ): 20.5 ms ± 0.5 ms [User: 13.4 ms, System: 5.1 ms] Range (min … max): 19.8 ms … 24.0 ms 119 runs Benchmark 2: target/release/deno run -A ../empty.js Time (mean ± σ): 18.8 ms ± 0.3 ms [User: 13.0 ms, System: 4.9 ms] Range (min … max): 18.3 ms … 19.9 ms 129 runs ``` --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/runtime.rs b/core/runtime.rs
index f751138a9..456dbe828 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -93,6 +93,9 @@ pub struct JsRuntime {
event_loop_middlewares: Vec<Box<OpEventLoopFn>>,
// Marks if this is considered the top-level runtime. Used only be inspector.
is_main: bool,
+ // Marks if it's OK to leak the current isolate. Use only by the
+ // CLI main worker.
+ leak_isolate: bool,
}
pub(crate) struct DynImportModEvaluate {
@@ -305,6 +308,10 @@ pub struct RuntimeOptions {
/// Describe if this is the main runtime instance, used by debuggers in some
/// situation - like disconnecting when program finishes running.
pub is_main: bool,
+
+ /// Whether it is OK to leak the V8 isolate. Only to be used by CLI
+ /// top-level runtime.
+ pub leak_isolate: bool,
}
#[derive(Copy, Clone, PartialEq, Eq)]
@@ -338,6 +345,16 @@ impl Drop for JsRuntime {
if let Some(v8_isolate) = self.v8_isolate.as_mut() {
Self::drop_state_and_module_map(v8_isolate);
}
+ if self.leak_isolate {
+ if let Some(v8_isolate) = self.v8_isolate.take() {
+ // Clear the GothamState. This allows final env cleanup hooks to run.
+ // Note: that OpState is cloned for every OpCtx, so we can't just drop
+ // one reference to it.
+ let rc_state = self.op_state();
+ rc_state.borrow_mut().clear_state();
+ std::mem::forget(v8_isolate);
+ }
+ }
}
}
@@ -674,6 +691,7 @@ impl JsRuntime {
state: state_rc,
module_map: Some(module_map_rc),
is_main: options.is_main,
+ leak_isolate: options.leak_isolate,
};
// Init resources and ops before extensions to make sure they are