Bug 236518 - Redirect shadow realm console output to page's ConsoleClient
Summary: Redirect shadow realm console output to page's ConsoleClient
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-11 10:30 PST by Joseph Griego
Modified: 2022-02-15 13:08 PST (History)
8 users (show)

See Also:


Attachments
Patch (6.28 KB, patch)
2022-02-11 10:32 PST, Joseph Griego
no flags Details | Formatted Diff | Diff
Patch (6.83 KB, patch)
2022-02-11 14:01 PST, Joseph Griego
hi: review+
Details | Formatted Diff | Diff
Patch (6.78 KB, patch)
2022-02-14 13:31 PST, Joseph Griego
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Griego 2022-02-11 10:30:40 PST
Redirect shadow realm console output to page's ConsoleClient
Comment 1 Joseph Griego 2022-02-11 10:32:49 PST
Created attachment 451723 [details]
Patch
Comment 2 Devin Rousso 2022-02-11 11:33:40 PST
Comment on attachment 451723 [details]
Patch

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

Nice fix!  Some style comments, but I think the logic is sound :)

BTW did you want this to be reviewed?  I dont see r? so I wasn't sure 😅  Apologies if that was not the intention/desire.

> LayoutTests/inspector/shadow-realm-console.html:6
> +     const realm = new ShadowRealm();

Style: this should only be indented four spaces, not five

NIT: you can omit `()` if there are no arguments when using `new`

> LayoutTests/inspector/shadow-realm-console.html:31
> +         WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, function(event) {

Rather than having this be global listener, you could have this just be a one-off `awaitEvent` inside each test.  As an example,
```
await test() {
    let [messageAddedEvent] = await Promise.all([
        WI.consoleManager.awaitEvent(WI.ConsoleManager.Event.MessageAdded),
        InspectorTest.evaluateInPage(`realmEvaluate("console.log('hello')")`),
    ]);
    let {message} = messageAddedEvent.data;

    InspectorTest.expectEqual(message.messageText, "hello", "The console message should have the text 'hello'.");
},
```

> LayoutTests/inspector/shadow-realm-console.html:41
> +             name: "log",

please give this a more descriptive name like `name: "ShadowRealm.Console.basic.log"`

> LayoutTests/inspector/shadow-realm-console.html:42
> +             description: "console.log in shadow realms should send to the incubating realm's console",

While this is perhaps true given that you're seeing a console message in the first place, I think we might also want to check that the `target` of the console message matches that of the creating context.  As such, I'd add something like this to the end of my example code in my comment on :31
```
InspectorText.expectEqual(message.target, WI.mainTarget, "The target of the console message should be the main target.");
```

> LayoutTests/inspector/shadow-realm-console.html:46
> +                     .then(msg => {

Style: we always add `(` `)` in arrow functions, even when there's only a single parameter

> LayoutTests/inspector/shadow-realm-console.html:47
> +                         InspectorTest.expectEqual(msg.messageText, "hello", "message text should match");

Style: we normally make these into complete sentences, e.g. "The console message should have the text 'hello'."

> LayoutTests/inspector/shadow-realm-console.html:55
> +             name: "nested log",

ditto (:41)

> LayoutTests/inspector/shadow-realm-console.html:60
> +                     .then(msg => {

ditto (:46)

> LayoutTests/inspector/shadow-realm-console.html:61
> +                         InspectorTest.expectEqual(msg.messageText, "hello", "message text should match");

ditto (:47)
Comment 3 Joseph Griego 2022-02-11 11:45:46 PST
Was waiting on EWS before setting r? but yes, thanks for the review :)
Comment 4 Joseph Griego 2022-02-11 14:01:25 PST
Created attachment 451743 [details]
Patch
Comment 5 Devin Rousso 2022-02-11 14:57:48 PST
Comment on attachment 451743 [details]
Patch

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

r=mews, thanks for taking my suggestions! =D

> LayoutTests/inspector/shadow-realm-console.html:26
> +            async test(resolve, reject) {

NIT: please remove the `resolve, reject` since those are not provided when using an `async test` :)

> LayoutTests/inspector/shadow-realm-console.html:40
> +            async test(resolve, reject) {

ditto (:26)
Comment 6 Joseph Griego 2022-02-14 13:31:15 PST
Created attachment 451938 [details]
Patch
Comment 7 EWS 2022-02-15 13:07:37 PST
Committed r289840 (247288@main): <https://commits.webkit.org/247288@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 451938 [details].
Comment 8 Radar WebKit Bug Importer 2022-02-15 13:08:25 PST
<rdar://problem/88983084>