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

Code before:
use crate::dom::globalscope::GlobalScope;
use crate::dom::workerglobalscope::WorkerGlobalScope;
use crate::script_runtime::JSContext;

/// The maximum object depth logged by console methods.
const MAX_LOG_DEPTH: usize = 10;
/// The maximum elements in an object logged by console methods.
const MAX_LOG_CHILDREN: usize = 15;

/// <https://developer.mozilla.org/en-US/docs/Web/API/Console>
#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
pub(crate) struct Console;

impl Console {
    #[expect(unsafe_code)]
    fn build_message(level: ConsoleLogLevel) -> ConsoleMessageBuilder {
        let cx = GlobalScope::get_cx();
        let caller = unsafe { describe_scripted_caller(*cx) }.unwrap_or_default();

        ConsoleMessageBuilder::new(level, caller.filename, caller.line, caller.col)
    }

    /// Helper to send a message that only consists of a single string
    fn send_string_message(global: &GlobalScope, level: ConsoleLogLevel, message: String) {
        let prefix = global.current_group_label().unwrap_or_default();
        let formatted_message = format!("{}{}", prefix, message);

        Self::send_to_embedder(global, level.clone(), formatted_message);

        let mut builder = Self::build_message(level);
        builder.add_argument(message.into());
        let log_message = builder.finish();

        Self::send_to_devtools(global, log_message);
    }

    fn method(
        global: &GlobalScope,
        level: ConsoleLogLevel,
        messages: Vec<HandleValue>,
        include_stacktrace: IncludeStackTrace,
    ) {
        let cx = GlobalScope::get_cx();

        let mut log: ConsoleMessageBuilder = Console::build_message(level.clone());
        for message in &messages {
            log.add_argument(console_argument_from_handle_value(cx, *message));
        }

        if include_stacktrace == IncludeStackTrace::Yes {
            log.attach_stack_trace(get_js_stack(*GlobalScope::get_cx()));

Review comment (suggestion):
```suggestion
        let formatted_message = format!("{prefix}{message}");
```

Code after:
use crate::dom::globalscope::GlobalScope;
use crate::dom::workerglobalscope::WorkerGlobalScope;
use crate::script_runtime::JSContext;

/// The maximum object depth logged by console methods.
const MAX_LOG_DEPTH: usize = 10;
/// The maximum elements in an object logged by console methods.
const MAX_LOG_CHILDREN: usize = 15;

/// <https://developer.mozilla.org/en-US/docs/Web/API/Console>
#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
pub(crate) struct Console;

impl Console {
    #[expect(unsafe_code)]
    fn build_message(level: ConsoleLogLevel) -> ConsoleMessageBuilder {
        let cx = GlobalScope::get_cx();
        let caller = unsafe { describe_scripted_caller(*cx) }.unwrap_or_default();

        ConsoleMessageBuilder::new(level, caller.filename, caller.line, caller.col)
    }

    /// Helper to send a message that only consists of a single string
    fn send_string_message(global: &GlobalScope, level: ConsoleLogLevel, message: String) {
        let prefix = global.current_group_label().unwrap_or_default();
        let formatted_message = format!("{prefix}{message}");

        Self::send_to_embedder(global, level.clone(), formatted_message);

        let mut builder = Self::build_message(level);
        builder.add_argument(message.into());
        let log_message = builder.finish();

        Self::send_to_devtools(global, log_message);
    }

    fn method(
        global: &GlobalScope,
        level: ConsoleLogLevel,
        messages: Vec<HandleValue>,
        include_stacktrace: IncludeStackTrace,
    ) {
        let cx = GlobalScope::get_cx();

        let mut log: ConsoleMessageBuilder = Console::build_message(level.clone());
        for message in &messages {
            log.add_argument(console_argument_from_handle_value(cx, *message));
        }

        if include_stacktrace == IncludeStackTrace::Yes {
            log.attach_stack_trace(get_js_stack(*GlobalScope::get_cx()));