Bug 228316 - Implement self.reportError()
Summary: Implement self.reportError()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-07-26 23:10 PDT by Anne van Kesteren
Modified: 2021-08-30 12:28 PDT (History)
13 users (show)

See Also:


Attachments
Patch (11.60 KB, patch)
2021-08-27 15:28 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (11.51 KB, patch)
2021-08-30 07:26 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anne van Kesteren 2021-07-26 23:10:56 PDT
This allows libraries to emulate the behavior of throwing exceptions in an event listener (triggers self.onerror).

HTML change: https://github.com/whatwg/html/pull/1196.

Tests: https://github.com/web-platform-tests/wpt/pull/29738.
Comment 1 Radar WebKit Bug Importer 2021-08-02 23:11:17 PDT
<rdar://problem/81446162>
Comment 2 Chris Dumez 2021-08-27 15:28:57 PDT
Created attachment 436682 [details]
Patch
Comment 3 Chris Dumez 2021-08-27 15:33:56 PDT
Comment on attachment 436682 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=436682&action=review

> Source/WebCore/page/DOMWindow.cpp:1809
> +    auto* exception = JSC::jsDynamicCast<JSC::Exception*>(vm, error);

FYI, I initially tried to call `reportException(JSGlobalObject* lexicalGlobalObject, JSValue exceptionValue, CachedScript* cachedScript)` overload directly with the JSValue.
However, for some reason, that reportException() overload doesn't capture the stack when constructing the JSC::Exception. This was causing some failures in the WPT tests as a result (things like e.filename were not populated).
Comment 4 Sam Weinig 2021-08-28 11:10:02 PDT
(In reply to Chris Dumez from comment #3)
> Comment on attachment 436682 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=436682&action=review
> 
> > Source/WebCore/page/DOMWindow.cpp:1809
> > +    auto* exception = JSC::jsDynamicCast<JSC::Exception*>(vm, error);
> 
> FYI, I initially tried to call `reportException(JSGlobalObject*
> lexicalGlobalObject, JSValue exceptionValue, CachedScript* cachedScript)`
> overload directly with the JSValue.
> However, for some reason, that reportException() overload doesn't capture
> the stack when constructing the JSC::Exception. This was causing some
> failures in the WPT tests as a result (things like e.filename were not
> populated).

We definitely have other issues where the stack is not captured or exposed for DOM related errors: http://wpt.live/WebIDL/ecmascript-binding/es-exceptions/DOMException-custom-bindings.any.html
Comment 5 Sam Weinig 2021-08-28 11:15:09 PDT
Comment on attachment 436682 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=436682&action=review

> Source/WebCore/page/WindowOrWorkerGlobalScope.idl:71
> +    [CallWith=GlobalObject] undefined reportError(any error);

Please move this to below crossOriginIsolated; to match it's location in the spec (I try to keep these as close to the spec IDL as I can).

> Source/WebCore/workers/WorkerGlobalScope.cpp:551
> +void WorkerGlobalScope::reportError(JSC::JSGlobalObject& globalObject, JSC::JSValue error)

Kind of a bummer to have to repeat this.
Comment 6 Chris Dumez 2021-08-30 07:26:46 PDT
Created attachment 436768 [details]
Patch
Comment 7 EWS 2021-08-30 07:59:48 PDT
Committed r281756 (241098@main): <https://commits.webkit.org/241098@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 436768 [details].
Comment 8 Chris Dumez 2021-08-30 12:28:26 PDT
(In reply to Sam Weinig from comment #5)
> Comment on attachment 436682 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=436682&action=review
> 
> > Source/WebCore/page/WindowOrWorkerGlobalScope.idl:71
> > +    [CallWith=GlobalObject] undefined reportError(any error);
> 
> Please move this to below crossOriginIsolated; to match it's location in the
> spec (I try to keep these as close to the spec IDL as I can).
> 
> > Source/WebCore/workers/WorkerGlobalScope.cpp:551
> > +void WorkerGlobalScope::reportError(JSC::JSGlobalObject& globalObject, JSC::JSValue error)
> 
> Kind of a bummer to have to repeat this.

Yes, I agree. I'll find a way to share and follow up.