Bug 202716 - Make WebInspector's remote debug EventLoop code into RunLoop
Summary: Make WebInspector's remote debug EventLoop code into RunLoop
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks: 164193 210177
  Show dependency treegraph
 
Reported: 2019-10-08 19:02 PDT by Ryosuke Niwa
Modified: 2020-04-10 11:04 PDT (History)
22 users (show)

See Also:


Attachments
Patch (31.93 KB, patch)
2019-10-08 19:09 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fix GTK+ (31.94 KB, patch)
2019-10-08 19:27 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch (44.16 KB, patch)
2019-10-08 19:46 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Updated (44.61 KB, patch)
2019-10-10 19:49 PDT, Ryosuke Niwa
joepeck: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2019-10-08 19:02:21 PDT
It's confusing to have a class called EventLoop which spins a run loop.
Comment 1 Ryosuke Niwa 2019-10-08 19:09:36 PDT
Created attachment 380492 [details]
Patch
Comment 2 Ryosuke Niwa 2019-10-08 19:27:41 PDT
Created attachment 380494 [details]
Fix GTK+
Comment 3 Ryosuke Niwa 2019-10-08 19:46:59 PDT
Created attachment 380495 [details]
Patch
Comment 4 Devin Rousso 2019-10-09 12:26:02 PDT
Comment on attachment 380495 [details]
Patch

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

r=me, this looks fine to me, but I'd suggest asking Joe to take a look as he's more familiar with this code

> Source/JavaScriptCore/inspector/JSGlobalObjectScriptDebugServer.cpp:79
> +    return "com.apple.JavaScriptCore.remote-inspector-runloop-mode";

`_s`?

> Source/JavaScriptCore/inspector/JSGlobalObjectScriptDebugServer.h:41
> +    static String runLoopMode();

NIT: I think we should move this to `RemoteInspectionTarget` since it's more "generic" than `JSGlobalObjectScriptDebugServer` (`RemoteInspectionTarget` is also used when inspecting webpages, which doesn't use `JSGlobalObjectScriptDebugServer`).

> Source/WTF/wtf/win/RunLoopWin.cpp:125
> +    MSG msg;

NIT: we should call this `message` to match the rest of the file

> Source/WTF/wtf/win/RunLoopWin.cpp:127
> +        m_ended = true;

This no longer exists.

> Source/WTF/wtf/win/RunLoopWin.cpp:132
> +    TranslateMessage(&msg);
> +    DispatchMessage(&msg);

Should these be `::TranslateMessage` and `::DispatchMessage`?
Comment 5 Joseph Pecoraro 2019-10-09 13:25:32 PDT
Comment on attachment 380495 [details]
Patch

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

>> Source/JavaScriptCore/inspector/JSGlobalObjectScriptDebugServer.h:41
>> +    static String runLoopMode();
> 
> NIT: I think we should move this to `RemoteInspectionTarget` since it's more "generic" than `JSGlobalObjectScriptDebugServer` (`RemoteInspectionTarget` is also used when inspecting webpages, which doesn't use `JSGlobalObjectScriptDebugServer`).

WebCore uses a slightly different EventLoop with different modes. Only JSContext debugging used the special mode which pauses the world.

> Source/WTF/wtf/cf/RunLoopCF.cpp:70
> +RunLoop::CycleResult RunLoop::cycle(String mode)
> +{
> +    CFTimeInterval timeInterval = 0.05;
> +    CFRunLoopRunInMode(mode.isNull() ? kCFRunLoopDefaultMode : mode.createCFString().get(), timeInterval, true);
> +    return CycleResult::Continue;
> +}

According to r151562 (bug 117596)
https://trac.webkit.org/changeset/151562/webkit

This would produce hangs while paused in Web Inspector in other apps.

Might want to do the following for PLATFORM(MAC):

    [NSApp setWindowsNeedUpdate:YES];
    [NSApp sendEvent:[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.05] inMode:NSDefaultRunLoopMode dequeue:YES]];
Comment 6 Joseph Pecoraro 2019-10-09 13:25:50 PDT
>     [NSApp setWindowsNeedUpdate:YES];
>     [NSApp sendEvent:[NSApp nextEventMatchingMask:NSAnyEventMask
> untilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]
> inMode:NSDefaultRunLoopMode dequeue:YES]];

