aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4jsonobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-04-28 18:27:15 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-15 18:27:12 +0000
commit3ef875b2aa7e850971e6865136029d450aa9928b (patch)
treea4215497cfe2199b8f98781078967c487c7dc4a5 /src/qml/jsruntime/qv4jsonobject.cpp
parent76e61ded19931f45e9519a284f1af9d0782004c6 (diff)
Fix another place where we were not compatible with a moving GC
Don't store a vector of Heap::String's. Instead allocate them on the JS stack and simply keep a pointer to them. Change-Id: Ie12b5f4d56446234519b5e2f0b33120834e927ab Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/jsruntime/qv4jsonobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4jsonobject.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp
index 56750f75c8..9cc0ccdb04 100644
--- a/src/qml/jsruntime/qv4jsonobject.cpp
+++ b/src/qml/jsruntime/qv4jsonobject.cpp
@@ -614,15 +614,15 @@ struct Stringify
{
ExecutionEngine *v4;
FunctionObject *replacerFunction;
- // ### GC
- QVector<Heap::String *> propertyList;
+ QV4::String *propertyList;
+ int propertyListSize;
QString gap;
QString indent;
// ### GC
QStack<Heap::Object *> stack;
- Stringify(ExecutionEngine *e) : v4(e), replacerFunction(0) {}
+ Stringify(ExecutionEngine *e) : v4(e), replacerFunction(0), propertyList(0), propertyListSize(0) {}
QString Str(const QString &key, const Value &v);
QString JA(ArrayObject *a);
@@ -763,7 +763,7 @@ QString Stringify::JO(Object *o)
indent += gap;
QStringList partial;
- if (propertyList.isEmpty()) {
+ if (!propertyListSize) {
ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly);
ScopedValue name(scope);
@@ -778,11 +778,13 @@ QString Stringify::JO(Object *o)
partial += member;
}
} else {
- ScopedString s(scope);
- for (int i = 0; i < propertyList.size(); ++i) {
+ ScopedValue v(scope);
+ for (int i = 0; i < propertyListSize; ++i) {
bool exists;
- s = propertyList.at(i);
- ScopedValue v(scope, o->get(s, &exists));
+ String *s = propertyList + i;
+ if (!s)
+ continue;
+ v = o->get(s, &exists);
if (!exists)
continue;
QString member = makeMember(s->toQString(), v);
@@ -891,15 +893,21 @@ ReturnedValue JsonObject::method_stringify(CallContext *ctx)
stringify.replacerFunction = o->as<FunctionObject>();
if (o->isArrayObject()) {
uint arrayLen = o->getLength();
- ScopedValue v(scope);
+ stringify.propertyList = static_cast<QV4::String *>(scope.alloc(arrayLen));
for (uint i = 0; i < arrayLen; ++i) {
- v = o->getIndexed(i);
+ Value *v = stringify.propertyList + i;
+ *v = o->getIndexed(i);
if (v->as<NumberObject>() || v->as<StringObject>() || v->isNumber())
- v = RuntimeHelpers::toString(scope.engine, v);
- if (v->isString()) {
- String *s = v->stringValue();
- if (!stringify.propertyList.contains(s->d()))
- stringify.propertyList.append(s->d());
+ *v = RuntimeHelpers::toString(scope.engine, *v);
+ if (!v->isString()) {
+ v->m = 0;
+ } else {
+ for (uint j = 0; j <i; ++j) {
+ if (stringify.propertyList[j].m == v->m) {
+ v->m = 0;
+ break;
+ }
+ }
}
}
}