Bug 239495

Summary: IPC testing API should have the ability to test IPC::Connection send and receive through IPC::Connection
Product: WebKit Reporter: Kimmo Kinnunen <kkinnunen>
Component: WebKit2Assignee: Kimmo Kinnunen <kkinnunen>
Status: RESOLVED FIXED    
Severity: Normal CC: annulen, darin, ews-watchlist, gyuyoung.kim, kkinnunen, ryuan.choi, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 15   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=239399
https://bugs.webkit.org/show_bug.cgi?id=239643
https://bugs.webkit.org/show_bug.cgi?id=239644
Bug Depends on:    
Bug Blocks: 239494    
Attachments:
Description Flags
Patch
none
For landing
none
For landing
none
[fast-cq] For landing none

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].