diff options
author | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2010-04-06 10:36:47 (GMT) |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2010-04-06 10:36:47 (GMT) |
commit | bb35b65bbfba82e0dd0ac306d3dab54436cdaff6 (patch) | |
tree | 8174cb262a960ff7b2e4aa8f1aaf154db71d2636 /src/3rdparty/webkit/JavaScriptCore/runtime/JSONObject.cpp | |
parent | 4b27d0d887269583a0f76e922948f8c25e96ab88 (diff) | |
download | Qt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.zip Qt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.tar.gz Qt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.tar.bz2 |
Update src/3rdparty/webkit from trunk.
Imported from 839d8709327f925aacb3b6362c06152594def97e
in branch qtwebkit-2.0 of repository
git://gitorious.org/+qtwebkit-developers/webkit/qtwebkit.git
Rubber-stamped-by: Simon Hausmann
Diffstat (limited to 'src/3rdparty/webkit/JavaScriptCore/runtime/JSONObject.cpp')
-rw-r--r-- | src/3rdparty/webkit/JavaScriptCore/runtime/JSONObject.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/JSONObject.cpp b/src/3rdparty/webkit/JavaScriptCore/runtime/JSONObject.cpp index 297d457..d5f3303 100644 --- a/src/3rdparty/webkit/JavaScriptCore/runtime/JSONObject.cpp +++ b/src/3rdparty/webkit/JavaScriptCore/runtime/JSONObject.cpp @@ -32,6 +32,7 @@ #include "JSArray.h" #include "LiteralParser.h" #include "PropertyNameArray.h" +#include "StringBuilder.h" #include <wtf/MathExtras.h> namespace JSC { @@ -70,8 +71,6 @@ public: void markAggregate(MarkStack&); private: - typedef UString StringBuilder; - class Holder { public: Holder(JSObject*); @@ -136,7 +135,7 @@ static inline JSValue unwrapBoxedPrimitive(ExecState* exec, JSValue value) static inline UString gap(ExecState* exec, JSValue space) { - const int maxGapLength = 10; + const unsigned maxGapLength = 10; space = unwrapBoxedPrimitive(exec, space); // If the space value is a number, create a gap string with that number of spaces. @@ -156,7 +155,7 @@ static inline UString gap(ExecState* exec, JSValue space) } // If the space value is a string, use it as the gap string, otherwise use no gap string. - UString spaces = space.getString(); + UString spaces = space.getString(exec); if (spaces.size() > maxGapLength) { spaces = spaces.substr(0, maxGapLength); } @@ -213,7 +212,7 @@ Stringifier::Stringifier(ExecState* exec, JSValue replacer, JSValue space) break; UString propertyName; - if (name.getString(propertyName)) { + if (name.getString(exec, propertyName)) { m_arrayReplacerPropertyNames.add(Identifier(exec, propertyName)); continue; } @@ -269,7 +268,7 @@ JSValue Stringifier::stringify(JSValue value) if (m_exec->hadException()) return jsNull(); - return jsString(m_exec, result); + return jsString(m_exec, result.build()); } void Stringifier::appendQuotedString(StringBuilder& builder, const UString& value) @@ -389,7 +388,7 @@ Stringifier::StringifyResult Stringifier::appendStringifiedValue(StringBuilder& } UString stringValue; - if (value.getString(stringValue)) { + if (value.getString(m_exec, stringValue)) { appendQuotedString(builder, stringValue); return StringifySucceeded; } @@ -457,9 +456,9 @@ inline bool Stringifier::willIndent() const inline void Stringifier::indent() { // Use a single shared string, m_repeatedGap, so we don't keep allocating new ones as we indent and unindent. - int newSize = m_indent.size() + m_gap.size(); + unsigned newSize = m_indent.size() + m_gap.size(); if (newSize > m_repeatedGap.size()) - m_repeatedGap.append(m_gap); + m_repeatedGap = makeString(m_repeatedGap, m_gap); ASSERT(newSize <= m_repeatedGap.size()); m_indent = m_repeatedGap.substr(0, newSize); } @@ -502,7 +501,7 @@ bool Stringifier::Holder::appendNextProperty(Stringifier& stringifier, StringBui m_propertyNames = stringifier.m_arrayReplacerPropertyNames.data(); else { PropertyNameArray objectPropertyNames(exec); - m_object->getPropertyNames(exec, objectPropertyNames); + m_object->getOwnPropertyNames(exec, objectPropertyNames); m_propertyNames = objectPropertyNames.releaseData(); } m_size = m_propertyNames->propertyNameVector().size(); @@ -586,7 +585,7 @@ bool Stringifier::Holder::appendNextProperty(Stringifier& stringifier, StringBui // This only occurs when get an undefined value for an object property. // In this case we don't want the separator and property name that we // already appended, so roll back. - builder = builder.substr(0, rollBackPoint); + builder.resize(rollBackPoint); break; } @@ -747,7 +746,7 @@ NEVER_INLINE JSValue Walker::walk(JSValue unfiltered) objectStack.append(object); indexStack.append(0); propertyStack.append(PropertyNameArray(m_exec)); - object->getPropertyNames(m_exec, propertyStack.last()); + object->getOwnPropertyNames(m_exec, propertyStack.last()); // fallthrough } objectStartVisitMember: @@ -869,4 +868,12 @@ JSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState* exec, JSObject*, JSValue return Stringifier(exec, replacer, space).stringify(value); } +UString JSONStringify(ExecState* exec, JSValue value, unsigned indent) +{ + JSValue result = Stringifier(exec, jsNull(), jsNumber(exec, indent)).stringify(value); + if (result.isUndefinedOrNull()) + return UString(); + return result.getString(exec); +} + } // namespace JSC |