1
1
// Copyright 2018-2025 the Deno authors. MIT license.
2
2
3
- use std:: cell:: RefCell ;
4
3
use std:: sync:: Arc ;
5
4
6
5
use deno_ast:: diagnostics:: Diagnostic ;
@@ -84,11 +83,6 @@ fn comment_source_to_position_range(
84
83
}
85
84
}
86
85
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
- }
92
86
fn get_prelude ( ) -> String {
93
87
r#"(() => {
94
88
const repl_internal = {
@@ -177,6 +171,7 @@ struct ReplJsxState {
177
171
}
178
172
179
173
pub struct ReplSession {
174
+ internal_object_id : Option < RemoteObjectId > ,
180
175
npm_installer : Option < Arc < NpmInstaller > > ,
181
176
resolver : Arc < CliResolver > ,
182
177
pub worker : MainWorker ,
@@ -264,6 +259,7 @@ impl ReplSession {
264
259
. transpile
265
260
. use_ts_decorators ;
266
261
let mut repl_session = ReplSession {
262
+ internal_object_id : None ,
267
263
npm_installer,
268
264
resolver,
269
265
worker,
@@ -294,7 +290,7 @@ impl ReplSession {
294
290
295
291
// inject prelude
296
292
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 ;
298
294
299
295
Ok ( repl_session)
300
296
}
@@ -308,7 +304,7 @@ impl ReplSession {
308
304
309
305
pub async fn closing ( & mut self ) -> Result < bool , AnyError > {
310
306
let result = self
311
- . call_function_on_args_internal (
307
+ . call_function_on_repl_internal_obj (
312
308
r#"function () { return this.closed; }"# . to_string ( ) ,
313
309
& [ ] ,
314
310
)
@@ -503,7 +499,7 @@ impl ReplSession {
503
499
function_declaration :
504
500
r#"function (object) { this.lastThrownError = object; }"#
505
501
. to_string ( ) ,
506
- object_id : REPL_INTERNAL_OBJECT_ID . with_borrow ( Clone :: clone) ,
502
+ object_id : self . internal_object_id . clone ( ) ,
507
503
arguments : Some ( vec ! [ error. into( ) ] ) ,
508
504
silent : None ,
509
505
return_by_value : None ,
@@ -529,7 +525,7 @@ impl ReplSession {
529
525
"Runtime.callFunctionOn" ,
530
526
Some ( cdp:: CallFunctionOnArgs {
531
527
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 ( ) ,
533
529
arguments : Some ( vec ! [ evaluate_result. into( ) ] ) ,
534
530
silent : None ,
535
531
return_by_value : None ,
@@ -581,7 +577,7 @@ impl ReplSession {
581
577
Ok ( response)
582
578
}
583
579
584
- pub async fn call_function_on_args_internal (
580
+ pub async fn call_function_on_repl_internal_obj (
585
581
& mut self ,
586
582
function_declaration : String ,
587
583
args : & [ cdp:: RemoteObject ] ,
@@ -597,7 +593,7 @@ impl ReplSession {
597
593
"Runtime.callFunctionOn" ,
598
594
Some ( cdp:: CallFunctionOnArgs {
599
595
function_declaration,
600
- object_id : REPL_INTERNAL_OBJECT_ID . with_borrow ( Clone :: clone) ,
596
+ object_id : self . internal_object_id . clone ( ) ,
601
597
arguments,
602
598
silent : None ,
603
599
return_by_value : None ,
@@ -624,7 +620,7 @@ impl ReplSession {
624
620
// consistent with the previous implementation we just get the preview result from
625
621
// Deno.inspectArgs.
626
622
let response = self
627
- . call_function_on_args_internal (
623
+ . call_function_on_repl_internal_obj (
628
624
r#"function (object) {
629
625
try {
630
626
return this.inspectArgs(["%o", object], { colors: !this.noColor });
0 commit comments