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

Code before:
            fetch_options,
            source: source_code,
            external,
            unminified_dir: self.unminified_js_dir(),
        };
        unminify_js(&mut script);

        // Step 13. Return script.
        script
    }

    /// <https://html.spec.whatwg.org/multipage/#run-a-classic-script>
    #[expect(unsafe_code)]
    pub(crate) fn run_a_classic_script(&self, script: ClassicScript, can_gc: CanGc) -> ErrorResult {
        let cx = GlobalScope::get_cx();
        // TODO Step 1. Let settings be the settings object of script.

        // Step 2. Check if we can run script with settings. If this returns "do not run", then return NormalCompletion(empty).
        if !self.can_run_script() {
            return Ok(());
        }

        // TODO Step 3. Record classic script execution start time given script.

        // Step 4. Prepare to run script given settings.
        // Once dropped this will run "Clean up after running script" steps
        let _aes = AutoEntryScript::new(self);

        // Step 5 Let evaluationStatus be null.
        rooted!(in(*cx) let mut evaluation_status = UndefinedValue());
        let mut result = false;

        match script.record {
            // Step 6 If script's error to rethrow is not null, then set evaluationStatus to ThrowCompletion(script's error to rethrow).
            Err(error_to_rethrow) => unsafe {
                JS_SetPendingException(
                    *cx,
                    error_to_rethrow.handle(),
                    ExceptionStackBehavior::Capture,
                )
            },
            // Step 7 Otherwise, set evaluationStatus to ScriptEvaluation(script's record).
            Ok(compiled_script) => {
                rooted!(in(*cx) let mut rval = UndefinedValue());
                result = evaluate_script(
                    cx,
                    compiled_script,
                    script.url,
                    script.fetch_options,
                    rval.handle_mut(),
                );

Review comment (refactor):
```suggestion
        // Once dropped this will run "Step 9. Clean up after running script"
```

Code after:
            url,
            fetch_options,
            source: source_code,
            external,
            unminified_dir: self.unminified_js_dir(),
        };
        unminify_js(&mut script);

        // Step 13. Return script.
        script
    }

    /// <https://html.spec.whatwg.org/multipage/#run-a-classic-script>
    #[expect(unsafe_code)]
    pub(crate) fn run_a_classic_script(&self, script: ClassicScript, can_gc: CanGc) -> ErrorResult {
        let cx = GlobalScope::get_cx();
        // TODO Step 1. Let settings be the settings object of script.

        // Step 2. Check if we can run script with settings. If this returns "do not run", then return NormalCompletion(empty).
        if !self.can_run_script() {
            return Ok(());
        }

        // TODO Step 3. Record classic script execution start time given script.

        // Step 4. Prepare to run script given settings.
        // Once dropped this will run "Step 9. Clean up after running script" steps
        let _aes = AutoEntryScript::new(self);

        // Step 5. Let evaluationStatus be null.
        rooted!(in(*cx) let mut evaluation_status = UndefinedValue());
        let mut result = false;

        match script.record {
            // Step 6. If script's error to rethrow is not null, then set evaluationStatus to ThrowCompletion(script's error to rethrow).
            Err(error_to_rethrow) => unsafe {
                JS_SetPendingException(
                    *cx,
                    error_to_rethrow.handle(),
                    ExceptionStackBehavior::Capture,
                )
            },
            // Step 7. Otherwise, set evaluationStatus to ScriptEvaluation(script's record).
            Ok(compiled_script) => {
                rooted!(in(*cx) let mut rval = UndefinedValue());
                result = evaluate_script(
                    cx,
                    compiled_script,
                    script.url,
                    script.fetch_options,
                    rval.handle_mut(),