Title: [199320] trunk/Source
Revision
199320
Author
[email protected]
Date
2016-04-11 16:22:16 -0700 (Mon, 11 Apr 2016)

Log Message

Web Inspector: get rid of InspectorBasicValue and InspectorString subclasses
https://bugs.webkit.org/show_bug.cgi?id=156407
<rdar://problem/25627659>

Reviewed by Joseph Pecoraro.

Source/_javascript_Core:

There's no point having these subclasses as they don't save any space.
Add a StringImpl to the union and merge some implementations of writeJSON.

Rename m_data to m_map and explicitly name the union as InspectorValue::m_value.
If the value is a string and the string is not empty or null (i.e., it has a
StringImpl), then we need to ref() and deref() the string as the InspectorValue
is created or destroyed.

Move uses of the subclass to InspectorValue and delete redundant methods.
Now, most InspectorValue methods are non-virtual so they can be templated.

* bindings/ScriptValue.cpp:
(Deprecated::jsToInspectorValue):
* inspector/InjectedScriptBase.cpp:
(Inspector::InjectedScriptBase::makeCall):
Don't used deleted subclasses.

* inspector/InspectorValues.cpp:
(Inspector::InspectorValue::null):
(Inspector::InspectorValue::create):
(Inspector::InspectorValue::asValue):
(Inspector::InspectorValue::asBoolean):
(Inspector::InspectorValue::asDouble):
(Inspector::InspectorValue::asInteger):
(Inspector::InspectorValue::asString):
These only need one implementation now.

(Inspector::InspectorValue::writeJSON):
Still a virtual method since Object and Array need their members.

(Inspector::InspectorObjectBase::InspectorObjectBase):
(Inspector::InspectorBasicValue::asBoolean): Deleted.
(Inspector::InspectorBasicValue::asDouble): Deleted.
(Inspector::InspectorBasicValue::asInteger): Deleted.
(Inspector::InspectorBasicValue::writeJSON): Deleted.
(Inspector::InspectorString::asString): Deleted.
(Inspector::InspectorString::writeJSON): Deleted.
(Inspector::InspectorString::create): Deleted.
(Inspector::InspectorBasicValue::create): Deleted.

* inspector/InspectorValues.h:
(Inspector::InspectorObjectBase::find):
(Inspector::InspectorObjectBase::setBoolean):
(Inspector::InspectorObjectBase::setInteger):
(Inspector::InspectorObjectBase::setDouble):
(Inspector::InspectorObjectBase::setString):
(Inspector::InspectorObjectBase::setValue):
(Inspector::InspectorObjectBase::setObject):
(Inspector::InspectorObjectBase::setArray):
(Inspector::InspectorArrayBase::pushBoolean):
(Inspector::InspectorArrayBase::pushInteger):
(Inspector::InspectorArrayBase::pushDouble):
(Inspector::InspectorArrayBase::pushString):
(Inspector::InspectorArrayBase::pushValue):
(Inspector::InspectorArrayBase::pushObject):
(Inspector::InspectorArrayBase::pushArray):
Use new factory methods.

* replay/EncodedValue.cpp:
(JSC::ScalarEncodingTraits<bool>::encodeValue):
(JSC::ScalarEncodingTraits<double>::encodeValue):
(JSC::ScalarEncodingTraits<float>::encodeValue):
(JSC::ScalarEncodingTraits<int32_t>::encodeValue):
(JSC::ScalarEncodingTraits<int64_t>::encodeValue):
(JSC::ScalarEncodingTraits<uint32_t>::encodeValue):
(JSC::ScalarEncodingTraits<uint64_t>::encodeValue):
* replay/EncodedValue.h:
Use new factory methods.

Source/WebCore:

* inspector/InspectorDatabaseAgent.cpp: Don't use deleted subclasses.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (199319 => 199320)


