Changeset 199320 in webkit


Ignore:
Timestamp:
Apr 11, 2016 4:22:16 PM (8 years ago)
Author:
BJ Burg
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/JavaScriptCore:

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.
Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r199303 r199320  
     12016-04-11  Brian Burg  <bburg@apple.com>
     2
     3        Web Inspector: get rid of InspectorBasicValue and InspectorString subclasses
     4        https://bugs.webkit.org/show_bug.cgi?id=156407
     5        <rdar://problem/25627659>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        There's no point having these subclasses as they don't save any space.
     10        Add a StringImpl to the union and merge some implementations of writeJSON.
     11
     12        Rename m_data to m_map and explicitly name the union as InspectorValue::m_value.
     13        If the value is a string and the string is not empty or null (i.e., it has a
     14        StringImpl), then we need to ref() and deref() the string as the InspectorValue
     15        is created or destroyed.
     16
     17        Move uses of the subclass to InspectorValue and delete redundant methods.
     18        Now, most InspectorValue methods are non-virtual so they can be templated.
     19
     20        * bindings/ScriptValue.cpp:
     21        (Deprecated::jsToInspectorValue):
     22        * inspector/InjectedScriptBase.cpp:
     23        (Inspector::InjectedScriptBase::makeCall):
     24        Don't used deleted subclasses.
     25
     26        * inspector/InspectorValues.cpp:
     27        (Inspector::InspectorValue::null):
     28        (Inspector::InspectorValue::create):
     29        (Inspector::InspectorValue::asValue):
     30        (Inspector::InspectorValue::asBoolean):
     31        (Inspector::InspectorValue::asDouble):
     32        (Inspector::InspectorValue::asInteger):
     33        (Inspector::InspectorValue::asString):
     34        These only need one implementation now.
     35
     36        (Inspector::InspectorValue::writeJSON):
     37        Still a virtual method since Object and Array need their members.
     38
     39        (Inspector::InspectorObjectBase::InspectorObjectBase):
     40        (Inspector::InspectorBasicValue::asBoolean): Deleted.
     41        (Inspector::InspectorBasicValue::asDouble): Deleted.
     42        (Inspector::InspectorBasicValue::asInteger): Deleted.
     43        (Inspector::InspectorBasicValue::writeJSON): Deleted.
     44        (Inspector::InspectorString::asString): Deleted.
     45        (Inspector::InspectorString::writeJSON): Deleted.
     46        (Inspector::InspectorString::create): Deleted.
     47        (Inspector::InspectorBasicValue::create): Deleted.
     48
     49        * inspector/InspectorValues.h:
     50        (Inspector::InspectorObjectBase::find):
     51        (Inspector::InspectorObjectBase::setBoolean):
     52        (Inspector::InspectorObjectBase::setInteger):
     53        (Inspector::InspectorObjectBase::setDouble):
     54        (Inspector::InspectorObjectBase::setString):
     55        (Inspector::InspectorObjectBase::setValue):
     56        (Inspector::InspectorObjectBase::setObject):
     57        (Inspector::InspectorObjectBase::setArray):
     58        (Inspector::InspectorArrayBase::pushBoolean):
     59        (Inspector::InspectorArrayBase::pushInteger):
     60        (Inspector::InspectorArrayBase::pushDouble):
     61        (Inspector::InspectorArrayBase::pushString):
     62        (Inspector::InspectorArrayBase::pushValue):
     63        (Inspector::InspectorArrayBase::pushObject):
     64        (Inspector::InspectorArrayBase::pushArray):
     65        Use new factory methods.
     66
     67        * replay/EncodedValue.cpp:
     68        (JSC::ScalarEncodingTraits<bool>::encodeValue):
     69        (JSC::ScalarEncodingTraits<double>::encodeValue):
     70        (JSC::ScalarEncodingTraits<float>::encodeValue):
     71        (JSC::ScalarEncodingTraits<int32_t>::encodeValue):
     72        (JSC::ScalarEncodingTraits<int64_t>::encodeValue):
     73        (JSC::ScalarEncodingTraits<uint32_t>::encodeValue):
     74        (JSC::ScalarEncodingTraits<uint64_t>::encodeValue):
     75        * replay/EncodedValue.h:
     76        Use new factory methods.
     77
    1782016-04-11  Filip Pizlo  <fpizlo@apple.com>
    279
  • trunk/Source/JavaScriptCore/bindings/ScriptValue.cpp

    r199276 r199320  
    113113        return InspectorValue::null();
    114114    if (value.isBoolean())
    115         return InspectorBasicValue::create(value.asBoolean());
     115        return InspectorValue::create(value.asBoolean());
    116116    if (value.isNumber() && value.isDouble())
    117         return InspectorBasicValue::create(value.asNumber());
     117        return InspectorValue::create(value.asNumber());
    118118    if (value.isNumber() && value.isMachineInt())
    119         return InspectorBasicValue::create(static_cast<int>(value.asMachineInt()));
     119        return InspectorValue::create(static_cast<int>(value.asMachineInt()));
    120120    if (value.isString())
    121         return InspectorString::create(value.getString(scriptState));
     121        return InspectorValue::create(value.getString(scriptState));
    122122
    123123    if (value.isObject()) {
  • trunk/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp

    r199276 r199320  
    100100        *result = resultValue.toInspectorValue(m_injectedScriptObject.scriptState());
    101101        if (!*result)
    102             *result = InspectorString::create(String::format("Object has too long reference chain (must not be longer than %d)", InspectorValue::maxDepth));
     102            *result = InspectorValue::create(String::format("Object has too long reference chain (must not be longer than %d)", InspectorValue::maxDepth));
    103103    } else
    104         *result = InspectorString::create("Exception while making a call.");
     104        *result = InspectorValue::create("Exception while making a call.");
    105105}
    106106
  • trunk/Source/JavaScriptCore/inspector/InspectorValues.cpp

    r199276 r199320  
    364364        break;
    365365    case BOOL_TRUE:
    366         result = InspectorBasicValue::create(true);
     366        result = InspectorValue::create(true);
    367367        break;
    368368    case BOOL_FALSE:
    369         result = InspectorBasicValue::create(false);
     369        result = InspectorValue::create(false);
    370370        break;
    371371    case NUMBER: {
     
    374374        if (!ok)
    375375            return nullptr;
    376         result = InspectorBasicValue::create(value);
     376        result = InspectorValue::create(value);
    377377        break;
    378378    }
     
    382382        if (!ok)
    383383            return nullptr;
    384         result = InspectorString::create(value);
     384        result = InspectorValue::create(value);
    385385        break;
    386386    }
     
    499499} // anonymous namespace
    500500
    501 bool InspectorValue::asBoolean(bool&) const
    502 {
    503     return false;
    504 }
    505 
    506 bool InspectorValue::asDouble(double&) const
    507 {
    508     return false;
    509 }
    510 
    511 bool InspectorValue::asDouble(float&) const
    512 {
    513     return false;
    514 }
    515 
    516 bool InspectorValue::asInteger(int&) const
    517 {
    518     return false;
    519 }
    520 
    521 bool InspectorValue::asInteger(unsigned&) const
    522 {
    523     return false;
    524 }
    525 
    526 bool InspectorValue::asInteger(long&) const
    527 {
    528     return false;
    529 }
    530 
    531 bool InspectorValue::asInteger(long long&) const
    532 {
    533     return false;
    534 }
    535 
    536 bool InspectorValue::asInteger(unsigned long&) const
    537 {
    538     return false;
    539 }
    540 
    541 bool InspectorValue::asInteger(unsigned long long&) const
    542 {
    543     return false;
    544 }
    545 
    546 bool InspectorValue::asString(String&) const
    547 {
    548     return false;
    549 }
    550 
    551 bool InspectorValue::asValue(RefPtr<InspectorValue>& output)
    552 {
    553     output = this;
     501Ref<InspectorValue> InspectorValue::null()
     502{
     503    return adoptRef(*new InspectorValue);
     504}
     505
     506Ref<InspectorValue> InspectorValue::create(bool value)
     507{
     508    return adoptRef(*new InspectorValue(value));
     509}
     510
     511Ref<InspectorValue> InspectorValue::create(int value)
     512{
     513    return adoptRef(*new InspectorValue(value));
     514}
     515
     516Ref<InspectorValue> InspectorValue::create(double value)
     517{
     518    return adoptRef(*new InspectorValue(value));
     519}
     520
     521Ref<InspectorValue> InspectorValue::create(const String& value)
     522{
     523    return adoptRef(*new InspectorValue(value));
     524}
     525
     526Ref<InspectorValue> InspectorValue::create(const char* value)
     527{
     528    return adoptRef(*new InspectorValue(value));
     529}
     530
     531bool InspectorValue::asValue(RefPtr<Inspector::InspectorValue> & value)
     532{
     533    value = this;
    554534    return true;
    555535}
     
    588568}
    589569
     570bool InspectorValue::asBoolean(bool& output) const
     571{
     572    if (type() != Type::Boolean)
     573        return false;
     574
     575    output = m_value.boolean;
     576    return true;
     577}
     578
     579bool InspectorValue::asDouble(double& output) const
     580{
     581    if (type() != Type::Double)
     582        return false;
     583
     584    output = m_value.number;
     585    return true;
     586}
     587
     588bool InspectorValue::asDouble(float& output) const
     589{
     590    if (type() != Type::Double)
     591        return false;
     592
     593    output = static_cast<float>(m_value.number);
     594    return true;
     595}
     596
     597bool InspectorValue::asInteger(int& output) const
     598{
     599    if (type() != Type::Integer && type() != Type::Double)
     600        return false;
     601
     602    output = static_cast<int>(m_value.number);
     603    return true;
     604}
     605
     606bool InspectorValue::asInteger(unsigned& output) const
     607{
     608    if (type() != Type::Integer && type() != Type::Double)
     609        return false;
     610
     611    output = static_cast<unsigned>(m_value.number);
     612    return true;
     613}
     614
     615bool InspectorValue::asInteger(long& output) const
     616{
     617    if (type() != Type::Integer && type() != Type::Double)
     618        return false;
     619
     620    output = static_cast<long>(m_value.number);
     621    return true;
     622}
     623
     624bool InspectorValue::asInteger(long long& output) const
     625{
     626    if (type() != Type::Integer && type() != Type::Double)
     627        return false;
     628
     629    output = static_cast<long long>(m_value.number);
     630    return true;
     631}
     632
     633bool InspectorValue::asInteger(unsigned long& output) const
     634{
     635    if (type() != Type::Integer && type() != Type::Double)
     636        return false;
     637
     638    output = static_cast<unsigned long>(m_value.number);
     639    return true;
     640}
     641
     642bool InspectorValue::asInteger(unsigned long long& output) const
     643{
     644    if (type() != Type::Integer && type() != Type::Double)
     645        return false;
     646
     647    output = static_cast<unsigned long long>(m_value.number);
     648    return true;
     649}
     650
     651bool InspectorValue::asString(String& output) const
     652{
     653    if (type() != Type::String)
     654        return false;
     655
     656    output = m_value.string;
     657    return true;
     658}
     659
    590660void InspectorValue::writeJSON(StringBuilder& output) const
    591661{
    592     ASSERT(m_type == Type::Null);
    593 
    594     output.appendLiteral("null");
    595 }
    596 
    597 bool InspectorBasicValue::asBoolean(bool& output) const
    598 {
    599     if (type() != Type::Boolean)
    600         return false;
    601 
    602     output = m_booleanValue;
    603     return true;
    604 }
    605 
    606 bool InspectorBasicValue::asDouble(double& output) const
    607 {
    608     if (type() != Type::Double)
    609         return false;
    610 
    611     output = m_doubleValue;
    612     return true;
    613 }
    614 
    615 bool InspectorBasicValue::asDouble(float& output) const
    616 {
    617     if (type() != Type::Double)
    618         return false;
    619 
    620     output = static_cast<float>(m_doubleValue);
    621     return true;
    622 }
    623 
    624 bool InspectorBasicValue::asInteger(int& output) const
    625 {
    626     if (type() != Type::Integer && type() != Type::Double)
    627         return false;
    628 
    629     output = static_cast<int>(m_doubleValue);
    630     return true;
    631 }
    632 
    633 bool InspectorBasicValue::asInteger(unsigned& output) const
    634 {
    635     if (type() != Type::Integer && type() != Type::Double)
    636         return false;
    637 
    638     output = static_cast<unsigned>(m_doubleValue);
    639     return true;
    640 }
    641 
    642 bool InspectorBasicValue::asInteger(long& output) const
    643 {
    644     if (type() != Type::Integer && type() != Type::Double)
    645         return false;
    646 
    647     output = static_cast<long>(m_doubleValue);
    648     return true;
    649 }
    650 
    651 bool InspectorBasicValue::asInteger(long long& output) const
    652 {
    653     if (type() != Type::Integer && type() != Type::Double)
    654         return false;
    655 
    656     output = static_cast<long long>(m_doubleValue);
    657     return true;
    658 }
    659 
    660 bool InspectorBasicValue::asInteger(unsigned long& output) const
    661 {
    662     if (type() != Type::Integer && type() != Type::Double)
    663         return false;
    664 
    665     output = static_cast<unsigned long>(m_doubleValue);
    666     return true;
    667 }
    668 
    669 bool InspectorBasicValue::asInteger(unsigned long long& output) const
    670 {
    671     if (type() != Type::Integer && type() != Type::Double)
    672         return false;
    673 
    674     output = static_cast<unsigned long long>(m_doubleValue);
    675     return true;
    676 }
    677 
    678 void InspectorBasicValue::writeJSON(StringBuilder& output) const
    679 {
    680     ASSERT(type() == Type::Boolean || type() == Type::Double || type() == Type::Integer);
    681 
    682     if (type() == Type::Boolean) {
    683         if (m_booleanValue)
     662    switch (m_type) {
     663    case Type::Null:
     664        output.appendLiteral("null");
     665        break;
     666    case Type::Boolean:
     667        if (m_value.boolean)
    684668            output.appendLiteral("true");
    685669        else
    686670            output.appendLiteral("false");
    687     } else if (type() == Type::Double || type() == Type::Integer) {
     671        break;
     672    case Type::String:
     673        doubleQuoteString(m_value.string, output);
     674        break;
     675    case Type::Double:
     676    case Type::Integer: {
    688677        NumberToLStringBuffer buffer;
    689         if (!std::isfinite(m_doubleValue)) {
     678        if (!std::isfinite(m_value.number)) {
    690679            output.appendLiteral("null");
    691680            return;
    692681        }
    693         DecimalNumber decimal = m_doubleValue;
     682        DecimalNumber decimal = m_value.number;
    694683        unsigned length = 0;
    695684        if (decimal.bufferLengthForStringDecimal() > WTF::NumberToStringBufferLength) {
     
    704693            length = decimal.toStringDecimal(buffer, WTF::NumberToStringBufferLength);
    705694        output.append(buffer, length);
    706     }
    707 }
    708 
    709 bool InspectorString::asString(String& output) const
    710 {
    711     output = m_stringValue;
    712     return true;
    713 }
    714 
    715 void InspectorString::writeJSON(StringBuilder& output) const
    716 {
    717     ASSERT(type() == Type::String);
    718     doubleQuoteString(m_stringValue, output);
     695        break;
     696    }
     697    default:
     698        ASSERT_NOT_REACHED();
     699    }
    719700}
    720701
     
    776757bool InspectorObjectBase::getValue(const String& name, RefPtr<InspectorValue>& output) const
    777758{
    778     Dictionary::const_iterator findResult = m_data.find(name);
    779     if (findResult == m_data.end())
     759    Dictionary::const_iterator findResult = m_map.find(name);
     760    if (findResult == m_map.end())
    780761        return false;
    781762
     
    786767void InspectorObjectBase::remove(const String& name)
    787768{
    788     m_data.remove(name);
     769    m_map.remove(name);
    789770    m_order.removeFirst(name);
    790771}
     
    794775    output.append('{');
    795776    for (size_t i = 0; i < m_order.size(); ++i) {
    796         auto findResult = m_data.find(m_order[i]);
    797         ASSERT(findResult != m_data.end());
     777        auto findResult = m_map.find(m_order[i]);
     778        ASSERT(findResult != m_map.end());
    798779        if (i)
    799780            output.append(',');
     
    806787
    807788InspectorObjectBase::InspectorObjectBase()
    808     : InspectorValue(Type::Object)
    809     , m_data()
     789    : Inspector::InspectorValue(Type::Object)
     790    , m_map()
    810791    , m_order()
    811792{
     
    826807{
    827808    output.append('[');
    828     for (Vector<RefPtr<InspectorValue>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {
    829         if (it != m_data.begin())
     809    for (Vector<RefPtr<InspectorValue>>::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
     810        if (it != m_map.begin())
    830811            output.append(',');
    831812        (*it)->writeJSON(output);
     
    836817InspectorArrayBase::InspectorArrayBase()
    837818    : InspectorValue(Type::Array)
    838     , m_data()
     819    , m_map()
    839820{
    840821}
     
    842823RefPtr<InspectorValue> InspectorArrayBase::get(size_t index) const
    843824{
    844     ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size());
    845     return m_data[index];
     825    ASSERT_WITH_SECURITY_IMPLICATION(index < m_map.size());
     826    return m_map[index];
    846827}
    847828
     
    856837}
    857838
    858 Ref<InspectorValue> InspectorValue::null()
    859 {
    860     return adoptRef(*new InspectorValue);
    861 }
    862 
    863 Ref<InspectorString> InspectorString::create(const String& value)
    864 {
    865     return adoptRef(*new InspectorString(value));
    866 }
    867 
    868 Ref<InspectorString> InspectorString::create(const char* value)
    869 {
    870     return adoptRef(*new InspectorString(value));
    871 }
    872 
    873 Ref<InspectorBasicValue> InspectorBasicValue::create(bool value)
    874 {
    875     return adoptRef(*new InspectorBasicValue(value));
    876 }
    877 
    878 Ref<InspectorBasicValue> InspectorBasicValue::create(int value)
    879 {
    880     return adoptRef(*new InspectorBasicValue(value));
    881 }
    882 
    883 Ref<InspectorBasicValue> InspectorBasicValue::create(double value)
    884 {
    885     return adoptRef(*new InspectorBasicValue(value));
    886 }
    887 
    888839} // namespace Inspector
  • trunk/Source/JavaScriptCore/inspector/InspectorValues.h

    r199276 r199320  
    5252    static const int maxDepth = 1000;
    5353
    54     InspectorValue()
    55         : m_type(Type::Null) { }
    56     virtual ~InspectorValue() { }
     54    virtual ~InspectorValue()
     55    {
     56        switch (m_type) {
     57        case Type::Null:
     58        case Type::Boolean:
     59        case Type::Double:
     60        case Type::Integer:
     61            break;
     62        case Type::String:
     63            if (m_value.string)
     64                m_value.string->deref();
     65            break;
     66        case Type::Object:
     67        case Type::Array:
     68            break;
     69        }
     70    }
    5771
    5872    static Ref<InspectorValue> null();
     73    static Ref<InspectorValue> create(bool);
     74    static Ref<InspectorValue> create(int);
     75    static Ref<InspectorValue> create(double);
     76    static Ref<InspectorValue> create(const String&);
     77    static Ref<InspectorValue> create(const char*);
    5978
    6079    enum class Type {
     
    6584        String,
    6685        Object,
    67         Array
     86        Array,
    6887    };
    6988
    7089    Type type() const { return m_type; }
    71 
    7290    bool isNull() const { return m_type == Type::Null; }
    7391
    74     virtual bool asBoolean(bool&) const;
    75     virtual bool asInteger(int&) const;
    76     virtual bool asInteger(unsigned&) const;
    77     virtual bool asInteger(long&) const;
    78     virtual bool asInteger(long long&) const;
    79     virtual bool asInteger(unsigned long&) const;
    80     virtual bool asInteger(unsigned long long&) const;
    81     virtual bool asDouble(double&) const;
    82     virtual bool asDouble(float&) const;
    83     virtual bool asString(String&) const;
    84     virtual bool asValue(RefPtr<InspectorValue>&);
     92    bool asBoolean(bool&) const;
     93    bool asInteger(int&) const;
     94    bool asInteger(unsigned&) const;
     95    bool asInteger(long&) const;
     96    bool asInteger(long long&) const;
     97    bool asInteger(unsigned long&) const;
     98    bool asInteger(unsigned long long&) const;
     99    bool asDouble(double&) const;
     100    bool asDouble(float&) const;
     101    bool asString(String&) const;
     102    bool asValue(RefPtr<InspectorValue>&);
     103
    85104    virtual bool asObject(RefPtr<InspectorObject>&);
    86105    virtual bool asArray(RefPtr<InspectorArray>&);
     
    92111
    93112protected:
    94     explicit InspectorValue(Type type) : m_type(type) { }
     113    InspectorValue()
     114        : m_type(Type::Null) { }
     115
     116    explicit InspectorValue(Type type)
     117        : m_type(type) { }
     118
     119    explicit InspectorValue(bool value)
     120        : m_type(Type::Boolean)
     121    {
     122        m_value.boolean = value;
     123    }
     124
     125    explicit InspectorValue(int value)
     126        : m_type(Type::Integer)
     127    {
     128        m_value.number = static_cast<double>(value);
     129    }
     130
     131    explicit InspectorValue(double value)
     132        : m_type(Type::Double)
     133    {
     134        m_value.number = value;
     135    }
     136
     137    explicit InspectorValue(const String& value)
     138        : m_type(Type::String)
     139    {
     140        m_value.string = value.impl();
     141        if (m_value.string)
     142            m_value.string->ref();
     143    }
     144
     145    explicit InspectorValue(const char* value)
     146        : m_type(Type::String)
     147    {
     148        String wrapper(value);
     149        m_value.string = wrapper.impl();
     150        if (m_value.string)
     151            m_value.string->ref();
     152    }
    95153
    96154private:
    97     Type m_type;
    98 };
    99 
    100 class JS_EXPORT_PRIVATE InspectorBasicValue : public InspectorValue {
    101 public:
    102 
    103     static Ref<InspectorBasicValue> create(bool);
    104     static Ref<InspectorBasicValue> create(int);
    105     static Ref<InspectorBasicValue> create(double);
    106 
    107     bool asBoolean(bool&) const override;
    108     // Numbers from the frontend are always parsed as doubles, so we allow
    109     // clients to convert to integral values with this function.
    110     bool asInteger(int&) const override;
    111     bool asInteger(unsigned&) const override;
    112     bool asInteger(long&) const override;
    113     bool asInteger(long long&) const override;
    114     bool asInteger(unsigned long&) const override;
    115     bool asInteger(unsigned long long&) const override;
    116     bool asDouble(double&) const override;
    117     bool asDouble(float&) const override;
    118 
    119     void writeJSON(StringBuilder& output) const override;
    120 
    121 private:
    122     explicit InspectorBasicValue(bool value)
    123         : InspectorValue(Type::Boolean)
    124         , m_booleanValue(value) { }
    125 
    126     explicit InspectorBasicValue(int value)
    127         : InspectorValue(Type::Integer)
    128         , m_doubleValue(static_cast<double>(value)) { }
    129 
    130     explicit InspectorBasicValue(double value)
    131         : InspectorValue(Type::Double)
    132         , m_doubleValue(value) { }
    133 
     155    Type m_type { Type::Null };
    134156    union {
    135         bool m_booleanValue;
    136         double m_doubleValue;
    137     };
    138 };
    139 
    140 class JS_EXPORT_PRIVATE InspectorString : public InspectorValue {
    141 public:
    142     static Ref<InspectorString> create(const String&);
    143     static Ref<InspectorString> create(const char*);
    144 
    145     bool asString(String& output) const override;
    146 
    147     void writeJSON(StringBuilder& output) const override;
    148 
    149 private:
    150     explicit InspectorString(const String& value)
    151         : InspectorValue(Type::String)
    152         , m_stringValue(value) { }
    153 
    154     explicit InspectorString(const char* value)
    155         : InspectorValue(Type::String)
    156         , m_stringValue(value) { }
    157 
    158     String m_stringValue;
     157        bool boolean;
     158        double number;
     159        StringImpl* string;
     160    } m_value;
    159161};
    160162
     
    214216    void writeJSON(StringBuilder& output) const override;
    215217
    216     iterator begin() { return m_data.begin(); }
    217     iterator end() { return m_data.end(); }
    218     const_iterator begin() const { return m_data.begin(); }
    219     const_iterator end() const { return m_data.end(); }
    220 
    221     int size() const { return m_data.size(); }
     218    iterator begin() { return m_map.begin(); }
     219    iterator end() { return m_map.end(); }
     220    const_iterator begin() const { return m_map.begin(); }
     221    const_iterator end() const { return m_map.end(); }
     222
     223    int size() const { return m_map.size(); }
    222224
    223225protected:
     
    225227
    226228private:
    227     Dictionary m_data;
     229    Dictionary m_map;
    228230    Vector<String> m_order;
    229231};
     
    266268    typedef Vector<RefPtr<InspectorValue>>::const_iterator const_iterator;
    267269
    268     unsigned length() const { return static_cast<unsigned>(m_data.size()); }
     270    unsigned length() const { return static_cast<unsigned>(m_map.size()); }
    269271
    270272protected:
     
    285287    void writeJSON(StringBuilder& output) const override;
    286288
    287     iterator begin() { return m_data.begin(); }
    288     iterator end() { return m_data.end(); }
    289     const_iterator begin() const { return m_data.begin(); }
    290     const_iterator end() const { return m_data.end(); }
     289    iterator begin() { return m_map.begin(); }
     290    iterator end() { return m_map.end(); }
     291    const_iterator begin() const { return m_map.begin(); }
     292    const_iterator end() const { return m_map.end(); }
    291293
    292294protected:
     
    294296
    295297private:
    296     Vector<RefPtr<InspectorValue>> m_data;
     298    Vector<RefPtr<InspectorValue>> m_map;
    297299};
    298300
     
    320322inline InspectorObjectBase::iterator InspectorObjectBase::find(const String& name)
    321323{
    322     return m_data.find(name);
     324    return m_map.find(name);
    323325}
    324326
    325327inline InspectorObjectBase::const_iterator InspectorObjectBase::find(const String& name) const
    326328{
    327     return m_data.find(name);
     329    return m_map.find(name);
    328330}
    329331
    330332inline void InspectorObjectBase::setBoolean(const String& name, bool value)
    331333{
    332     setValue(name, InspectorBasicValue::create(value));
     334    setValue(name, InspectorValue::create(value));
    333335}
    334336
    335337inline void InspectorObjectBase::setInteger(const String& name, int value)
    336338{
    337     setValue(name, InspectorBasicValue::create(value));
     339    setValue(name, InspectorValue::create(value));
    338340}
    339341
    340342inline void InspectorObjectBase::setDouble(const String& name, double value)
    341343{
    342     setValue(name, InspectorBasicValue::create(value));
     344    setValue(name, InspectorValue::create(value));
    343345}
    344346
    345347inline void InspectorObjectBase::setString(const String& name, const String& value)
    346348{
    347     setValue(name, InspectorString::create(value));
     349    setValue(name, InspectorValue::create(value));
    348350}
    349351
     
    351353{
    352354    ASSERT(value);
    353     if (m_data.set(name, WTFMove(value)).isNewEntry)
     355    if (m_map.set(name, WTFMove(value)).isNewEntry)
    354356        m_order.append(name);
    355357}
     
    358360{
    359361    ASSERT(value);
    360     if (m_data.set(name, WTFMove(value)).isNewEntry)
     362    if (m_map.set(name, WTFMove(value)).isNewEntry)
    361363        m_order.append(name);
    362364}
     
    365367{
    366368    ASSERT(value);
    367     if (m_data.set(name, WTFMove(value)).isNewEntry)
     369    if (m_map.set(name, WTFMove(value)).isNewEntry)
    368370        m_order.append(name);
    369371}
     
    371373inline void InspectorArrayBase::pushBoolean(bool value)
    372374{
    373     m_data.append(InspectorBasicValue::create(value));
     375    m_map.append(InspectorValue::create(value));
    374376}
    375377
    376378inline void InspectorArrayBase::pushInteger(int value)
    377379{
    378     m_data.append(InspectorBasicValue::create(value));
     380    m_map.append(InspectorValue::create(value));
    379381}
    380382
    381383inline void InspectorArrayBase::pushDouble(double value)
    382384{
    383     m_data.append(InspectorBasicValue::create(value));
     385    m_map.append(InspectorValue::create(value));
    384386}
    385387
    386388inline void InspectorArrayBase::pushString(const String& value)
    387389{
    388     m_data.append(InspectorString::create(value));
     390    m_map.append(InspectorValue::create(value));
    389391}
    390392
     
    392394{
    393395    ASSERT(value);
    394     m_data.append(WTFMove(value));
     396    m_map.append(WTFMove(value));
    395397}
    396398
     
    398400{
    399401    ASSERT(value);
    400     m_data.append(WTFMove(value));
     402    m_map.append(WTFMove(value));
    401403}
    402404
     
    404406{
    405407    ASSERT(value);
    406     m_data.append(WTFMove(value));
     408    m_map.append(WTFMove(value));
    407409}
    408410
  • trunk/Source/JavaScriptCore/replay/EncodedValue.cpp

    r199276 r199320  
    6868template<> EncodedValue ScalarEncodingTraits<bool>::encodeValue(const bool& value)
    6969{
    70     return EncodedValue(InspectorBasicValue::create(value));
     70    return EncodedValue(InspectorValue::create(value));
    7171}
    7272
    7373template<> EncodedValue ScalarEncodingTraits<double>::encodeValue(const double& value)
    7474{
    75     return EncodedValue(InspectorBasicValue::create(value));
     75    return EncodedValue(InspectorValue::create(value));
    7676}
    7777
    7878template<> EncodedValue ScalarEncodingTraits<float>::encodeValue(const float& value)
    7979{
    80     return EncodedValue(InspectorBasicValue::create((double)value));
     80    return EncodedValue(InspectorValue::create((double)value));
    8181}
    8282
    8383template<> EncodedValue ScalarEncodingTraits<int32_t>::encodeValue(const int32_t& value)
    8484{
    85     return EncodedValue(InspectorBasicValue::create((double)value));
     85    return EncodedValue(InspectorValue::create((double)value));
    8686}
    8787
    8888template<> EncodedValue ScalarEncodingTraits<int64_t>::encodeValue(const int64_t& value)
    8989{
    90     return EncodedValue(InspectorBasicValue::create((double)value));
     90    return EncodedValue(InspectorValue::create((double)value));
    9191}
    9292
    9393template<> EncodedValue ScalarEncodingTraits<uint32_t>::encodeValue(const uint32_t& value)
    9494{
    95     return EncodedValue(InspectorBasicValue::create((double)value));
     95    return EncodedValue(InspectorValue::create((double)value));
    9696}
    9797
    9898template<> EncodedValue ScalarEncodingTraits<uint64_t>::encodeValue(const uint64_t& value)
    9999{
    100     return EncodedValue(InspectorBasicValue::create((double)value));
     100    return EncodedValue(InspectorValue::create((double)value));
    101101}
    102102
  • trunk/Source/JavaScriptCore/replay/EncodedValue.h

    r199276 r199320  
    6060    static EncodedValue createString(const String& value)
    6161    {
    62         return EncodedValue(Inspector::InspectorString::create(value));
     62        return EncodedValue(Inspector::InspectorValue::create(value));
    6363    }
    6464
    6565    static EncodedValue createString(const char* value)
    6666    {
    67         return EncodedValue(Inspector::InspectorString::create(value));
     67        return EncodedValue(Inspector::InspectorValue::create(value));
    6868    }
    6969
  • trunk/Source/WebCore/ChangeLog

    r199317 r199320  
     12016-04-11  Brian Burg  <bburg@apple.com>
     2
     3        Web Inspector: get rid of InspectorBasicValue and InspectorString subclasses
     4        https://bugs.webkit.org/show_bug.cgi?id=156407
     5        <rdar://problem/25627659>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * inspector/InspectorDatabaseAgent.cpp: Don't use deleted subclasses.
     10
    1112016-04-11  Commit Queue  <commit-queue@webkit.org>
    212
  • trunk/Source/WebCore/inspector/InspectorDatabaseAgent.cpp

    r199276 r199320  
    8888            RefPtr<InspectorValue> inspectorValue;
    8989            switch (value.type()) {
    90             case SQLValue::StringValue: inspectorValue = InspectorString::create(value.string()); break;
    91             case SQLValue::NumberValue: inspectorValue = InspectorBasicValue::create(value.number()); break;
     90            case SQLValue::StringValue: inspectorValue = InspectorValue::create(value.string()); break;
     91            case SQLValue::NumberValue: inspectorValue = InspectorValue::create(value.number()); break;
    9292            case SQLValue::NullValue: inspectorValue = InspectorValue::null(); break;
    9393            }
Note: See TracChangeset for help on using the changeset viewer.