Source/JavaScriptCore:
Web Inspector: disambiguate double and integer primitive types in the protocol
https://bugs.webkit.org/show_bug.cgi?id=136606

Reviewed by Timothy Hatcher.

Right now it's really easy to mix up doubles and integers when serializing or deserializing
values for the inspector protocol. This patch disambiguates setting/getting doubles and integers
so that it is clearer as to which type is intended.

A new InspectorValue::Type is added for Integer types, and the Number type is renamed to Double.
The existing callsites for asNumber/getNumber/setNumber have been fixed.

Address various integration points to make sure the right type tag is assigned to InspectorValues.

* bindings/ScriptValue.cpp:
(Deprecated::jsToInspectorValue): Make an Integer if the JSValue is Int52 or smaller.
* inspector/InjectedScriptManager.cpp:
(Inspector::InjectedScriptManager::injectedScriptForObjectId):
* inspector/InspectorBackendDispatcher.cpp:
(Inspector::InspectorBackendDispatcher::dispatch):
(Inspector::InspectorBackendDispatcher::sendResponse):
(Inspector::InspectorBackendDispatcher::reportProtocolError):
(Inspector::AsMethodBridges::asInteger):
(Inspector::AsMethodBridges::asDouble):
(Inspector::InspectorBackendDispatcher::getInteger):
(Inspector::InspectorBackendDispatcher::getDouble):
(Inspector::AsMethodBridges::asInt): Deleted.
(Inspector::InspectorBackendDispatcher::getInt): Deleted.
* inspector/InspectorBackendDispatcher.h:
* inspector/InspectorProtocolTypes.h: Remove the special case for checking int type tags.
(Inspector::Protocol::ArrayItemHelper<int>::Traits::pushRaw):
(Inspector::Protocol::ArrayItemHelper<double>::Traits::pushRaw):
(Inspector::Protocol::BindingTraits<int>::assertValueHasExpectedType): Deleted.
* inspector/InspectorValues.cpp: Allow integers and doubles to be convertible using asInteger/asDouble.
(Inspector::InspectorValue::asDouble):
(Inspector::InspectorValue::asInteger):
(Inspector::InspectorBasicValue::asDouble):
(Inspector::InspectorBasicValue::asInteger):
(Inspector::InspectorBasicValue::writeJSON):
(Inspector::InspectorValue::asNumber): Deleted.
(Inspector::InspectorBasicValue::asNumber): Deleted.
* inspector/InspectorValues.h:
(Inspector::InspectorObjectBase::setInteger):
(Inspector::InspectorObjectBase::setDouble):
(Inspector::InspectorArrayBase::pushInteger):
(Inspector::InspectorArrayBase::pushDouble):
(Inspector::InspectorObjectBase::setNumber): Deleted.
(Inspector::InspectorArrayBase::pushInt): Deleted.
(Inspector::InspectorArrayBase::pushNumber): Deleted.
* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::buildObjectForBreakpointCookie):
(Inspector::InspectorDebuggerAgent::breakpointActionsFromProtocol):
(Inspector::parseLocation):
(Inspector::InspectorDebuggerAgent::didParseSource):
* inspector/agents/InspectorRuntimeAgent.cpp:
(Inspector::InspectorRuntimeAgent::getRuntimeTypesForVariablesAtOffsets):
* inspector/scripts/codegen/generator.py: Update emitted code and rebaseline test results.
(Generator.keyed_get_method_for_type):
(Generator.keyed_set_method_for_type):
* inspector/scripts/tests/expected/commands-with-async-attribute.json-result:
* inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result:
* inspector/scripts/tests/expected/domains-with-varying-command-sizes.json-result:
* inspector/scripts/tests/expected/events-with-optional-parameters.json-result:
* inspector/scripts/tests/expected/generate-domains-with-feature-guards.json-result:
* inspector/scripts/tests/expected/type-declaration-object-type.json-result:
* inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result:
* replay/EncodedValue.cpp:
(JSC::EncodedValue::convertTo<double>):
(JSC::EncodedValue::convertTo<float>):
(JSC::EncodedValue::convertTo<int32_t>):
(JSC::EncodedValue::convertTo<int64_t>):
(JSC::EncodedValue::convertTo<uint32_t>):
(JSC::EncodedValue::convertTo<uint64_t>):

Source/WebCore:
Web Inspector: disambiguate integral and real number primitive types in the protocol
https://bugs.webkit.org/show_bug.cgi?id=136606

Reviewed by Timothy Hatcher.

Update clients of InspectorValue to disambiguate integer and double primitive types.

No new tests, no behavior changed.