--- trunk/Source/_javascript_Core/ChangeLog	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-04-11 23:22:16 UTC (rev 199320)
@@ -1,3 +1,80 @@
+2016-04-11  Brian Burg  <[email protected]>
+
+        Web Inspector: get rid of InspectorBasicValue and InspectorString subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=156407
+        <rdar://problem/25627659>
+
+        Reviewed by Joseph Pecoraro.
+
+        There's no point having these subclasses as they don't save any space.
+        Add a StringImpl to the union and merge some implementations of writeJSON.
+
+        Rename m_data to m_map and explicitly name the union as InspectorValue::m_value.
+        If the value is a string and the string is not empty or null (i.e., it has a
+        StringImpl), then we need to ref() and deref() the string as the InspectorValue
+        is created or destroyed.
+
+        Move uses of the subclass to InspectorValue and delete redundant methods.
+        Now, most InspectorValue methods are non-virtual so they can be templated.
+
+        * bindings/ScriptValue.cpp:
+        (Deprecated::jsToInspectorValue):
+        * inspector/InjectedScriptBase.cpp:
+        (Inspector::InjectedScriptBase::makeCall):
+        Don't used deleted subclasses.
+
+        * inspector/InspectorValues.cpp:
+        (Inspector::InspectorValue::null):
+        (Inspector::InspectorValue::create):
+        (Inspector::InspectorValue::asValue):
+        (Inspector::InspectorValue::asBoolean):
+        (Inspector::InspectorValue::asDouble):
+        (Inspector::InspectorValue::asInteger):
+        (Inspector::InspectorValue::asString):
+        These only need one implementation now.
+
+        (Inspector::InspectorValue::writeJSON):
+        Still a virtual method since Object and Array need their members.
+
+        (Inspector::InspectorObjectBase::InspectorObjectBase):
+        (Inspector::InspectorBasicValue::asBoolean): Deleted.
+        (Inspector::InspectorBasicValue::asDouble): Deleted.
+        (Inspector::InspectorBasicValue::asInteger): Deleted.
+        (Inspector::InspectorBasicValue::writeJSON): Deleted.
+        (Inspector::InspectorString::asString): Deleted.
+        (Inspector::InspectorString::writeJSON): Deleted.
+        (Inspector::InspectorString::create): Deleted.
+        (Inspector::InspectorBasicValue::create): Deleted.
+
+        * inspector/InspectorValues.h:
+        (Inspector::InspectorObjectBase::find):
+        (Inspector::InspectorObjectBase::setBoolean):
+        (Inspector::InspectorObjectBase::setInteger):
+        (Inspector::InspectorObjectBase::setDouble):
+        (Inspector::InspectorObjectBase::setString):
+        (Inspector::InspectorObjectBase::setValue):
+        (Inspector::InspectorObjectBase::setObject):
+        (Inspector::InspectorObjectBase::setArray):
+        (Inspector::InspectorArrayBase::pushBoolean):
+        (Inspector::InspectorArrayBase::pushInteger):
+        (Inspector::InspectorArrayBase::pushDouble):
+        (Inspector::InspectorArrayBase::pushString):
+        (Inspector::InspectorArrayBase::pushValue):
+        (Inspector::InspectorArrayBase::pushObject):
+        (Inspector::InspectorArrayBase::pushArray):
+        Use new factory methods.
+
+        * replay/EncodedValue.cpp:
+        (JSC::ScalarEncodingTraits<bool>::encodeValue):
+        (JSC::ScalarEncodingTraits<double>::encodeValue):
+        (JSC::ScalarEncodingTraits<float>::encodeValue):
+        (JSC::ScalarEncodingTraits<int32_t>::encodeValue):
+        (JSC::ScalarEncodingTraits<int64_t>::encodeValue):
+        (JSC::ScalarEncodingTraits<uint32_t>::encodeValue):
+        (JSC::ScalarEncodingTraits<uint64_t>::encodeValue):
+        * replay/EncodedValue.h:
+        Use new factory methods.
+
 2016-04-11  Filip Pizlo  <[email protected]>
 
         It should be possible to edit StructureStubInfo without recompiling the world

Modified: trunk/Source/_javascript_Core/bindings/ScriptValue.cpp (199319 => 199320)


--- trunk/Source/_javascript_Core/bindings/ScriptValue.cpp	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/_javascript_Core/bindings/ScriptValue.cpp	2016-04-11 23:22:16 UTC (rev 199320)
@@ -112,13 +112,13 @@
     if (value.isNull() || value.isUndefined())
         return InspectorValue::null();
     if (value.isBoolean())
-        return InspectorBasicValue::create(value.asBoolean());
+        return InspectorValue::create(value.asBoolean());
     if (value.isNumber() && value.isDouble())
-        return InspectorBasicValue::create(value.asNumber());
+        return InspectorValue::create(value.asNumber());
     if (value.isNumber() && value.isMachineInt())
-        return InspectorBasicValue::create(static_cast<int>(value.asMachineInt()));
+        return InspectorValue::create(static_cast<int>(value.asMachineInt()));
     if (value.isString())
