Bug 140557 - Web Inspector: code generator should introduce typedefs for protocol types that are arrays
Summary: Web Inspector: code generator should introduce typedefs for protocol types th...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Brian Burg
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-01-16 12:36 PST by Brian Burg
Modified: 2015-01-16 15:17 PST (History)
8 users (show)

See Also:


Attachments
Patch (100.12 KB, patch)
2015-01-16 13:21 PST, Brian Burg
joepeck: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Burg 2015-01-16 12:36:34 PST
Example: say I want the following situation:

{
    "domain": "OverlayTypes",
    "description": "Exposes types to be used by the inspector overlay.",
    "types": [
        {
            "id": "Point",
            "type": "object",
            "properties": [
                { "name": "x", "type": "number" },
                { "name": "y", "type": "number" }
            ]
        },
        {
            "id": "Quad",
            "description": "A quad is a collection of 4 points, often representing a transformed rectangle. When initialized from a rect, the points are in clockwise order from top left.",
            "type": "array",
            "items": { "type": "Point" }
        }
    ]
}


Currently, there is no generated type name for Inspector::Protocol::OverlayTypes::Quad. Instead, you have to do Inspector::Protocol::Array<Inspector::Protocol::OverlayTypes::Point>. This is longwinded and makes the code hard to follow.
Comment 1 Radar WebKit Bug Importer 2015-01-16 12:36:56 PST
<rdar://problem/19502481>
Comment 2 Brian Burg 2015-01-16 13:21:09 PST
Created attachment 244799 [details]
Patch
Comment 3 WebKit Commit Bot 2015-01-16 13:24:16 PST
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 4 Joseph Pecoraro 2015-01-16 14:17:50 PST
Comment on attachment 244799 [details]
Patch

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

Nice. r=me

> Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_header.py:154
> +            if len(declaration.description) > 0:
> +                typedef_lines.append('/* %s */' % declaration.description)

I see this is copied from the primitive typedef, is it useful in either case? I'll be honest, I don't think I ever noticed these comments before.

> Source/JavaScriptCore/inspector/scripts/tests/expected/type-declaration-array-type.json-result:368
> +typedef Inspector::Protocol::Array<int> LuckyNumbers;
> +
> +typedef Inspector::Protocol::Array<String> BabyNames;
> +
> +typedef Inspector::Protocol::Array<Inspector::Protocol::Runtime::ObjectId> NewObjects;
> +
> +typedef Inspector::Protocol::Array<Inspector::Protocol::Debugger::BreakpointId> OldObjects;
> +
> +typedef Inspector::Protocol::Array<Inspector::Protocol::Debugger::Reason> StopReasons;

Hmm, why are there newlines between these? They are all defined in the same domain.
Comment 5 Brian Burg 2015-01-16 14:19:40 PST
Comment on attachment 244799 [details]
Patch

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

>> Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_header.py:154
>> +                typedef_lines.append('/* %s */' % declaration.description)
> 
> I see this is copied from the primitive typedef, is it useful in either case? I'll be honest, I don't think I ever noticed these comments before.

It is a vestige from the old generator. I think the idea is that you will see a description if you use "go to definition" in an IDE.

>> Source/JavaScriptCore/inspector/scripts/tests/expected/type-declaration-array-type.json-result:368
>> +typedef Inspector::Protocol::Array<Inspector::Protocol::Debugger::Reason> StopReasons;
> 
> Hmm, why are there newlines between these? They are all defined in the same domain.

I'll fix that.
Comment 6 Brian Burg 2015-01-16 15:17:44 PST
Committed r178606: <http://trac.webkit.org/changeset/178606>