Bug 202421 - Socket RWI client should acquire backend commands from server
Summary: Socket RWI client should acquire backend commands from server
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: Ross Kirsling
URL:
Keywords: InRadar
: 199016 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-10-01 12:26 PDT by Ross Kirsling
Modified: 2019-10-03 14:38 PDT (History)
17 users (show)

See Also:


Attachments
Patch (14.63 KB, patch)
2019-10-01 12:54 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (81.91 KB, patch)
2019-10-01 16:30 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (83.49 KB, patch)
2019-10-01 18:01 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (87.88 KB, patch)
2019-10-01 18:47 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (89.88 KB, patch)
2019-10-01 19:04 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (9.82 KB, patch)
2019-10-02 13:53 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch for landing (9.79 KB, patch)
2019-10-03 13:54 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ross Kirsling 2019-10-01 12:26:13 PDT
Socket RWI client should acquire backend commands from server
Comment 1 Ross Kirsling 2019-10-01 12:54:17 PDT
Created attachment 379935 [details]
Patch
Comment 2 EWS Watchlist 2019-10-01 12:54:38 PDT
This patch modifies the inspector protocol generator. Please ensure that you have rebaselined any generator test results (i.e., by running `Tools/Scripts/run-inspector-generator-tests --reset-results`)
Comment 3 Basuke Suzuki 2019-10-01 13:11:36 PDT
*** Bug 199016 has been marked as a duplicate of this bug. ***
Comment 4 Basuke Suzuki 2019-10-01 13:20:41 PDT
Comment on attachment 379935 [details]
Patch

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

This is informal review.

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp:134
> +bool RemoteInspectorServer::start(const char* address, uint16_t port, String&& backendCommandsPath)

PlayStation port doesn't require this argument. I think it is better to add another method to set m_backendCommandsPath. It shouldn't be too late if the path is set just after start().

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.h:43
> +    JS_EXPORT_PRIVATE bool start(const char* address, uint16_t port, String&& backendCommandsPath = String());

Ditto.

> Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp:68
> +    Inspector::RemoteInspectorServer::singleton().start(host.utf8().data(), port.value(), backendCommandsPath());

Ditto
Comment 5 Devin Rousso 2019-10-01 13:26:55 PDT
Comment on attachment 379935 [details]
Patch

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

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp:268
> +    if (!m_backendCommandsPath)

Should this be `isEmpty()`?

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp:269
> +        return String();

You can use `{ }` instead.

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp:273
> +        return String();

Ditto

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp:278
> +        return String();

Ditto

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp:283
> +    FileSystem::readFromFile(handle, buffer.data(), size);

Should we be early-returning with a `String()` if this returns `-1`?

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.h:43
> +    JS_EXPORT_PRIVATE bool start(const char* address, uint16_t port, String&& backendCommandsPath = String());

I don't think we should have a fallback for this.  I'd expect any callers to provide a `backendCommandsPath` (which is what it looks like is done now already).  Are there other callers of this that don't provide a `backendCommandsPath`?

> Source/JavaScriptCore/inspector/scripts/codegen/generate_js_backend_commands.py:158
> +class CppBackendCommandsGenerator(JSBackendCommandsGenerator):

I think we'd prefer if you moved this into a separate file 'generate_cpp_backend_commands.py'.

> Source/JavaScriptCore/inspector/scripts/generate-inspector-protocol-bindings.py:166
> +        generators.append(CppBackendCommandsGenerator(*generator_arguments))

Please include this for "Frameworks.Test" too.  We should also probably have some sort of testing for this, especially since you do some character replacements for the C++ string.

> Source/WebKit/UIProcess/socket/RemoteInspectorClient.cpp:191
> +void RemoteInspectorClient::setBackendCommands(const Event& event)

I think this signature is missing from the header 'RemoateInspectorClient.h'.

> Source/WebKit/UIProcess/socket/RemoteInspectorClient.cpp:196
> +    m_backendCommandsURL = makeString("data:text/javascript;base64,", *event.message);

Style: I think we prefer using `.value()` for `Optional` instead of `*`.

> Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp:45
> +        return String();

Ditto

> Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp:49
> +        return String();

Ditto

> Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp:51
> +    return String(path);