-        return InspectorString::create(value.getString(scriptState));
+        return InspectorValue::create(value.getString(scriptState));
 
     if (value.isObject()) {
         if (isJSArray(value)) {

Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp (199319 => 199320)


--- trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp	2016-04-11 23:22:16 UTC (rev 199320)
@@ -99,9 +99,9 @@
     if (!hadException) {
         *result = resultValue.toInspectorValue(m_injectedScriptObject.scriptState());
         if (!*result)
-            *result = InspectorString::create(String::format("Object has too long reference chain (must not be longer than %d)", InspectorValue::maxDepth));
+            *result = InspectorValue::create(String::format("Object has too long reference chain (must not be longer than %d)", InspectorValue::maxDepth));
     } else
-        *result = InspectorString::create("Exception while making a call.");
+        *result = InspectorValue::create("Exception while making a call.");
 }
 
 void InjectedScriptBase::makeEvalCall(ErrorString& errorString, Deprecated::ScriptFunctionCall& function, RefPtr<Protocol::Runtime::RemoteObject>* objectResult, Protocol::OptOutput<bool>* wasThrown, Protocol::OptOutput<int>* savedResultIndex)

Modified: trunk/Source/_javascript_Core/inspector/InspectorValues.cpp (199319 => 199320)


--- trunk/Source/_javascript_Core/inspector/InspectorValues.cpp	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/_javascript_Core/inspector/InspectorValues.cpp	2016-04-11 23:22:16 UTC (rev 199320)
@@ -363,17 +363,17 @@
         result = InspectorValue::null();
         break;
     case BOOL_TRUE:
-        result = InspectorBasicValue::create(true);
+        result = InspectorValue::create(true);
         break;
     case BOOL_FALSE:
-        result = InspectorBasicValue::create(false);
+        result = InspectorValue::create(false);
         break;
     case NUMBER: {
         bool ok;
         double value = charactersToDouble(tokenStart, tokenEnd - tokenStart, &ok);
         if (!ok)
             return nullptr;
-        result = InspectorBasicValue::create(value);
+        result = InspectorValue::create(value);
         break;
     }
     case STRING: {
@@ -381,7 +381,7 @@
         bool ok = decodeString(tokenStart + 1, tokenEnd - 1, value);
         if (!ok)
             return nullptr;
-        result = InspectorString::create(value);
+        result = InspectorValue::create(value);
         break;
     }
     case ARRAY_BEGIN: {
@@ -498,59 +498,39 @@
 
 } // anonymous namespace
 
-bool InspectorValue::asBoolean(bool&) const
+Ref<InspectorValue> InspectorValue::null()
 {
-    return false;
+    return adoptRef(*new InspectorValue);
 }
 
-bool InspectorValue::asDouble(double&) const
+Ref<InspectorValue> InspectorValue::create(bool value)
 {
-    return false;
+    return adoptRef(*new InspectorValue(value));
 }
 
-bool InspectorValue::asDouble(float&) const
+Ref<InspectorValue> InspectorValue::create(int value)
 {
-    return false;
+    return adoptRef(*new InspectorValue(value));
 }
 
-bool InspectorValue::asInteger(int&) const
+Ref<InspectorValue> InspectorValue::create(double value)
 {
-    return false;
+    return adoptRef(*new InspectorValue(value));
 }
 
-bool InspectorValue::asInteger(unsigned&) const
+Ref<InspectorValue> InspectorValue::create(const String& value)
 {
-    return false;
+    return adoptRef(*new InspectorValue(value));
 }
 
-bool InspectorValue::asInteger(long&) const
+Ref<InspectorValue> InspectorValue::create(const char* value)
 {
-    return false;
+    return adoptRef(*new InspectorValue(value));
 }
 
-bool InspectorValue::asInteger(long long&) const
+bool InspectorValue::asValue(RefPtr<Inspector::InspectorValue> & value)
 {
-    return false;
-}
-
-bool InspectorValue::asInteger(unsigned long&) const
-{
-    return false;
-}
-
-bool InspectorValue::asInteger(unsigned long long&) const
-{
-    return false;
-}
-
-bool InspectorValue::asString(String&) const
-{
-    return false;
-}
-
-bool InspectorValue::asValue(RefPtr<InspectorValue>& output)
-{
-    output = this;
+    value = this;
     return true;
 }
 
@@ -587,110 +567,119 @@
     return result.toString();
 }
 
-void InspectorValue::writeJSON(StringBuilder& output) const
+bool InspectorValue::asBoolean(bool& output) const
 {
-    ASSERT(m_type == Type::Null);
-
-    output.appendLiteral("null");
-}
-
-bool InspectorBasicValue::asBoolean(bool& output) const
-{
     if (type() != Type::Boolean)
         return false;
 
-    output = m_booleanValue;
+    output = m_value.boolean;
     return true;
 }
 
-bool InspectorBasicValue::asDouble(double& output) const
+bool InspectorValue::asDouble(double& output) const
 {
     if (type() != Type::Double)
         return false;
 
-    output = m_doubleValue;
+    output = m_value.number;
     return true;
 }
 
-bool InspectorBasicValue::asDouble(float& output) const
+bool InspectorValue::asDouble(float& output) const
 {
     if (type() != Type::Double)
         return false;
 
-    output = static_cast<float>(m_doubleValue);
+    output = static_cast<float>(m_value.number);
     return true;
 }
 