Err, obviously respecting the `mode` passed in.
Comment 7 Ryosuke Niwa 2019-10-09 15:24:17 PDT
(In reply to Devin Rousso from comment #4)
> Comment on attachment 380495 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=380495&action=review
> 
> r=me, this looks fine to me, but I'd suggest asking Joe to take a look as
> he's more familiar with this code
> 
> > Source/JavaScriptCore/inspector/JSGlobalObjectScriptDebugServer.cpp:79
> > +    return "com.apple.JavaScriptCore.remote-inspector-runloop-mode";
> 
> `_s`?

Fixed.

> > Source/JavaScriptCore/inspector/JSGlobalObjectScriptDebugServer.h:41
> > +    static String runLoopMode();
> 
> NIT: I think we should move this to `RemoteInspectionTarget` since it's more
> "generic" than `JSGlobalObjectScriptDebugServer` (`RemoteInspectionTarget`
> is also used when inspecting webpages, which doesn't use
> `JSGlobalObjectScriptDebugServer`).

We can't doe that because RemoteInspectionTarget isn't always enabled but JSGlobalObjectScriptDebugServer is.

> > Source/WTF/wtf/win/RunLoopWin.cpp:125
> > +    MSG msg;
> 
> NIT: we should call this `message` to match the rest of the file

Fixed.

> > Source/WTF/wtf/win/RunLoopWin.cpp:127
> > +        m_ended = true;
> 
> This no longer exists.

Removed.

> > Source/WTF/wtf/win/RunLoopWin.cpp:132
> > +    TranslateMessage(&msg);
> > +    DispatchMessage(&msg);
> 
> Should these be `::TranslateMessage` and `::DispatchMessage`?

I'll do that although it shouldn't matter.
Comment 8 Ryosuke Niwa 2019-10-09 16:25:43 PDT
(In reply to Joseph Pecoraro from comment #5)
> Comment on attachment 380495 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=380495&action=review
>
> > Source/WTF/wtf/cf/RunLoopCF.cpp:70
> > +RunLoop::CycleResult RunLoop::cycle(String mode)
> > +{
> > +    CFTimeInterval timeInterval = 0.05;
> > +    CFRunLoopRunInMode(mode.isNull() ? kCFRunLoopDefaultMode : mode.createCFString().get(), timeInterval, true);
> > +    return CycleResult::Continue;
> > +}
> 
> According to r151562 (bug 117596)
> https://trac.webkit.org/changeset/151562/webkit
> 
> This would produce hangs while paused in Web Inspector in other apps.
> 
> Might want to do the following for PLATFORM(MAC):
> 
>     [NSApp setWindowsNeedUpdate:YES];
>     [NSApp sendEvent:[NSApp nextEventMatchingMask:NSAnyEventMask
> untilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]
> inMode:NSDefaultRunLoopMode dequeue:YES]];

Ugh... we can't do that because JavaScriptCore can't link against AppKit :(
Comment 9 Ryosuke Niwa 2019-10-10 19:44:46 PDT
(In reply to Joseph Pecoraro from comment #5)
> Comment on attachment 380495 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=380495&action=review
>
> > Source/WTF/wtf/cf/RunLoopCF.cpp:70
> > +RunLoop::CycleResult RunLoop::cycle(String mode)
> > +{
> > +    CFTimeInterval timeInterval = 0.05;
> > +    CFRunLoopRunInMode(mode.isNull() ? kCFRunLoopDefaultMode : mode.createCFString().get(), timeInterval, true);
> > +    return CycleResult::Continue;
> > +}
> 
> According to r151562 (bug 117596)
> https://trac.webkit.org/changeset/151562/webkit
> 
> This would produce hangs while paused in Web Inspector in other apps.

Looks like this fix is no longer needed. I've tested both Mini Browser WK1 as well as the app attached on <rdar://problem/14133001> and they both seem to work fine.
Comment 10 Ryosuke Niwa 2019-10-10 19:49:13 PDT
Created attachment 380716 [details]
Updated
Comment 11 Joseph Pecoraro 2019-10-11 13:34:47 PDT
Comment on attachment 380716 [details]
Updated

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

r=me

> Source/WTF/wtf/RunLoop.h:65
> +    WTF_EXPORT_PRIVATE CycleResult static cycle(String = { });

Can this be a `const String&` or does it need to be a `String` for a particular reason?
Comment 12 Joseph Pecoraro 2019-10-11 13:35:26 PDT
Comment on attachment 380716 [details]
Updated

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

> ChangeLog:8
> +        * WebKit.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:

This doesn't look like it was modified. Might be an accident, so this file can be unmodified.
Comment 13 Ryosuke Niwa 2019-10-11 19:51:34 PDT
Committed r251036: <https://trac.webkit.org/changeset/251036>
Comment 14 Radar WebKit Bug Importer 2019-10-15 16:16:20 PDT
<rdar://problem/56312647>
Comment 15 BJ Burg 2019-10-16 08:58:22 PDT
Comment on attachment 380495 [details]
Patch

Good cleanup. I'll keep my eyes open for regressions that come in. In particular, auto-inspect and remote debugging 3rd party apps seem most affected by RunLoop modes.