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

Code before:
                }
                let line_number = if script.external {
                    1
                } else {
                    self.line_number as u32
                };
                let window = self.owner_window();
                let global = window.as_global_scope();

                let script = global.create_a_classic_script(
                    (*script.text().str()).into(),
                    script.url,
                    script.fetch_options,
                    Some(introduction_type),
                    line_number,
                    script.external,
                );
                _ = global.run_a_classic_script(script, can_gc);
                document.set_current_script(old_script.as_deref());
            },
            ScriptType::Module => {
                document.set_current_script(None);
                self.run_a_module_script(&script, false, can_gc);
            },
            ScriptType::ImportMap => {
                // Step 6.1 Register an import map given el's relevant global object and el's result.
                register_import_map(&self.owner_global(), script.import_map, can_gc);
            },
        }

        // Step 7.
        // Decrement the ignore-destructive-writes counter of document, if it was incremented in the earlier step.
        if let Some(doc) = neutralized_doc {
            doc.decr_ignore_destructive_writes_counter();
        }

        // Step 8. If el's from an external file is true, then fire an event named load at el.
        if script.external {
            self.dispatch_load_event(can_gc);
        }
    }

    /// <https://html.spec.whatwg.org/multipage/#run-a-module-script>
    pub(crate) fn run_a_module_script(
        &self,
        script: &ScriptOrigin,
        _rethrow_errors: bool,
        can_gc: CanGc,
    ) {
        // TODO use a settings object rather than this element's document/window
        // Step 2

Review comment (suggestion):
```suggestion
                // Step 6."classic".4. Set document's currentScript attribute to oldCurrentScript.
                document.set_current_script(old_script.as_deref());
```

Code after:
                    document.set_current_script(None)
                } else {
                    document.set_current_script(Some(self))
                }

                let line_number = if script.external {
                    1
                } else {
                    self.line_number as u32
                };
                let window = self.owner_window();
                let global = window.as_global_scope();

                let script = global.create_a_classic_script(
                    (*script.text().str()).into(),
                    script.url,
                    script.fetch_options,
                    Some(introduction_type),
                    line_number,
                    script.external,
                );
                // Step 6."classic".3. Run the classic script given by el's result.
                _ = global.run_a_classic_script(script, can_gc);

                // Step 6."classic".4. Set document's currentScript attribute to oldCurrentScript.
                document.set_current_script(old_script.as_deref());
            },
            ScriptType::Module => {
                document.set_current_script(None);
                self.run_a_module_script(&script, false, can_gc);
            },
            ScriptType::ImportMap => {
                // Step 6.1 Register an import map given el's relevant global object and el's result.
                register_import_map(&self.owner_global(), script.import_map, can_gc);
            },
        }

        // Step 7.
        // Decrement the ignore-destructive-writes counter of document, if it was incremented in the earlier step.
        if let Some(doc) = neutralized_doc {
            doc.decr_ignore_destructive_writes_counter();
        }

        // Step 8. If el's from an external file is true, then fire an event named load at el.
        if script.external {
            self.dispatch_load_event(can_gc);
        }
    }

    /// <https://html.spec.whatwg.org/multipage/#run-a-module-script>
    pub(crate) fn run_a_module_script(