Bug 137190

Summary: Web Inspector: InspectorValues should use references for out parameters
Product: WebKit Reporter: Brian Burg <burg>
Component: Web InspectorAssignee: Brian Burg <burg>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, graouts, joepeck, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch joepeck: review+

Description Brian Burg 2014-09-28 00:33:59 PDT
We never check for null, so...
Comment 1 Radar WebKit Bug Importer 2014-09-28 00:34:08 PDT
<rdar://problem/18480915>
Comment 2 Brian Burg 2014-09-28 14:40:11 PDT
Created attachment 238822 [details]
Patch
Comment 3 WebKit Commit Bot 2014-09-28 14:41:48 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 4 Joseph Pecoraro 2014-09-29 13:15:43 PDT
Comment on attachment 238822 [details]
Patch

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

r=me

> Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp:229
> +    static bool asInteger(InspectorValue& value, int& output) { return value.asInteger(output); }
> +    static bool asDouble(InspectorValue& value, double& output) { return value.asDouble(output); }
> +    static bool asString(InspectorValue& value, String& output) { return value.asString(output); }
> +    static bool asBoolean(InspectorValue& value, bool& output) { return value.asBoolean(output); }
> +    static bool asObject(InspectorValue& value, RefPtr<InspectorObject>& output) { return value.asObject(output); }
> +    static bool asArray(InspectorValue& value, RefPtr<InspectorArray>& output) { return value.asArray(output); }

Nit: "const" InspectorValue& value

> Source/JavaScriptCore/inspector/InspectorValues.cpp:334
> +        output = "";

Nit: We should use String() or emptyString() instead of "".

> Source/JavaScriptCore/inspector/InspectorValues.cpp:684
> +            output.append(trueString, 4);

I think we can change all of these append(const char*, unsigned) into appendLiteral(const char*). Which will have the compiler computer the length and call append(const char*, unsigned) for us. But that could be done separately.

> Source/JavaScriptCore/inspector/InspectorValues.cpp:765
> +    return result;

Nit: .release()

> Source/JavaScriptCore/inspector/InspectorValues.cpp:776
> +    return result;

Nit: .release()

> Source/JavaScriptCore/inspector/InspectorValues.h:87
> +    static bool parseJSON(const String& jsonInput, RefPtr<InspectorValue>& output);

I liked the original parseJSON just fine. This seems fine though. Do you see an advantage?

> Source/WebCore/inspector/InspectorIndexedDBAgent.cpp:340
>      if (type == number) {
>          double number;
> -        if (!key->getDouble("number", &number))
> +        if (!key->getDouble("number", number))

I don't like the shadowing of variables.

outer scope: NeverDestroyed<const String> number(ASCIILiteral("number"));
inner scope: double number;

But you are not changing this.
Comment 5 Brian Burg 2014-09-29 14:16:03 PDT
Comment on attachment 238822 [details]
Patch

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

>> Source/JavaScriptCore/inspector/InspectorValues.cpp:334
>> +        output = "";
> 
> Nit: We should use String() or emptyString() instead of "".

OK. (My next plan was to make ErrorString everywhere a reference, but this would of course completely clash with this patch)

>> Source/JavaScriptCore/inspector/InspectorValues.cpp:684
>> +            output.append(trueString, 4);
> 
> I think we can change all of these append(const char*, unsigned) into appendLiteral(const char*). Which will have the compiler computer the length and call append(const char*, unsigned) for us. But that could be done separately.

had never thought of it, but sure!

>> Source/JavaScriptCore/inspector/InspectorValues.h:87
>> +    static bool parseJSON(const String& jsonInput, RefPtr<InspectorValue>& output);
> 
> I liked the original parseJSON just fine. This seems fine though. Do you see an advantage?

I prefer the slightly more cumbersome outparam approach, because it forces callers to handle parse failure (or look suspicious not doing so).  This patch standardizes on that pattern (for object and array casts/gets, too).

>> Source/WebCore/inspector/InspectorIndexedDBAgent.cpp:340
>> +        if (!key->getDouble("number", number))
> 
> I don't like the shadowing of variables.
> 
> outer scope: NeverDestroyed<const String> number(ASCIILiteral("number"));
> inner scope: double number;
> 
> But you are not changing this.

yuck, i'll rename the literals.
Comment 6 Brian Burg 2014-09-29 20:30:57 PDT
Committed r174094: <http://trac.webkit.org/changeset/174094>