-bool InspectorBasicValue::asInteger(int& output) const
+bool InspectorValue::asInteger(int& output) const
 {
     if (type() != Type::Integer && type() != Type::Double)
         return false;
 
-    output = static_cast<int>(m_doubleValue);
+    output = static_cast<int>(m_value.number);
     return true;
 }
 
-bool InspectorBasicValue::asInteger(unsigned& output) const
+bool InspectorValue::asInteger(unsigned& output) const
 {
     if (type() != Type::Integer && type() != Type::Double)
         return false;
 
-    output = static_cast<unsigned>(m_doubleValue);
+    output = static_cast<unsigned>(m_value.number);
     return true;
 }
 
-bool InspectorBasicValue::asInteger(long& output) const
+bool InspectorValue::asInteger(long& output) const
 {
     if (type() != Type::Integer && type() != Type::Double)
         return false;
 
-    output = static_cast<long>(m_doubleValue);
+    output = static_cast<long>(m_value.number);
     return true;
 }
 
-bool InspectorBasicValue::asInteger(long long& output) const
+bool InspectorValue::asInteger(long long& output) const
 {
     if (type() != Type::Integer && type() != Type::Double)
         return false;
 
-    output = static_cast<long long>(m_doubleValue);
+    output = static_cast<long long>(m_value.number);
     return true;
 }
 
-bool InspectorBasicValue::asInteger(unsigned long& output) const
+bool InspectorValue::asInteger(unsigned long& output) const
 {
     if (type() != Type::Integer && type() != Type::Double)
         return false;
 
-    output = static_cast<unsigned long>(m_doubleValue);
+    output = static_cast<unsigned long>(m_value.number);
     return true;
 }
 
-bool InspectorBasicValue::asInteger(unsigned long long& output) const
+bool InspectorValue::asInteger(unsigned long long& output) const
 {
     if (type() != Type::Integer && type() != Type::Double)
         return false;
 
-    output = static_cast<unsigned long long>(m_doubleValue);
+    output = static_cast<unsigned long long>(m_value.number);
     return true;
 }
 
