Bug 239495 - IPC testing API should have the ability to test IPC::Connection send and receive through IPC::Connection
Summary: IPC testing API should have the ability to test IPC::Connection send and rece...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: Safari 15
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kimmo Kinnunen
URL:
Keywords: InRadar
Depends on:
Blocks: 239494
  Show dependency treegraph
 
Reported: 2022-04-19 07:10 PDT by Kimmo Kinnunen
Modified: 2022-04-28 00:19 PDT (History)
8 users (show)

See Also:


Attachments
Patch (78.82 KB, patch)
2022-04-21 06:05 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
For landing (78.72 KB, patch)
2022-04-22 01:57 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
For landing (78.94 KB, patch)
2022-04-27 07:42 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
[fast-cq] For landing (78.99 KB, patch)
2022-04-28 00:14 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kimmo Kinnunen 2022-04-19 07:10:53 PDT
IPC testing API should have the ability to test IPC::Connection send and receive through IPC::Connection
Comment 1 Kimmo Kinnunen 2022-04-21 06:05:45 PDT
Created attachment 458055 [details]
Patch
Comment 2 Darin Adler 2022-04-21 14:07:19 PDT
Comment on attachment 458055 [details]
Patch

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

> Source/WebKit/Shared/IPCConnectionTester.cpp:48
> +#if USE(UNIX_DOMAIN_SOCKETS)
> +    IPC::Connection::Identifier connectionHandle { connectionIdentifier.release().release() };
> +#elif OS(DARWIN)
> +    IPC::Connection::Identifier connectionHandle { connectionIdentifier.port() };
> +#elif OS(WINDOWS)
> +    IPC::Connection::Identifier connectionHandle { connectionIdentifier.handle() };
> +#else
> +    notImplemented();
> +    IPC::Connection::Identifier connectionHandle { };
> +#endif
> +    return connectionHandle;

Why the local variable? Why not just use "return" statements?

> Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp:414
> +        JSGlobalContextRetain(JSContextGetGlobalContext(context));
> +        JSValueProtect(context, resolve);
> +        JSValueProtect(context, reject);

I strongly suggest we use smart pointers in cases like this rather than hand-written function call pairs. But maybe the need is not quite as strong for test code? And maybe we don’t already have the correct smart pointer classes already handy to use? I thought we did, but not sure.

> Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp:508
> +        if (scope.exception()) {
> +            *exception = toRef(globalObject, scope.exception());
> +            scope.clearException();

Maybe we should consider a helper function that does this repeated pattern. The coding idioms here are repetitive enough that I am craving some helper functions.
Comment 3 Kimmo Kinnunen 2022-04-22 01:55:29 PDT
(In reply to Darin Adler from comment #2)
> > Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp:414
> > +        JSGlobalContextRetain(JSContextGetGlobalContext(context));
> > +        JSValueProtect(context, resolve);
> > +        JSValueProtect(context, reject);
> 
> I strongly suggest we use smart pointers in cases like this rather than
> hand-written function call pairs. But maybe the need is not quite as strong
> for test code? And maybe we don’t already have the correct smart pointer
> classes already handy to use? I thought we did, but not sure.

bug 239643 - Add a smart pointer to hold JSValueProtect() objects

> 
> > Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp:508
> > +        if (scope.exception()) {
> > +            *exception = toRef(globalObject, scope.exception());
> > +            scope.clearException();
> 
> Maybe we should consider a helper function that does this repeated pattern.
> The coding idioms here are repetitive enough that I am craving some helper
> functions.

I think this is due to the system using the public JS API instead of more normal way of doing JS-C++ integration in WebKit

Bug 239644 - IPC testing API should use the existing IDL bindings instead of manual binding with public JS API
Comment 4 Kimmo Kinnunen 2022-04-22 01:57:57 PDT
Created attachment 458123 [details]
For landing
Comment 5 Darin Adler 2022-04-22 11:01:49 PDT
(In reply to Kimmo Kinnunen from comment #3)
> > Maybe we should consider a helper function that does this repeated pattern.
> > The coding idioms here are repetitive enough that I am craving some helper
> > functions.
> 
> I think this is due to the system using the public JS API instead of more
> normal way of doing JS-C++ integration in WebKit

Sure but my separate point was that within this file a helper could make the code less repetitive and perhaps less error prone.

There may be reasons it’s not easy to use the IDL bindings here. In WebKitTestRunner we also have a lot of code using the JavaScript C API rather than our bindings system, but since it’s C++ code, I wrote lots of helper functions there for WebKitTestRunner to make the idioms simpler and less error prone.
Comment 6 Radar WebKit Bug Importer 2022-04-26 07:11:13 PDT
<rdar://problem/92331751>
Comment 7 EWS 2022-04-27 07:31:29 PDT
Tools/Scripts/svn-apply failed to apply attachment 458123 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 8 Kimmo Kinnunen 2022-04-27 07:32:40 PDT
(In reply to Darin Adler from comment #5)
> (In reply to Kimmo Kinnunen from comment #3)
> > > Maybe we should consider a helper function that does this repeated pattern.
> > > The coding idioms here are repetitive enough that I am craving some helper
> > > functions.
> > 
> > I think this is due to the system using the public JS API instead of more
> > normal way of doing JS-C++ integration in WebKit
> 
> Sure but my separate point was that within this file a helper could make the
> code less repetitive and perhaps less error prone.
> 
> There may be reasons it’s not easy to use the IDL bindings here. In
> WebKitTestRunner we also have a lot of code using the JavaScript C API
> rather than our bindings system, but since it’s C++ code, I wrote lots of
> helper functions there for WebKitTestRunner to make the idioms simpler and
> less error prone.

I see what I can do to reduce the repetitiveness. The initial reaction is that the idl system should be the best option here.
Comment 9 Kimmo Kinnunen 2022-04-27 07:42:19 PDT
Created attachment 458445 [details]
For landing
Comment 10 EWS 2022-04-27 22:40:06 PDT
ChangeLog entry in LayoutTests/ChangeLog contains OOPS!.
Comment 11 Kimmo Kinnunen 2022-04-28 00:14:55 PDT
Created attachment 458496 [details]
[fast-cq] For landing
Comment 12 EWS 2022-04-28 00:19:26 PDT
Committed r293567 (250081@main): <https://commits.webkit.org/250081@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 458496 [details].