Unreviewed, rolling out r199242.
https://bugs.webkit.org/show_bug.cgi?id=156442
Caused many many leaks (Requested by ap on #webkit).
Reverted changeset:
"Web Inspector: get rid of InspectorBasicValue and
InspectorString subclasses"
https://bugs.webkit.org/show_bug.cgi?id=156407
http://trac.webkit.org/changeset/199242
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@199276 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp b/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp
index d9bba87..27ec8a1 100644
--- a/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp
+++ b/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp
@@ -99,9 +99,9 @@
if (!hadException) {
*result = resultValue.toInspectorValue(m_injectedScriptObject.scriptState());
if (!*result)
- *result = InspectorValue::create(String::format("Object has too long reference chain (must not be longer than %d)", InspectorValue::maxDepth));
+ *result = InspectorString::create(String::format("Object has too long reference chain (must not be longer than %d)", InspectorValue::maxDepth));
} else
- *result = InspectorValue::create("Exception while making a call.");
+ *result = InspectorString::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)
diff --git a/Source/JavaScriptCore/inspector/InspectorValues.cpp b/Source/JavaScriptCore/inspector/InspectorValues.cpp
index f31e584..547b181 100644
--- a/Source/JavaScriptCore/inspector/InspectorValues.cpp
+++ b/Source/JavaScriptCore/inspector/InspectorValues.cpp
@@ -363,17 +363,17 @@
result = InspectorValue::null();
break;
case BOOL_TRUE:
- result = InspectorValue::create(true);
+ result = InspectorBasicValue::create(true);
break;
case BOOL_FALSE:
- result = InspectorValue::create(false);
+ result = InspectorBasicValue::create(false);
break;
case NUMBER: {
bool ok;
double value = charactersToDouble(tokenStart, tokenEnd - tokenStart, &ok);
if (!ok)
return nullptr;
- result = InspectorValue::create(value);
+ result = InspectorBasicValue::create(value);
break;
}
case STRING: {
@@ -381,7 +381,7 @@
bool ok = decodeString(tokenStart + 1, tokenEnd - 1, value);
if (!ok)
return nullptr;
- result = InspectorValue::create(value);
+ result = InspectorString::create(value);
break;
}
case ARRAY_BEGIN: {
@@ -498,39 +498,59 @@
} // anonymous namespace
-Ref<InspectorValue> InspectorValue::null()
+bool InspectorValue::asBoolean(bool&) const
{
- return adoptRef(*new InspectorValue);
+ return false;
}
-Ref<InspectorValue> InspectorValue::create(bool value)
+bool InspectorValue::asDouble(double&) const
{
- return adoptRef(*new InspectorValue(value));
+ return false;
}
-Ref<InspectorValue> InspectorValue::create(int value)
+bool InspectorValue::asDouble(float&) const
{
- return adoptRef(*new InspectorValue(value));
+ return false;
}
-Ref<InspectorValue> InspectorValue::create(double value)
+bool InspectorValue::asInteger(int&) const
{
- return adoptRef(*new InspectorValue(value));
+ return false;
}
-Ref<InspectorValue> InspectorValue::create(const String& value)
+bool InspectorValue::asInteger(unsigned&) const
{
- return adoptRef(*new InspectorValue(value));
+ return false;
}
-Ref<InspectorValue> InspectorValue::create(const char* value)
+bool InspectorValue::asInteger(long&) const
{
- return adoptRef(*new InspectorValue(value));
+ return false;
}
-bool InspectorValue::asValue(RefPtr<Inspector::InspectorValue> & value)
+bool InspectorValue::asInteger(long long&) const
{
- value = this;
+ 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;
return true;
}
@@ -567,7 +587,14 @@
return result.toString();
}
-bool InspectorValue::asBoolean(bool& output) const
+void InspectorValue::writeJSON(StringBuilder& output) const
+{
+ ASSERT(m_type == Type::Null);
+
+ output.appendLiteral("null");
+}
+
+bool InspectorBasicValue::asBoolean(bool& output) const
{
if (type() != Type::Boolean)
return false;
@@ -576,7 +603,7 @@
return true;
}
-bool InspectorValue::asDouble(double& output) const
+bool InspectorBasicValue::asDouble(double& output) const
{
if (type() != Type::Double)
return false;
@@ -585,7 +612,7 @@
return true;
}
-bool InspectorValue::asDouble(float& output) const
+bool InspectorBasicValue::asDouble(float& output) const
{
if (type() != Type::Double)
return false;
@@ -594,7 +621,7 @@
return true;
}
-bool InspectorValue::asInteger(int& output) const
+bool InspectorBasicValue::asInteger(int& output) const
{
if (type() != Type::Integer && type() != Type::Double)
return false;
@@ -603,7 +630,7 @@
return true;
}
-bool InspectorValue::asInteger(unsigned& output) const
+bool InspectorBasicValue::asInteger(unsigned& output) const
{
if (type() != Type::Integer && type() != Type::Double)
return false;
@@ -612,7 +639,7 @@
return true;
}
-bool InspectorValue::asInteger(long& output) const
+bool InspectorBasicValue::asInteger(long& output) const
{
if (type() != Type::Integer && type() != Type::Double)
return false;
@@ -621,7 +648,7 @@
return true;
}
-bool InspectorValue::asInteger(long long& output) const
+bool InspectorBasicValue::asInteger(long long& output) const
{
if (type() != Type::Integer && type() != Type::Double)
return false;
@@ -630,7 +657,7 @@
return true;
}
-bool InspectorValue::asInteger(unsigned long& output) const
+bool InspectorBasicValue::asInteger(unsigned long& output) const
{
if (type() != Type::Integer && type() != Type::Double)
return false;
@@ -639,7 +666,7 @@
return true;
}
-bool InspectorValue::asInteger(unsigned long long& output) const
+bool InspectorBasicValue::asInteger(unsigned long long& output) const
{
if (type() != Type::Integer && type() != Type::Double)
return false;
@@ -648,32 +675,16 @@
return true;
}
-bool InspectorValue::asString(String& output) const
+void InspectorBasicValue::writeJSON(StringBuilder& output) const
{
- if (type() != Type::String)
- return false;
+ ASSERT(type() == Type::Boolean || type() == Type::Double || type() == Type::Integer);
- output = m_stringValue;
- return true;
-}
-
-void InspectorValue::writeJSON(StringBuilder& output) const
-{
- switch (m_type) {
- case Type::Null:
- output.appendLiteral("null");
- break;
- case Type::Boolean:
+ if (type() == Type::Boolean) {
if (m_booleanValue)
output.appendLiteral("true");
else
output.appendLiteral("false");
- break;
- case Type::String:
- doubleQuoteString(m_stringValue, output);
- break;
- case Type::Double:
- case Type::Integer: {
+ } else if (type() == Type::Double || type() == Type::Integer) {
NumberToLStringBuffer buffer;
if (!std::isfinite(m_doubleValue)) {
output.appendLiteral("null");
@@ -692,11 +703,19 @@
} 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()
@@ -786,7 +805,7 @@
}
InspectorObjectBase::InspectorObjectBase()
- : Inspector::InspectorValue(Type::Object)
+ : InspectorValue(Type::Object)
, m_data()
, m_order()
{
@@ -836,4 +855,34 @@
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
diff --git a/Source/JavaScriptCore/inspector/InspectorValues.h b/Source/JavaScriptCore/inspector/InspectorValues.h
index 2dad504..c14efa5 100644
--- a/Source/JavaScriptCore/inspector/InspectorValues.h
+++ b/Source/JavaScriptCore/inspector/InspectorValues.h
@@ -51,14 +51,11 @@
public:
static const int maxDepth = 1000;
+ InspectorValue()
+ : m_type(Type::Null) { }
virtual ~InspectorValue() { }
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,
@@ -67,24 +64,24 @@
Integer,
String,
Object,
- Array,
+ Array
};
Type type() const { return m_type; }
+
bool isNull() const { return m_type == Type::Null; }
- 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 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>&);
virtual bool asObject(RefPtr<InspectorObject>&);
virtual bool asArray(RefPtr<InspectorArray>&);
@@ -94,41 +91,73 @@
virtual void writeJSON(StringBuilder& output) const;
protected:
- InspectorValue()
- : m_type(Type::Null) { }
-
- explicit InspectorValue(Type type)
- : m_type(type) { }
-
- explicit InspectorValue(bool value)
- : m_type(Type::Boolean)
- , m_booleanValue(value) { }
-
- explicit InspectorValue(int value)
- : m_type(Type::Integer)
- , m_doubleValue(static_cast<double>(value)) { }
-
- explicit InspectorValue(double value)
- : m_type(Type::Double)
- , m_doubleValue(value) { }
-
- explicit InspectorValue(const String& value)
- : m_type(Type::String)
- , m_stringValue(value) { }
-
- explicit InspectorValue(const char* value)
- : m_type(Type::String)
- , m_stringValue(value) { }
+ explicit InspectorValue(Type type) : m_type(type) { }
private:
- Type m_type { Type::Null };
+ Type m_type;
+};
+
+class JS_EXPORT_PRIVATE InspectorBasicValue : public InspectorValue {
+public:
+
+ static Ref<InspectorBasicValue> create(bool);
+ static Ref<InspectorBasicValue> create(int);
+ static Ref<InspectorBasicValue> create(double);
+
+ 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;
+
+ void writeJSON(StringBuilder& output) const override;
+
+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) { }
+
union {
bool m_booleanValue;
double m_doubleValue;
- String m_stringValue;
};
};
+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;
@@ -300,22 +329,22 @@
inline void InspectorObjectBase::setBoolean(const String& name, bool value)
{
- setValue(name, InspectorValue::create(value));
+ setValue(name, InspectorBasicValue::create(value));
}
inline void InspectorObjectBase::setInteger(const String& name, int value)
{
- setValue(name, InspectorValue::create(value));
+ setValue(name, InspectorBasicValue::create(value));
}
inline void InspectorObjectBase::setDouble(const String& name, double value)
{
- setValue(name, InspectorValue::create(value));
+ setValue(name, InspectorBasicValue::create(value));
}
inline void InspectorObjectBase::setString(const String& name, const String& value)
{
- setValue(name, InspectorValue::create(value));
+ setValue(name, InspectorString::create(value));
}
inline void InspectorObjectBase::setValue(const String& name, RefPtr<InspectorValue>&& value)
@@ -341,22 +370,22 @@
inline void InspectorArrayBase::pushBoolean(bool value)
{
- m_data.append(InspectorValue::create(value));
+ m_data.append(InspectorBasicValue::create(value));
}
inline void InspectorArrayBase::pushInteger(int value)
{
- m_data.append(InspectorValue::create(value));
+ m_data.append(InspectorBasicValue::create(value));
}
inline void InspectorArrayBase::pushDouble(double value)
{
- m_data.append(InspectorValue::create(value));
+ m_data.append(InspectorBasicValue::create(value));
}
inline void InspectorArrayBase::pushString(const String& value)
{
- m_data.append(InspectorValue::create(value));
+ m_data.append(InspectorString::create(value));
}
inline void InspectorArrayBase::pushValue(RefPtr<InspectorValue>&& value)