Repository: servo/servo
File: components/script/script_thread.rs (Rust)

Code before:
            image_cache_sender,
            time_profiler_sender: state.time_profiler_sender,
            memory_profiler_sender: state.memory_profiler_sender,
            devtools_server_sender,
            devtools_client_to_script_thread_sender: ipc_devtools_sender,
        };

        let microtask_queue = runtime.microtask_queue.clone();
        let js_runtime = Rc::new(runtime);
        #[cfg(feature = "webgpu")]
        let gpu_id_hub = Arc::new(IdentityHub::default());

        let debugger_pipeline_id = PipelineId::new();
        let script_to_constellation_chan = ScriptToConstellationChan {
            sender: senders.pipeline_to_constellation_sender.clone(),
            // This channel is not expected to be used, so the `WebViewId` that we set here
            // does not matter.
            // TODO: Look at ways of removing the channel entirely for debugger globals.
            webview_id: TEST_WEBVIEW_ID,
            pipeline_id: debugger_pipeline_id,
        };
        let debugger_global = DebuggerGlobalScope::new(
            PipelineId::new(),
            senders.devtools_server_sender.clone(),
            senders.devtools_client_to_script_thread_sender.clone(),
            Some(debugger_devtools_receiver),
            senders.memory_profiler_sender.clone(),
            senders.time_profiler_sender.clone(),
            script_to_constellation_chan,
            senders.pipeline_to_embedder_sender.clone(),
            state.resource_threads.clone(),
            state.storage_threads.clone(),
            #[cfg(feature = "webgpu")]
            gpu_id_hub.clone(),
            &mut cx,
        );

        debugger_global.execute(CanGc::from_cx(&mut cx));

        let user_contents_for_manager_id =
            FxHashMap::from_iter(state.user_contents_for_manager_id.into_iter().map(
                |(user_content_manager_id, user_contents)| {
                    (user_content_manager_id, user_contents.into())
                },
            ));

        (
            Rc::new_cyclic(|weak_script_thread| Self {
                documents: DomRefCell::new(DocumentCollection::default()),
                last_render_opportunity_time: Default::default(),
                window_proxies: Default::default(),

Review comment (bug):
Very small nit, but we can maybe have something like this to match the senders, and remove the `let debugger_devtools_receiver` line:

```suggestion
            Some(receivers.devtools_server_receiver.clone()),
```

Code after:
        let script_to_constellation_chan = ScriptToConstellationChan {
            sender: senders.pipeline_to_constellation_sender.clone(),
            // This channel is not expected to be used, so the `WebViewId` that we set here
            // does not matter.
            // TODO: Look at ways of removing the channel entirely for debugger globals.
            webview_id: TEST_WEBVIEW_ID,
            pipeline_id: debugger_pipeline_id,
        };
        let debugger_global = DebuggerGlobalScope::new(
            PipelineId::new(),
            senders.devtools_server_sender.clone(),
            senders.devtools_client_to_script_thread_sender.clone(),
            senders.memory_profiler_sender.clone(),
            senders.time_profiler_sender.clone(),
            script_to_constellation_chan,
            senders.pipeline_to_embedder_sender.clone(),
            state.resource_threads.clone(),
            state.storage_threads.clone(),
            #[cfg(feature = "webgpu")]
            gpu_id_hub.clone(),
            &mut cx,
        );

        debugger_global.execute(&mut cx);

        let user_contents_for_manager_id =
            FxHashMap::from_iter(state.user_contents_for_manager_id.into_iter().map(
                |(user_content_manager_id, user_contents)| {
                    (user_content_manager_id, user_contents.into())
                },
            ));

        (
            Rc::new_cyclic(|weak_script_thread| {
                runtime.set_script_thread(weak_script_thread.clone());
                Self {
                    documents: DomRefCell::new(DocumentCollection::default()),
                    last_render_opportunity_time: Default::default(),
                    window_proxies: Default::default(),
                    incomplete_loads: DomRefCell::new(vec![]),
                    incomplete_parser_contexts: IncompleteParserContexts(RefCell::new(vec![])),
                    senders,
                    receivers,
                    image_cache_factory,
                    resource_threads: state.resource_threads,
                    storage_threads: state.storage_threads,
                    task_queue,
                    background_hang_monitor,
                    closing,
                    timer_scheduler: Default::default(),
                    microtask_queue,