Implement WindowOrWorkerGlobalScope::reportError (#40654)

This web API is alternative API to `throw e`, which is why we can reuse
a lot of the existing machinery.

The one testcase that isn't passing yet is because it reports an empty
`TypeError`. The current logic in `ErrorInfo` only retrieves the message
data, but doesn't include the type of the exception. For that, we need
to use `(*report)._base.errorNumber` and map that back to the original
type codes. However, deferring that to a follow-up as that requires some
more work in mozjs.

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This commit is contained in:
Tim van der Lippe
2025-11-16 10:30:16 +01:00
committed by GitHub
parent 10796b8590
commit 8e0c2d5750
10 changed files with 63 additions and 46 deletions

View File

@@ -1329,6 +1329,12 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
Some(DomRoot::from_ref(container))
}
/// <https://html.spec.whatwg.org/multipage/#dom-reporterror>
fn ReportError(&self, cx: JSContext, error: HandleValue, can_gc: CanGc) {
self.as_global_scope()
.report_an_exception(cx, error, can_gc);
}
/// <https://html.spec.whatwg.org/multipage/#dom-navigator>
fn Navigator(&self) -> DomRoot<Navigator> {
self.navigator