-void InspectorBasicValue::writeJSON(StringBuilder& output) const
+bool InspectorValue::asString(String& output) const
 {
-    ASSERT(type() == Type::Boolean || type() == Type::Double || type() == Type::Integer);
+    if (type() != Type::String)
+        return false;
 
-    if (type() == Type::Boolean) {
-        if (m_booleanValue)
+    output = m_value.string;
+    return true;
+}
+
+void InspectorValue::writeJSON(StringBuilder& output) const
+{
+    switch (m_type) {
+    case Type::Null:
+        output.appendLiteral("null");
+        break;
+    case Type::Boolean:
+        if (m_value.boolean)
             output.appendLiteral("true");
         else
             output.appendLiteral("false");
-    } else if (type() == Type::Double || type() == Type::Integer) {
+        break;
+    case Type::String:
+        doubleQuoteString(m_value.string, output);
+        break;
+    case Type::Double:
+    case Type::Integer: {
         NumberToLStringBuffer buffer;
-        if (!std::isfinite(m_doubleValue)) {
+        if (!std::isfinite(m_value.number)) {
             output.appendLiteral("null");
             return;
         }
-        DecimalNumber decimal = m_doubleValue;
+        DecimalNumber decimal = m_value.number;
         unsigned length = 0;
         if (decimal.bufferLengthForStringDecimal() > WTF::NumberToStringBufferLength) {
             // Not enough room for decimal. Use exponential format.
@@ -703,21 +692,13 @@
         } else
             length = decimal.toStringDecimal(buffer, WTF::NumberToStringBufferLength);
         output.append(buffer, length);
+        break;
     }
+    default:
+        ASSERT_NOT_REACHED();
+    }
 }
 
-bool InspectorString::asString(String& output) const
-{
-    output = m_stringValue;
-    return true;
-}
-
-void InspectorString::writeJSON(StringBuilder& output) const
-{
-    ASSERT(type() == Type::String);
-    doubleQuoteString(m_stringValue, output);
-}
-
 InspectorObjectBase::~InspectorObjectBase()
 {
 }
@@ -775,8 +756,8 @@
 
 bool InspectorObjectBase::getValue(const String& name, RefPtr<InspectorValue>& output) const
 {
-    Dictionary::const_iterator findResult = m_data.find(name);
-    if (findResult == m_data.end())
+    Dictionary::const_iterator findResult = m_map.find(name);
+    if (findResult == m_map.end())
         return false;
 
     output = findResult->value;
@@ -785,7 +766,7 @@
 
 void InspectorObjectBase::remove(const String& name)
 {
-    m_data.remove(name);
+    m_map.remove(name);
     m_order.removeFirst(name);
 }
 
@@ -793,8 +774,8 @@
 {
     output.append('{');
     for (size_t i = 0; i < m_order.size(); ++i) {
-        auto findResult = m_data.find(m_order[i]);
-        ASSERT(findResult != m_data.end());
+        auto findResult = m_map.find(m_order[i]);
+        ASSERT(findResult != m_map.end());
         if (i)
             output.append(',');
         doubleQuoteString(findResult->key, output);
@@ -805,8 +786,8 @@
 }
 
 InspectorObjectBase::InspectorObjectBase()
-    : InspectorValue(Type::Object)
-    , m_data()
+    : Inspector::InspectorValue(Type::Object)
+    , m_map()
     , m_order()
 {
 }
@@ -825,8 +806,8 @@
 void InspectorArrayBase::writeJSON(StringBuilder& output) const
 {
     output.append('[');
-    for (Vector<RefPtr<InspectorValue>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {
-        if (it != m_data.begin())
+    for (Vector<RefPtr<InspectorValue>>::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
+        if (it != m_map.begin())
             output.append(',');
         (*it)->writeJSON(output);
     }
@@ -835,14 +816,14 @@
 
 InspectorArrayBase::InspectorArrayBase()
     : InspectorValue(Type::Array)
-    , m_data()
+    , m_map()
 {
 }
 
 RefPtr<InspectorValue> InspectorArrayBase::get(size_t index) const
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size());
-    return m_data[index];
+    ASSERT_WITH_SECURITY_IMPLICATION(index < m_map.size());
+    return m_map[index];
 }
 
 Ref<InspectorObject> InspectorObject::create()
@@ -855,34 +836,4 @@
     return adoptRef(*new InspectorArray);
 }
 
-Ref<InspectorValue> InspectorValue::null()
-{
-    return adoptRef(*new InspectorValue);
-}
-
-Ref<InspectorString> InspectorString::create(const String& value)
-{
-    return adoptRef(*new InspectorString(value));
-}
-
-Ref<InspectorString> InspectorString::create(const char* value)
-{
-    return adoptRef(*new InspectorString(value));
-}
-
-Ref<InspectorBasicValue> InspectorBasicValue::create(bool value)
-{
-    return adoptRef(*new InspectorBasicValue(value));
-}
-
-Ref<InspectorBasicValue> InspectorBasicValue::create(int value)
-{
-    return adoptRef(*new InspectorBasicValue(value));
-}
-
-Ref<InspectorBasicValue> InspectorBasicValue::create(double value)
-{
-    return adoptRef(*new InspectorBasicValue(value));
-}
-
 } // namespace Inspector

Modified: trunk/Source/_javascript_Core/inspector/InspectorValues.h (199319 => 199320)


--- trunk/Source/_javascript_Core/inspector/InspectorValues.h	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/_javascript_Core/inspector/InspectorValues.h	2016-04-11 23:22:16 UTC (rev 199320)
@@ -51,11 +51,30 @@
 public:
     static const int maxDepth = 1000;
 
-    InspectorValue()
-        : m_type(Type::Null) { }
-    virtual ~InspectorValue() { }
+    virtual ~InspectorValue()
+    {
+        switch (m_type) {
+        case Type::Null:
+        case Type::Boolean:
+        case Type::Double:
+        case Type::Integer:
+            break;
+        case Type::String:
+            if (m_value.string)
+                m_value.string->deref();
+            break;
+        case Type::Object:
+        case Type::Array:
+            break;
+        }
+    }
 
     static Ref<InspectorValue> null();
+    static Ref<InspectorValue> create(bool);
+    static Ref<InspectorValue> create(int);
+    static Ref<InspectorValue> create(double);
+    static Ref<InspectorValue> create(const String&);
+    static Ref<InspectorValue> create(const char*);
 
     enum class Type {
         Null = 0,
@@ -64,24 +83,24 @@
         Integer,
         String,
         Object,
-        Array
+        Array,
     };
 
     Type type() const { return m_type; }
-
     bool isNull() const { return m_type == Type::Null; }
 
-    virtual bool asBoolean(bool&) const;
-    virtual bool asInteger(int&) const;
-    virtual bool asInteger(unsigned&) const;
-    virtual bool asInteger(long&) const;
-    virtual bool asInteger(long long&) const;
-    virtual bool asInteger(unsigned long&) const;
-    virtual bool asInteger(unsigned long long&) const;
-    virtual bool asDouble(double&) const;
-    virtual bool asDouble(float&) const;
-    virtual bool asString(String&) const;
-    virtual bool asValue(RefPtr<InspectorValue>&);
+    bool asBoolean(bool&) const;
+    bool asInteger(int&) const;
+    bool asInteger(unsigned&) const;
+    bool asInteger(long&) const;
+    bool asInteger(long long&) const;
+    bool asInteger(unsigned long&) const;
+    bool asInteger(unsigned long long&) const;
+    bool asDouble(double&) const;
+    bool asDouble(float&) const;
+    bool asString(String&) const;
+    bool asValue(RefPtr<InspectorValue>&);
+
     virtual bool asObject(RefPtr<InspectorObject>&);
     virtual bool asArray(RefPtr<InspectorArray>&);
 
@@ -91,73 +110,56 @@
     virtual void writeJSON(StringBuilder& output) const;
 
 protected:
-    explicit InspectorValue(Type type) : m_type(type) { }
+    InspectorValue()
+        : m_type(Type::Null) { }
 
-private:
-    Type m_type;
-};
+    explicit InspectorValue(Type type)
+        : m_type(type) { }
 
-class JS_EXPORT_PRIVATE InspectorBasicValue : public InspectorValue {
-public:
+    explicit InspectorValue(bool value)
+        : m_type(Type::Boolean)
+    {
+        m_value.boolean = value;
+    }
 
-    static Ref<InspectorBasicValue> create(bool);
-    static Ref<InspectorBasicValue> create(int);
-    static Ref<InspectorBasicValue> create(double);
+    explicit InspectorValue(int value)
+        : m_type(Type::Integer)
+    {
+        m_value.number = static_cast<double>(value);
+    }
 
-    bool asBoolean(bool&) const override;
-    // Numbers from the frontend are always parsed as doubles, so we allow
-    // clients to convert to integral values with this function.
-    bool asInteger(int&) const override;
-    bool asInteger(unsigned&) const override;
-    bool asInteger(long&) const override;
-    bool asInteger(long long&) const override;
-    bool asInteger(unsigned long&) const override;
-    bool asInteger(unsigned long long&) const override;
-    bool asDouble(double&) const override;
-    bool asDouble(float&) const override;
+    explicit InspectorValue(double value)
+        : m_type(Type::Double)
+    {
+        m_value.number = value;
+    }
 
-    void writeJSON(StringBuilder& output) const override;
+    explicit InspectorValue(const String& value)
+        : m_type(Type::String)
+    {
+        m_value.string = value.impl();
+        if (m_value.string)
+            m_value.string->ref();
+    }
 
+    explicit InspectorValue(const char* value)
+        : m_type(Type::String)
+    {
+        String wrapper(value);
+        m_value.string = wrapper.impl();
+        if (m_value.string)
+            m_value.string->ref();
+    }
+
 private:
-    explicit InspectorBasicValue(bool value)
-        : InspectorValue(Type::Boolean)
-        , m_booleanValue(value) { }
-
-    explicit InspectorBasicValue(int value)
-        : InspectorValue(Type::Integer)
-        , m_doubleValue(static_cast<double>(value)) { }
-
-    explicit InspectorBasicValue(double value)
-        : InspectorValue(Type::Double)
-        , m_doubleValue(value) { }
-
+    Type m_type { Type::Null };
     union {
-        bool m_booleanValue;
-        double m_doubleValue;
-    };
+        bool boolean;
+        double number;
+        StringImpl* string;
+    } m_value;
 };
 
-class JS_EXPORT_PRIVATE InspectorString : public InspectorValue {
-public:
-    static Ref<InspectorString> create(const String&);
-    static Ref<InspectorString> create(const char*);
-
-    bool asString(String& output) const override;
-
-    void writeJSON(StringBuilder& output) const override;
-
-private:
-    explicit InspectorString(const String& value)
-        : InspectorValue(Type::String)
-        , m_stringValue(value) { }
-
-    explicit InspectorString(const char* value)
-        : InspectorValue(Type::String)
-        , m_stringValue(value) { }
-
-    String m_stringValue;
-};
-
 class JS_EXPORT_PRIVATE InspectorObjectBase : public InspectorValue {
 private:
     typedef HashMap<String, RefPtr<InspectorValue>> Dictionary;
@@ -213,18 +215,18 @@
 
     void writeJSON(StringBuilder& output) const override;
 
-    iterator begin() { return m_data.begin(); }
-    iterator end() { return m_data.end(); }
-    const_iterator begin() const { return m_data.begin(); }
-    const_iterator end() const { return m_data.end(); }
+    iterator begin() { return m_map.begin(); }
+    iterator end() { return m_map.end(); }
+    const_iterator begin() const { return m_map.begin(); }
+    const_iterator end() const { return m_map.end(); }
 
-    int size() const { return m_data.size(); }
+    int size() const { return m_map.size(); }
 
 protected:
     InspectorObjectBase();
 
 private:
-    Dictionary m_data;
+    Dictionary m_map;
     Vector<String> m_order;
 };
 
@@ -265,7 +267,7 @@
     typedef Vector<RefPtr<InspectorValue>>::iterator iterator;
     typedef Vector<RefPtr<InspectorValue>>::const_iterator const_iterator;
 
-    unsigned length() const { return static_cast<unsigned>(m_data.size()); }
+    unsigned length() const { return static_cast<unsigned>(m_map.size()); }
 
 protected:
     virtual ~InspectorArrayBase();
@@ -284,16 +286,16 @@
 
     void writeJSON(StringBuilder& output) const override;
 
-    iterator begin() { return m_data.begin(); }
-    iterator end() { return m_data.end(); }
-    const_iterator begin() const { return m_data.begin(); }
-    const_iterator end() const { return m_data.end(); }
+    iterator begin() { return m_map.begin(); }
+    iterator end() { return m_map.end(); }
+    const_iterator begin() const { return m_map.begin(); }
+    const_iterator end() const { return m_map.end(); }
 
 protected:
     InspectorArrayBase();
 
 private:
-    Vector<RefPtr<InspectorValue>> m_data;
+    Vector<RefPtr<InspectorValue>> m_map;
 };
 
 class InspectorArray : public InspectorArrayBase {
@@ -319,91 +321,91 @@
 
 inline InspectorObjectBase::iterator InspectorObjectBase::find(const String& name)
 {
-    return m_data.find(name);
+    return m_map.find(name);
 }
 
 inline InspectorObjectBase::const_iterator InspectorObjectBase::find(const String& name) const
 {
-    return m_data.find(name);
+    return m_map.find(name);
 }
 
 inline void InspectorObjectBase::setBoolean(const String& name, bool value)
 {
-    setValue(name, InspectorBasicValue::create(value));
+    setValue(name, InspectorValue::create(value));
 }
 
 inline void InspectorObjectBase::setInteger(const String& name, int value)
 {
-    setValue(name, InspectorBasicValue::create(value));
+    setValue(name, InspectorValue::create(value));
 }
 
 inline void InspectorObjectBase::setDouble(const String& name, double value)
 {
-    setValue(name, InspectorBasicValue::create(value));
+    setValue(name, InspectorValue::create(value));
 }
 
 inline void InspectorObjectBase::setString(const String& name, const String& value)
 {
-    setValue(name, InspectorString::create(value));
+    setValue(name, InspectorValue::create(value));
 }
 
 inline void InspectorObjectBase::setValue(const String& name, RefPtr<InspectorValue>&& value)
 {
     ASSERT(value);
-    if (m_data.set(name, WTFMove(value)).isNewEntry)
+    if (m_map.set(name, WTFMove(value)).isNewEntry)
         m_order.append(name);
 }
 
 inline void InspectorObjectBase::setObject(const String& name, RefPtr<InspectorObjectBase>&& value)
 {
     ASSERT(value);
-    if (m_data.set(name, WTFMove(value)).isNewEntry)
+    if (m_map.set(name, WTFMove(value)).isNewEntry)
         m_order.append(name);
 }
 
 inline void InspectorObjectBase::setArray(const String& name, RefPtr<InspectorArrayBase>&& value)
 {
     ASSERT(value);
-    if (m_data.set(name, WTFMove(value)).isNewEntry)
+    if (m_map.set(name, WTFMove(value)).isNewEntry)
         m_order.append(name);
 }
 
 inline void InspectorArrayBase::pushBoolean(bool value)
 {
-    m_data.append(InspectorBasicValue::create(value));
+    m_map.append(InspectorValue::create(value));
 }
 
 inline void InspectorArrayBase::pushInteger(int value)
 {
-    m_data.append(InspectorBasicValue::create(value));
+    m_map.append(InspectorValue::create(value));
 }
 
 inline void InspectorArrayBase::pushDouble(double value)
 {
-    m_data.append(InspectorBasicValue::create(value));
+    m_map.append(InspectorValue::create(value));
 }
 
 inline void InspectorArrayBase::pushString(const String& value)
 {
-    m_data.append(InspectorString::create(value));
+    m_map.append(InspectorValue::create(value));
 }
 
 inline void InspectorArrayBase::pushValue(RefPtr<InspectorValue>&& value)
 {
     ASSERT(value);
-    m_data.append(WTFMove(value));
+    m_map.append(WTFMove(value));
 }
 
 inline void InspectorArrayBase::pushObject(RefPtr<InspectorObjectBase>&& value)
 {
     ASSERT(value);
-    m_data.append(WTFMove(value));
+    m_map.append(WTFMove(value));
 }
 
 inline void InspectorArrayBase::pushArray(RefPtr<InspectorArrayBase>&& value)
 {
     ASSERT(value);
-    m_data.append(WTFMove(value));
+    m_map.append(WTFMove(value));
 }
 
 } // namespace Inspector

