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

Code before:
                .has_trustworthy_ancestor_or_current_origin()
        })
    }

    /// <https://html.spec.whatwg.org/multipage/#report-an-exception>
    pub(crate) fn report_an_exception(&self, cx: SafeJSContext, error: HandleValue, can_gc: CanGc) {
        // Step 1. Let notHandled be true.
        //
        // Handled in `report_an_error`

        // Step 2. Let errorInfo be the result of extracting error information from exception.
        // Step 3. Let script be a script found in an implementation-defined way, or null.
        // This should usually be the running script (most notably during run a classic script).
        // Step 4. If script is a classic script and script's muted errors is true, then set errorInfo[error] to null,
        // errorInfo[message] to "Script error.", errorInfo[filename] to the empty string,
        // errorInfo[lineno] to 0, and errorInfo[colno] to 0.
        let error_info = crate::dom::bindings::error::ErrorInfo::from_value(error, cx, can_gc);
        // Step 5. If omitError is true, then set errorInfo[error] to null.
        //
        // `omitError` defaults to `false`

        // Step 6-7
        self.report_an_error(error_info, error, can_gc);
    }

    /// <https://html.spec.whatwg.org/multipage/#report-the-error>
    pub(crate) fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue, can_gc: CanGc) {
        // Step 6. Early return if global is in error reporting mode,
        if self.in_error_reporting_mode.get() {
            return;
        }

        // Step 6.1. Set global's in error reporting mode to true.
        self.in_error_reporting_mode.set(true);

        // Step 6.2. Set notHandled to the result of firing an event named error at global,
        // using ErrorEvent, with the cancelable attribute initialized to true,
        // and additional attributes initialized according to errorInfo.

        // FIXME(#13195): muted errors.
        let event = ErrorEvent::new(
            self,
            atom!("error"),
            EventBubbles::DoesNotBubble,
            EventCancelable::Cancelable,
            error_info.message.as_str().into(),
            error_info.filename.as_str().into(),
            error_info.lineno,
            error_info.column,
            value,
            can_gc,

Review comment (suggestion):
This link now points to same as `report_an_exception`. Maybe just remove it, and say it is step 6-7.

Code after:
                .has_trustworthy_ancestor_or_current_origin()
        })
    }

    /// <https://html.spec.whatwg.org/multipage/#report-an-exception>
    pub(crate) fn report_an_exception(&self, cx: SafeJSContext, error: HandleValue, can_gc: CanGc) {
        // Step 1. Let notHandled be true.
        //
        // Handled in `report_an_error`

        // Step 2. Let errorInfo be the result of extracting error information from exception.
        // Step 3. Let script be a script found in an implementation-defined way, or null.
        // This should usually be the running script (most notably during run a classic script).
        // Step 4. If script is a classic script and script's muted errors is true, then set errorInfo[error] to null,
        // errorInfo[message] to "Script error.", errorInfo[filename] to the empty string,
        // errorInfo[lineno] to 0, and errorInfo[colno] to 0.
        let error_info = crate::dom::bindings::error::ErrorInfo::from_value(error, cx, can_gc);
        // Step 5. If omitError is true, then set errorInfo[error] to null.
        //
        // `omitError` defaults to `false`

        // Steps 6-7
        self.report_an_error(error_info, error, can_gc);
    }

    /// Steps 6-7 of <https://html.spec.whatwg.org/multipage/#report-an-exception>
    pub(crate) fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue, can_gc: CanGc) {
        // Step 6. Early return if global is in error reporting mode,
        if self.in_error_reporting_mode.get() {
            return;
        }

        // Step 6.1. Set global's in error reporting mode to true.
        self.in_error_reporting_mode.set(true);

        // Step 6.2. Set notHandled to the result of firing an event named error at global,
        // using ErrorEvent, with the cancelable attribute initialized to true,
        // and additional attributes initialized according to errorInfo.

        // FIXME(#13195): muted errors.
        let event = ErrorEvent::new(
            self,
            atom!("error"),
            EventBubbles::DoesNotBubble,
            EventCancelable::Cancelable,
            error_info.message.as_str().into(),
            error_info.filename.as_str().into(),
            error_info.lineno,
            error_info.column,
            value,
            can_gc,