Skip to content

Commit 77651a2

Browse files
committed
update
1 parent 52b88cf commit 77651a2

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

cli/tools/repl/session.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
22

3-
use std::cell::RefCell;
43
use std::sync::Arc;
54

65
use deno_ast::diagnostics::Diagnostic;
@@ -84,11 +83,6 @@ fn comment_source_to_position_range(
8483
}
8584
}
8685

87-
thread_local! {
88-
/// We store functions used in the repl on this object because
89-
/// the user might modify the `Deno` global or delete it outright.
90-
pub static REPL_INTERNAL_OBJECT_ID: RefCell<Option<RemoteObjectId>> = const { RefCell::new(None) };
91-
}
9286
fn get_prelude() -> String {
9387
r#"(() => {
9488
const repl_internal = {
@@ -177,6 +171,7 @@ struct ReplJsxState {
177171
}
178172

179173
pub struct ReplSession {
174+
internal_object_id: Option<RemoteObjectId>,
180175
npm_installer: Option<Arc<NpmInstaller>>,
181176
resolver: Arc<CliResolver>,
182177
pub worker: MainWorker,
@@ -264,6 +259,7 @@ impl ReplSession {
264259
.transpile
265260
.use_ts_decorators;
266261
let mut repl_session = ReplSession {
262+
internal_object_id: None,
267263
npm_installer,
268264
resolver,
269265
worker,
@@ -294,7 +290,7 @@ impl ReplSession {
294290

295291
// inject prelude
296292
let evaluated = repl_session.evaluate_expression(&get_prelude()).await?;
297-
REPL_INTERNAL_OBJECT_ID.replace(evaluated.result.object_id);
293+
repl_session.internal_object_id = evaluated.result.object_id;
298294

299295
Ok(repl_session)
300296
}
@@ -308,7 +304,7 @@ impl ReplSession {
308304

309305
pub async fn closing(&mut self) -> Result<bool, AnyError> {
310306
let result = self
311-
.call_function_on_args_internal(
307+
.call_function_on_repl_internal_obj(
312308
r#"function () { return this.closed; }"#.to_string(),
313309
&[],
314310
)
@@ -503,7 +499,7 @@ impl ReplSession {
503499
function_declaration:
504500
r#"function (object) { this.lastThrownError = object; }"#
505501
.to_string(),
506-
object_id: REPL_INTERNAL_OBJECT_ID.with_borrow(Clone::clone),
502+
object_id: self.internal_object_id.clone(),
507503
arguments: Some(vec![error.into()]),
508504
silent: None,
509505
return_by_value: None,
@@ -529,7 +525,7 @@ impl ReplSession {
529525
"Runtime.callFunctionOn",
530526
Some(cdp::CallFunctionOnArgs {
531527
function_declaration: r#"function (object) { this.lastEvalResult = object; }"#.to_string(),
532-
object_id: REPL_INTERNAL_OBJECT_ID.with_borrow(Clone::clone),
528+
object_id: self.internal_object_id.clone(),
533529
arguments: Some(vec![evaluate_result.into()]),
534530
silent: None,
535531
return_by_value: None,
@@ -581,7 +577,7 @@ impl ReplSession {
581577
Ok(response)
582578
}
583579

584-
pub async fn call_function_on_args_internal(
580+
pub async fn call_function_on_repl_internal_obj(
585581
&mut self,
586582
function_declaration: String,
587583
args: &[cdp::RemoteObject],
@@ -597,7 +593,7 @@ impl ReplSession {
597593
"Runtime.callFunctionOn",
598594
Some(cdp::CallFunctionOnArgs {
599595
function_declaration,
600-
object_id: REPL_INTERNAL_OBJECT_ID.with_borrow(Clone::clone),
596+
object_id: self.internal_object_id.clone(),
601597
arguments,
602598
silent: None,
603599
return_by_value: None,
@@ -624,7 +620,7 @@ impl ReplSession {
624620
// consistent with the previous implementation we just get the preview result from
625621
// Deno.inspectArgs.
626622
let response = self
627-
.call_function_on_args_internal(
623+
.call_function_on_repl_internal_obj(
628624
r#"function (object) {
629625
try {
630626
return this.inspectArgs(["%o", object], { colors: !this.noColor });

0 commit comments

Comments
 (0)