aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-09-19 12:55:36 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-22 01:06:20 +0200
commita9bdc91cefabb3729d0240fce4c01a669be09dbf (patch)
tree6f2a2639164ec1a530ccc33bc96bece299df0dbf /src/qml
parent49369e62b50a4f903a5b2fcbfbfbc1f6f2838e8e (diff)
Fix some more methods to take ValueRef's
Change-Id: Ia0e30ba98c16e51c9992027c7e5f78d4def8697a Reviewed-by: Simon Hausmann <simon.hausmann@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4arrayobject.cpp8
-rw-r--r--src/qml/jsruntime/qv4jsonobject.cpp8
-rw-r--r--src/qml/jsruntime/qv4object.cpp6
-rw-r--r--src/qml/jsruntime/qv4object_p.h16
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp16
5 files changed, 28 insertions, 26 deletions
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp
index 5e2a7db9a1..1ff64830ae 100644
--- a/src/qml/jsruntime/qv4arrayobject.cpp
+++ b/src/qml/jsruntime/qv4arrayobject.cpp
@@ -164,7 +164,7 @@ ReturnedValue ArrayPrototype::method_concat(SimpleCallContext *ctx)
if (instance) {
result->copyArrayData(instance.getPointer());
} else {
- result->arraySet(0, thisObject.asValue());
+ result->arraySet(0, thisObject);
}
for (uint i = 0; i < ctx->argumentCount; ++i) {
@@ -284,17 +284,15 @@ ReturnedValue ArrayPrototype::method_push(SimpleCallContext *ctx)
if (!instance->protoHasArray() && instance->arrayDataLen <= len) {
for (uint i = 0; i < ctx->argumentCount; ++i) {
- Value v = ctx->arguments[i];
-
if (!instance->sparseArray) {
if (len >= instance->arrayAlloc)
instance->arrayReserve(len + 1);
- instance->arrayData[len].value = v;
+ instance->arrayData[len].value = ctx->arguments[i];
if (instance->arrayAttributes)
instance->arrayAttributes[len] = Attr_Data;
instance->arrayDataLen = len + 1;
} else {
- uint i = instance->allocArrayValue(v);
+ uint i = instance->allocArrayValue(ctx->arguments[i]);
instance->sparseArray->push_back(i, len);
}
++len;
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp
index e3e159233b..f311dfd420 100644
--- a/src/qml/jsruntime/qv4jsonobject.cpp
+++ b/src/qml/jsruntime/qv4jsonobject.cpp
@@ -81,7 +81,7 @@ private:
ReturnedValue parseArray();
bool parseMember(Object *o);
bool parseString(QString *string);
- bool parseValue(Value *val);
+ bool parseValue(ValueRef val);
bool parseNumber(Value *val);
ExecutionContext *context;
@@ -313,8 +313,8 @@ ReturnedValue JsonParser::parseArray()
} else {
uint index = 0;
while (1) {
- Value val;
- if (!parseValue(&val))
+ ScopedValue val(scope);
+ if (!parseValue(val))
return Encode::undefined();
array->arraySet(index, val);
QChar token = nextToken();
@@ -343,7 +343,7 @@ value = false / null / true / object / array / number / string
*/
-bool JsonParser::parseValue(Value *val)
+bool JsonParser::parseValue(ValueRef val)
{
BEGIN << "parse Value" << *json;
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index 7b9074edd5..77c755e413 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -861,7 +861,7 @@ void Object::internalPutIndexed(uint index, const ValueRef value)
return;
}
- arraySet(index, *value);
+ arraySet(index, value);
return;
reject:
@@ -1110,13 +1110,15 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, const QString &name, c
void Object::copyArrayData(Object *other)
{
Q_ASSERT(isArrayObject());
+ Scope scope(engine());
if (other->protoHasArray() || other->hasAccessorProperty) {
uint len = other->arrayLength();
Q_ASSERT(len);
+ ScopedValue v(scope);
for (uint i = 0; i < len; ++i) {
- arraySet(i, Value::fromReturnedValue(other->getIndexed(i)));
+ arraySet(i, (v = other->getIndexed(i)));
}
} else {
arrayReserve(other->arrayDataLen);
diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h
index b97d682c3d..03cc56ac79 100644
--- a/src/qml/jsruntime/qv4object_p.h
+++ b/src/qml/jsruntime/qv4object_p.h
@@ -186,10 +186,10 @@ struct Q_QML_EXPORT Object: Managed {
return idx;
}
- uint allocArrayValue(Value v) {
+ uint allocArrayValue(const ValueRef v) {
uint idx = allocArrayValue();
Property *pd = &arrayData[idx];
- pd->value = v;
+ pd->value = *v;
return idx;
}
void freeArrayValue(int idx) {
@@ -228,7 +228,7 @@ public:
Property *arrayInsert(uint index, PropertyAttributes attributes = Attr_Data);
void arraySet(uint index, const Property *pd);
- void arraySet(uint index, Value value);
+ void arraySet(uint index, ValueRef value);
uint propertyIndexFromArrayIndex(uint index) const
{
@@ -261,7 +261,7 @@ public:
void markArrayObjects() const;
- void push_back(Value v);
+ void push_back(const ValueRef v);
SparseArrayNode *sparseArrayBegin() { return sparseArray ? sparseArray->begin() : 0; }
SparseArrayNode *sparseArrayEnd() { return sparseArray ? sparseArray->end() : 0; }
@@ -397,13 +397,13 @@ inline void Object::setArrayLengthUnchecked(uint l)
}
}
-inline void Object::push_back(Value v)
+inline void Object::push_back(const ValueRef v)
{
uint idx = arrayLength();
if (!sparseArray) {
if (idx >= arrayAlloc)
arrayReserve(idx + 1);
- arrayData[idx].value = v;
+ arrayData[idx].value = *v;
arrayDataLen = idx + 1;
} else {
uint idx = allocArrayValue(v);
@@ -445,10 +445,10 @@ inline Property *Object::arrayInsert(uint index, PropertyAttributes attributes)
return pd;
}
-inline void Object::arraySet(uint index, Value value)
+inline void Object::arraySet(uint index, ValueRef value)
{
Property *pd = arrayInsert(index);
- pd->value = value;
+ pd->value = *value;
}
inline void Object::arraySet(uint index, const Property *pd)
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index 26f662d005..feee229668 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -634,7 +634,8 @@ ReturnedValue StringPrototype::method_split(SimpleCallContext *ctx)
if (separatorValue->isUndefined()) {
if (limitValue->isUndefined()) {
- array->push_back(Value::fromString(ctx, text));
+ ScopedString s(scope, ctx->engine->newString(text));
+ array->push_back(s);
return array.asReturnedValue();
}
return Value::fromString(ctx, text.left(limitValue->toInteger())).asReturnedValue();
@@ -653,6 +654,7 @@ ReturnedValue StringPrototype::method_split(SimpleCallContext *ctx)
}
}
+ ScopedString s(scope);
if (!!re) {
uint offset = 0;
uint* matchOffsets = (uint*)alloca(re->value->captureCount() * 2 * sizeof(uint));
@@ -661,7 +663,7 @@ ReturnedValue StringPrototype::method_split(SimpleCallContext *ctx)
if (result == JSC::Yarr::offsetNoMatch)
break;
- array->push_back(Value::fromString(ctx, text.mid(offset, matchOffsets[0] - offset)));
+ array->push_back((s = Value::fromString(ctx, text.mid(offset, matchOffsets[0] - offset))));
offset = qMax(offset + 1, matchOffsets[1]);
if (array->arrayLength() >= limit)
@@ -670,31 +672,31 @@ ReturnedValue StringPrototype::method_split(SimpleCallContext *ctx)
for (int i = 1; i < re->value->captureCount(); ++i) {
uint start = matchOffsets[i * 2];
uint end = matchOffsets[i * 2 + 1];
- array->push_back(Value::fromString(ctx, text.mid(start, end - start)));
+ array->push_back((s = Value::fromString(ctx, text.mid(start, end - start))));
if (array->arrayLength() >= limit)
break;
}
}
if (array->arrayLength() < limit)
- array->push_back(Value::fromString(ctx, text.mid(offset)));
+ array->push_back((s = Value::fromString(ctx, text.mid(offset))));
} else {
QString separator = separatorValue->toString(ctx)->toQString();
if (separator.isEmpty()) {
for (uint i = 0; i < qMin(limit, uint(text.length())); ++i)
- array->push_back(Value::fromString(ctx, text.mid(i, 1)));
+ array->push_back((s = Value::fromString(ctx, text.mid(i, 1))));
return array.asReturnedValue();
}
int start = 0;
int end;
while ((end = text.indexOf(separator, start)) != -1) {
- array->push_back(Value::fromString(ctx, text.mid(start, end - start)));
+ array->push_back((s = Value::fromString(ctx, text.mid(start, end - start))));
start = end + separator.size();
if (array->arrayLength() >= limit)
break;
}
if (array->arrayLength() < limit && start != -1)
- array->push_back(Value::fromString(ctx, text.mid(start)));
+ array->push_back((s = Value::fromString(ctx, text.mid(start))));
}
return array.asReturnedValue();
}