Modified: trunk/Source/_javascript_Core/replay/EncodedValue.cpp (199319 => 199320)


--- trunk/Source/_javascript_Core/replay/EncodedValue.cpp	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/_javascript_Core/replay/EncodedValue.cpp	2016-04-11 23:22:16 UTC (rev 199320)
@@ -67,37 +67,37 @@
 
 template<> EncodedValue ScalarEncodingTraits<bool>::encodeValue(const bool& value)
 {
-    return EncodedValue(InspectorBasicValue::create(value));
+    return EncodedValue(InspectorValue::create(value));
 }
 
 template<> EncodedValue ScalarEncodingTraits<double>::encodeValue(const double& value)
 {
-    return EncodedValue(InspectorBasicValue::create(value));
+    return EncodedValue(InspectorValue::create(value));
 }
 
 template<> EncodedValue ScalarEncodingTraits<float>::encodeValue(const float& value)
 {
-    return EncodedValue(InspectorBasicValue::create((double)value));
+    return EncodedValue(InspectorValue::create((double)value));
 }
 
 template<> EncodedValue ScalarEncodingTraits<int32_t>::encodeValue(const int32_t& value)
 {
-    return EncodedValue(InspectorBasicValue::create((double)value));
+    return EncodedValue(InspectorValue::create((double)value));
 }
 
 template<> EncodedValue ScalarEncodingTraits<int64_t>::encodeValue(const int64_t& value)
 {
-    return EncodedValue(InspectorBasicValue::create((double)value));
+    return EncodedValue(InspectorValue::create((double)value));
 }
 
 template<> EncodedValue ScalarEncodingTraits<uint32_t>::encodeValue(const uint32_t& value)
 {
-    return EncodedValue(InspectorBasicValue::create((double)value));
+    return EncodedValue(InspectorValue::create((double)value));
 }
 
 template<> EncodedValue ScalarEncodingTraits<uint64_t>::encodeValue(const uint64_t& value)
 {
-    return EncodedValue(InspectorBasicValue::create((double)value));
+    return EncodedValue(InspectorValue::create((double)value));
 }
 
 template<> bool EncodedValue::convertTo<bool>()

