Bug 228316

Summary: Implement self.reportError()
Product: WebKit Reporter: Anne van Kesteren <annevk>
Component: DOMAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, clopez, darin, esprehn+autocc, ews-watchlist, ggaren, hi, kondapallykalyan, mkwst, rniwa, sam, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch none

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.