Do you need to explicitly construct the `String`, or can it be implicit?
Comment 6 Ross Kirsling 2019-10-01 15:17:45 PDT
(In reply to Devin Rousso from comment #5)
> > Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.h:43
> > +    JS_EXPORT_PRIVATE bool start(const char* address, uint16_t port, String&& backendCommandsPath = String());
> 
> I don't think we should have a fallback for this.  I'd expect any callers to
> provide a `backendCommandsPath` (which is what it looks like is done now
> already).  Are there other callers of this that don't provide a
> `backendCommandsPath`?

It's just PS that uses the C++ copy instead of the path to the JS resource, so yeah, I'll split that out as Basuke also suggested.

> > Source/JavaScriptCore/inspector/scripts/generate-inspector-protocol-bindings.py:166
> > +        generators.append(CppBackendCommandsGenerator(*generator_arguments))
> 
> Please include this for "Frameworks.Test" too.  We should also probably have
> some sort of testing for this, especially since you do some character
> replacements for the C++ string.

Er, now that you mention it, we shouldn't be doing these string replaces at all, since C++11 has raw strings.

> > Source/WebKit/UIProcess/socket/RemoteInspectorClient.cpp:191
> > +void RemoteInspectorClient::setBackendCommands(const Event& event)
> 
> I think this signature is missing from the header 'RemoateInspectorClient.h'.

Oddly enough, it's already there and just not implemented.
Comment 7 Ross Kirsling 2019-10-01 16:30:10 PDT
Created attachment 379964 [details]
Patch
Comment 8 Ross Kirsling 2019-10-01 16:32:09 PDT
Comment on attachment 379964 [details]
Patch

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

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp:265
> +    return s_inspectorBackendCommandsString ? s_inspectorBackendCommandsString : String();

Style note: Apparently initializer lists aren't syntactically valid inside ternary branches. :(
Comment 9 Ross Kirsling 2019-10-01 18:01:38 PDT
Created attachment 379976 [details]
Patch
Comment 10 Ross Kirsling 2019-10-01 18:47:03 PDT
Created attachment 379978 [details]
Patch
Comment 11 Ross Kirsling 2019-10-01 19:04:59 PDT
Created attachment 379979 [details]
Patch
Comment 12 Ross Kirsling 2019-10-01 19:22:39 PDT
Sigh...no matter how many files I add, it doesn't please iOS.

I'm sure that in itself is fixable, but this all feels like a ton of Xcode wiring for something that we have no particular expectation of ever using outside of PlayStation port.
Comment 13 Ross Kirsling 2019-10-02 13:53:18 PDT
Created attachment 380054 [details]
Patch
Comment 14 Ross Kirsling 2019-10-02 13:53:52 PDT
Here's the patch without any special support for PlayStation port -- we can deal with that stuff at a later date.
Comment 15 Devin Rousso 2019-10-03 08:53:58 PDT
Comment on attachment 380054 [details]
Patch

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

r=me

> Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp:263
> +    auto handle = FileSystem::openFile(m_backendCommandsPath, FileSystem::FileOpenMode::Read);

NIT: I would reorganize this function a bit so you can better ensure that `FileSystem::closeFile` gets called:
```
    if (m_backendCommandsPath.isEmpty())
        return { };

    auto handle = FileSystem::openFile(m_backendCommandsPath, FileSystem::FileOpenMode::Read);
    if (!FileSystem::isHandleValid(handle))
        return { };

    String result;
    long long size;
    if (FileSystem::getFileSize(handle, size)) {
        Vector<char> buffer(size);
        auto bytesRead = FileSystem::readFromFile(handle, buffer.data(), size);
        result = String::adopt(WTFMove(buffer));
    }
    FileSystem::closeFile(handle);
    return result;
```
Comment 16 Ross Kirsling 2019-10-03 11:50:53 PDT
Unfortunately it doesn't seem like String::adopt can handle a Vector of char, which is the type used by FileSystem::readFromFile.
Comment 17 Ross Kirsling 2019-10-03 13:52:48 PDT
(In reply to Ross Kirsling from comment #16)
> Unfortunately it doesn't seem like String::adopt can handle a Vector of
> char, which is the type used by FileSystem::readFromFile.

(Nevermind, I can reinterpret_cast from LChar...)
Comment 18 Ross Kirsling 2019-10-03 13:54:03 PDT
Created attachment 380159 [details]
Patch for landing
Comment 19 WebKit Commit Bot 2019-10-03 14:37:54 PDT
Comment on attachment 380159 [details]
Patch for landing

Clearing flags on attachment: 380159

Committed r250679: <https://trac.webkit.org/changeset/250679>
Comment 20 WebKit Commit Bot 2019-10-03 14:37:56 PDT
All reviewed patches have been landed.  Closing bug.
Comment 21 Radar WebKit Bug Importer 2019-10-03 14:38:24 PDT
<rdar://problem/55961622>