* inspector/InspectorDOMAgent.cpp:
(WebCore::parseColor):
(WebCore::parseQuad):
(WebCore::InspectorDOMAgent::performSearch):
* inspector/InspectorDOMDebuggerAgent.cpp:
(WebCore::InspectorDOMDebuggerAgent::descriptionForDOMEvent):
* inspector/InspectorIndexedDBAgent.cpp:
* inspector/InspectorOverlay.cpp:
(WebCore::buildObjectForPoint):
(WebCore::buildObjectForRect):
(WebCore::buildObjectForSize):
(WebCore::appendPathCommandAndPoints):
(WebCore::InspectorOverlay::reset):
* inspector/InspectorReplayAgent.cpp:
(WebCore::InspectorReplayAgent::replayToPosition):
* inspector/InspectorStyleSheet.h:
(WebCore::InspectorCSSId::InspectorCSSId):
* inspector/InspectorTimelineAgent.cpp:
(WebCore::InspectorTimelineAgent::didWriteHTML):
(WebCore::InspectorTimelineAgent::didCompleteRecordEntry):
* inspector/TimelineRecordFactory.cpp:
(WebCore::TimelineRecordFactory::createGenericRecord):
(WebCore::TimelineRecordFactory::createBackgroundRecord):
(WebCore::TimelineRecordFactory::createGCEventData):
(WebCore::TimelineRecordFactory::createFunctionCallData):
(WebCore::TimelineRecordFactory::createProbeSampleData):
(WebCore::TimelineRecordFactory::createGenericTimerData):
(WebCore::TimelineRecordFactory::createTimerInstallData):
(WebCore::TimelineRecordFactory::createXHRReadyStateChangeData):
(WebCore::TimelineRecordFactory::createEvaluateScriptData):
(WebCore::TimelineRecordFactory::createResourceReceiveResponseData):
(WebCore::TimelineRecordFactory::createResourceFinishData):
(WebCore::TimelineRecordFactory::createReceiveResourceData):
(WebCore::TimelineRecordFactory::createLayoutData):
(WebCore::TimelineRecordFactory::createParseHTMLData):
(WebCore::TimelineRecordFactory::createAnimationFrameData):
(WebCore::createQuad):
* inspector/TimelineRecordFactory.h:
(WebCore::TimelineRecordFactory::createWebSocketCreateData):
(WebCore::TimelineRecordFactory::createGenericWebSocketData):
* page/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::reportViolation):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@173554 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/inspector/InspectorValues.h b/Source/JavaScriptCore/inspector/InspectorValues.h
index 97cb88b..d30e9b3 100644
--- a/Source/JavaScriptCore/inspector/InspectorValues.h
+++ b/Source/JavaScriptCore/inspector/InspectorValues.h
@@ -58,7 +58,8 @@
     enum class Type {
         Null = 0,
         Boolean,
-        Number,
+        Double,
+        Integer,
         String,
         Object,
         Array
@@ -69,14 +70,14 @@
     bool isNull() const { return m_type == Type::Null; }
 
     virtual bool asBoolean(bool* output) const;
-    virtual bool asNumber(double* output) const;
-    virtual bool asNumber(float* output) const;
-    virtual bool asNumber(int* output) const;
-    virtual bool asNumber(unsigned* output) const;
-    virtual bool asNumber(long* output) const;
-    virtual bool asNumber(long long* output) const;
-    virtual bool asNumber(unsigned long* output) const;
-    virtual bool asNumber(unsigned long long* output) const;
+    virtual bool asInteger(int* output) const;
+    virtual bool asInteger(unsigned* output) const;
+    virtual bool asInteger(long* output) const;
+    virtual bool asInteger(long long* output) const;
+    virtual bool asInteger(unsigned long* output) const;
+    virtual bool asInteger(unsigned long long* output) const;
+    virtual bool asDouble(double* output) const;
+    virtual bool asDouble(float* output) const;
     virtual bool asString(String* output) const;
     virtual bool asValue(RefPtr<InspectorValue>* output);
     virtual bool asObject(RefPtr<InspectorObject>* output);
@@ -104,14 +105,16 @@
     static PassRefPtr<InspectorBasicValue> create(double);
 
     virtual bool asBoolean(bool* output) const override;
-    virtual bool asNumber(double* output) const override;
-    virtual bool asNumber(float* output) const override;
-    virtual bool asNumber(int* output) const override;
-    virtual bool asNumber(unsigned* output) const override;
-    virtual bool asNumber(long* output) const override;
-    virtual bool asNumber(long long* output) const override;
-    virtual bool asNumber(unsigned long* output) const override;
-    virtual bool asNumber(unsigned long long* output) const override;
+    // Numbers from the frontend are always parsed as doubles, so we allow
+    // clients to convert to integral values with this function.
+    virtual bool asInteger(int* output) const override;
+    virtual bool asInteger(unsigned* output) const override;
+    virtual bool asInteger(long* output) const override;
+    virtual bool asInteger(long long* output) const override;
+    virtual bool asInteger(unsigned long* output) const override;
+    virtual bool asInteger(unsigned long long* output) const override;
+    virtual bool asDouble(double* output) const override;
+    virtual bool asDouble(float* output) const override;
 
     virtual void writeJSON(StringBuilder* output) const override;
 
@@ -121,11 +124,11 @@
         , m_boolValue(value) { }
 
     explicit InspectorBasicValue(int value)
-        : InspectorValue(Type::Number)
+        : InspectorValue(Type::Integer)
         , m_doubleValue(static_cast<double>(value)) { }
 
     explicit InspectorBasicValue(double value)
-        : InspectorValue(Type::Number)
+        : InspectorValue(Type::Double)
         , m_doubleValue(value) { }
 
     union {
@@ -171,8 +174,10 @@
 
     virtual bool asObject(RefPtr<InspectorObject>* output) override;
 
+    // FIXME: use templates to reduce the amount of duplicated set*() methods.
     void setBoolean(const String& name, bool);
-    void setNumber(const String& name, double);
+    void setInteger(const String& name, int);
+    void setDouble(const String& name, double);
     void setString(const String& name, const String&);
     void setValue(const String& name, PassRefPtr<InspectorValue>);
     void setObject(const String& name, PassRefPtr<InspectorObjectBase>);
@@ -180,14 +185,24 @@
 
     iterator find(const String& name);
     const_iterator find(const String& name) const;
+
+    // FIXME: use templates to reduce the amount of duplicated get*() methods.
     bool getBoolean(const String& name, bool* output) const;
-    template<class T> bool getNumber(const String& name, T* output) const
+    template<class T> bool getDouble(const String& name, T* output) const
     {
         RefPtr<InspectorValue> value = get(name);
         if (!value)
             return false;
-        return value->asNumber(output);
+        return value->asDouble(output);
     }
+    template<class T> bool getInteger(const String& name, T* output) const
+    {
+        RefPtr<InspectorValue> value = get(name);
+        if (!value)
+            return false;
+        return value->asInteger(output);
+    }
+
     bool getString(const String& name, String* output) const;
     PassRefPtr<InspectorObject> getObject(const String& name) const;
     PassRefPtr<InspectorArray> getArray(const String& name) const;
@@ -219,7 +234,8 @@
     using InspectorObjectBase::asObject;
 
     using InspectorObjectBase::setBoolean;
-    using InspectorObjectBase::setNumber;
+    using InspectorObjectBase::setInteger;
+    using InspectorObjectBase::setDouble;
     using InspectorObjectBase::setString;
     using InspectorObjectBase::setValue;
     using InspectorObjectBase::setObject;
@@ -227,7 +243,8 @@
 
     using InspectorObjectBase::find;
     using InspectorObjectBase::getBoolean;
-    using InspectorObjectBase::getNumber;
+    using InspectorObjectBase::getInteger;
+    using InspectorObjectBase::getDouble;
     using InspectorObjectBase::getString;
     using InspectorObjectBase::getObject;
     using InspectorObjectBase::getArray;
@@ -257,8 +274,8 @@
     virtual bool asArray(RefPtr<InspectorArray>* output) override;
 
     void pushBoolean(bool);
-    void pushInt(int);
-    void pushNumber(double);
+    void pushInteger(int);
+    void pushDouble(double);
     void pushString(const String&);
     void pushValue(PassRefPtr<InspectorValue>);
     void pushObject(PassRefPtr<InspectorObject>);
@@ -287,8 +304,8 @@
     using InspectorArrayBase::asArray;
 
     using InspectorArrayBase::pushBoolean;
-    using InspectorArrayBase::pushInt;
-    using InspectorArrayBase::pushNumber;
+    using InspectorArrayBase::pushInteger;
+    using InspectorArrayBase::pushDouble;
     using InspectorArrayBase::pushString;
     using InspectorArrayBase::pushValue;
     using InspectorArrayBase::pushObject;
@@ -316,7 +333,12 @@
     setValue(name, InspectorBasicValue::create(value));
 }
 
-inline void InspectorObjectBase::setNumber(const String& name, double value)
+inline void InspectorObjectBase::setInteger(const String& name, int value)
+{
+    setValue(name, InspectorBasicValue::create(value));
+}
+
+inline void InspectorObjectBase::setDouble(const String& name, double value)
 {
     setValue(name, InspectorBasicValue::create(value));
 }
@@ -352,12 +374,12 @@
     m_data.append(InspectorBasicValue::create(value));
 }
 
-inline void InspectorArrayBase::pushInt(int value)
+inline void InspectorArrayBase::pushInteger(int value)
 {
     m_data.append(InspectorBasicValue::create(value));
 }
 
-inline void InspectorArrayBase::pushNumber(double value)
+inline void InspectorArrayBase::pushDouble(double value)
 {
     m_data.append(InspectorBasicValue::create(value));
 }