Modified: trunk/Source/_javascript_Core/replay/EncodedValue.h (199319 => 199320)


--- trunk/Source/_javascript_Core/replay/EncodedValue.h	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/_javascript_Core/replay/EncodedValue.h	2016-04-11 23:22:16 UTC (rev 199320)
@@ -59,12 +59,12 @@
 
     static EncodedValue createString(const String& value)
     {
-        return EncodedValue(Inspector::InspectorString::create(value));
+        return EncodedValue(Inspector::InspectorValue::create(value));
     }
 
     static EncodedValue createString(const char* value)
     {
-        return EncodedValue(Inspector::InspectorString::create(value));
+        return EncodedValue(Inspector::InspectorValue::create(value));
     }
 
     template<typename T>

Modified: trunk/Source/WebCore/ChangeLog (199319 => 199320)


--- trunk/Source/WebCore/ChangeLog	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/WebCore/ChangeLog	2016-04-11 23:22:16 UTC (rev 199320)
@@ -1,3 +1,13 @@
+2016-04-11  Brian Burg  <[email protected]>
+
+        Web Inspector: get rid of InspectorBasicValue and InspectorString subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=156407
+        <rdar://problem/25627659>
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/InspectorDatabaseAgent.cpp: Don't use deleted subclasses.
+
 2016-04-11  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r198909.

Modified: trunk/Source/WebCore/inspector/InspectorDatabaseAgent.cpp (199319 => 199320)


--- trunk/Source/WebCore/inspector/InspectorDatabaseAgent.cpp	2016-04-11 23:16:31 UTC (rev 199319)
+++ trunk/Source/WebCore/inspector/InspectorDatabaseAgent.cpp	2016-04-11 23:22:16 UTC (rev 199320)
@@ -87,8 +87,8 @@
         for (auto& value : rowList->values()) {
             RefPtr<InspectorValue> inspectorValue;
             switch (value.type()) {
-            case SQLValue::StringValue: inspectorValue = InspectorString::create(value.string()); break;
-            case SQLValue::NumberValue: inspectorValue = InspectorBasicValue::create(value.number()); break;
+            case SQLValue::StringValue: inspectorValue = InspectorValue::create(value.string()); break;
+            case SQLValue::NumberValue: inspectorValue = InspectorValue::create(value.number()); break;
             case SQLValue::NullValue: inspectorValue = InspectorValue::null(); break;
             }
             
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to