~QQmlSqlDatabaseWrapper() {
}
- static Value getIndexed(Managed *m, uint index, bool *hasProperty);
+ static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
static void destroy(Managed *that) {
static_cast<QQmlSqlDatabaseWrapper *>(that)->~QQmlSqlDatabaseWrapper();
}
}
}
-Value QQmlSqlDatabaseWrapper::getIndexed(Managed *m, uint index, bool *hasProperty)
+ReturnedValue QQmlSqlDatabaseWrapper::getIndexed(Managed *m, uint index, bool *hasProperty)
{
QQmlSqlDatabaseWrapper *r = m->as<QQmlSqlDatabaseWrapper>();
if (!r || r->type != QQmlSqlDatabaseWrapper::Rows)
return Object::getIndexed(m, index, hasProperty);
- return qmlsqldatabase_rows_index(r, m->engine(), index, hasProperty);
+ return qmlsqldatabase_rows_index(r, m->engine(), index, hasProperty).asReturnedValue();
}
static Value qmlsqldatabase_rows_item(SimpleCallContext *ctx)
if (ArrayObject *array = values.asArrayObject()) {
quint32 size = array->arrayLength();
for (quint32 ii = 0; ii < size; ++ii)
- query.bindValue(ii, engine->toVariant(array->getIndexed(ii), -1));
+ query.bindValue(ii, engine->toVariant(QV4::Value::fromReturnedValue(array->getIndexed(ii)), -1));
} else if (Object *object = values.asObject()) {
ObjectIterator it(object, ObjectIterator::WithProtoChain|ObjectIterator::EnumerableOnly);
while (1) {
QV4::ExecutionContext *ctx = engine->current;
try {
- QV4::ScopedValue v(scope, arrayIndex == UINT_MAX ? o->get(engine->id_uintMax) : o->getIndexed(arrayIndex).asReturnedValue());
+ QV4::ScopedValue v(scope, arrayIndex == UINT_MAX ? o->get(engine->id_uintMax) : o->getIndexed(arrayIndex));
return new QJSValuePrivate(engine, v);
} catch (QV4::Exception &e) {
e.accept(ctx);
// ### FIXME
if (ArrayObject *a = self->asArrayObject()) {
+ ScopedValue e(scope);
for (uint i = 0; i < a->arrayLength(); ++i) {
if (i)
R += r4;
- Value e = a->getIndexed(i);
- if (! (e.isUndefined() || e.isNull()))
- R += e.toString(ctx)->toQString();
+ e = a->getIndexed(i);
+ if (!e->isNullOrUndefined())
+ R += e->toString(ctx)->toQString();
}
} else {
//
Value ArrayPrototype::method_pop(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
return Value::undefinedValue();
}
- Value result = instance->getIndexed(len - 1);
+ ScopedValue result(scope, instance->getIndexed(len - 1));
instance->deleteIndexedProperty(len - 1);
if (instance->isArrayObject())
Value ArrayPrototype::method_reverse(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
Object *instance = ctx->thisObject.toObject(ctx);
uint length = getLength(ctx, instance);
int lo = 0, hi = length - 1;
+ ScopedValue lval(scope);
+ ScopedValue hval(scope);
for (; lo < hi; ++lo, --hi) {
bool loExists, hiExists;
- Value lval = instance->getIndexed(lo, &loExists);
- Value hval = instance->getIndexed(hi, &hiExists);
+ lval = instance->getIndexed(lo, &loExists);
+ hval = instance->getIndexed(hi, &hiExists);
if (hiExists)
instance->putIndexed(lo, hval);
else
Value ArrayPrototype::method_shift(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
instance->freeArrayValue(idx);
}
} else {
+ ScopedValue v(scope);
// do it the slow way
for (uint k = 1; k < len; ++k) {
bool exists;
- Value v = instance->getIndexed(k, &exists);
+ v = instance->getIndexed(k, &exists);
if (exists)
instance->putIndexed(k - 1, v);
else
Value ArrayPrototype::method_slice(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
Object *o = ctx->thisObject.toObject(ctx);
ArrayObject *result = ctx->engine->newArrayObject();
end = (uint) e;
}
+ ScopedValue v(scope);
uint n = 0;
for (uint i = start; i < end; ++i) {
bool exists;
- Value v = o->getIndexed(i, &exists);
+ v = o->getIndexed(i, &exists);
if (exists) {
result->arraySet(n, v);
}
Value ArrayPrototype::method_splice(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
newArray->arrayReserve(deleteCount);
Property *pd = newArray->arrayData;
for (uint i = 0; i < deleteCount; ++i) {
- pd->value = instance->getIndexed(start + i);
+ pd->value = Value::fromReturnedValue(instance->getIndexed(start + i));
++pd;
}
newArray->arrayDataLen = deleteCount;
uint itemCount = ctx->argumentCount < 2 ? 0 : ctx->argumentCount - 2;
+ ScopedValue v(scope);
if (itemCount < deleteCount) {
for (uint k = start; k < len - deleteCount; ++k) {
bool exists;
- Value v = instance->getIndexed(k + deleteCount, &exists);
+ v = instance->getIndexed(k + deleteCount, &exists);
if (exists)
instance->putIndexed(k + itemCount, v);
else
uint k = len - deleteCount;
while (k > start) {
bool exists;
- Value v = instance->getIndexed(k + deleteCount - 1, &exists);
+ v = instance->getIndexed(k + deleteCount - 1, &exists);
if (exists)
instance->putIndexed(k + itemCount - 1, v);
else
Value ArrayPrototype::method_unshift(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
}
}
} else {
+ ScopedValue v(scope);
for (uint k = len; k > 0; --k) {
bool exists;
- Value v = instance->getIndexed(k - 1, &exists);
+ v = instance->getIndexed(k - 1, &exists);
if (exists)
instance->putIndexed(k + ctx->argumentCount - 1, v);
else
callData->args[2] = Value::fromObject(instance);
callData->thisObject = thisArg;
ScopedValue r(scope);
+ ScopedValue v(scope);
bool ok = true;
for (uint k = 0; ok && k < len; ++k) {
bool exists;
- Value v = instance->getIndexed(k, &exists);
+ v = instance->getIndexed(k, &exists);
if (!exists)
continue;
ScopedCallData callData(scope, 3);
callData->thisObject = ctx->argument(1);
callData->args[2] = Value::fromObject(instance);
+ ScopedValue v(scope);
for (uint k = 0; k < len; ++k) {
bool exists;
- Value v = instance->getIndexed(k, &exists);
+ v = instance->getIndexed(k, &exists);
if (!exists)
continue;
callData->thisObject = ctx->argument(1);
callData->args[2] = Value::fromObject(instance);
+ ScopedValue v(scope);
for (uint k = 0; k < len; ++k) {
bool exists;
- Value v = instance->getIndexed(k, &exists);
+ v = instance->getIndexed(k, &exists);
if (!exists)
continue;
callData->thisObject = thisArg;
callData->args[2] = Value::fromObject(instance);
+ ScopedValue v(scope);
for (uint k = 0; k < len; ++k) {
bool exists;
- Value v = instance->getIndexed(k, &exists);
+ v = instance->getIndexed(k, &exists);
if (!exists)
continue;
callData->thisObject = thisArg;
callData->args[2] = Value::fromObject(instance);
+ ScopedValue v(scope);
+
uint to = 0;
for (uint k = 0; k < len; ++k) {
bool exists;
- Value v = instance->getIndexed(k, &exists);
+ v = instance->getIndexed(k, &exists);
if (!exists)
continue;
uint k = 0;
ScopedValue acc(scope);
+ ScopedValue v(scope);
+
if (ctx->argumentCount > 1) {
acc = ctx->argument(1);
} else {
bool kPresent = false;
while (k < len && !kPresent) {
- Value v = instance->getIndexed(k, &kPresent);
+ v = instance->getIndexed(k, &kPresent);
if (kPresent)
acc = v;
++k;
while (k < len) {
bool kPresent;
- Value v = instance->getIndexed(k, &kPresent);
+ v = instance->getIndexed(k, &kPresent);
if (kPresent) {
callData->args[0] = acc;
callData->args[1] = v;
uint k = len;
ScopedValue acc(scope);
+ ScopedValue v(scope);
if (ctx->argumentCount > 1) {
acc = ctx->argument(1);
} else {
bool kPresent = false;
while (k > 0 && !kPresent) {
- Value v = instance->getIndexed(k - 1, &kPresent);
+ v = instance->getIndexed(k - 1, &kPresent);
if (kPresent)
acc = v;
--k;
while (k > 0) {
bool kPresent;
- Value v = instance->getIndexed(k - 1, &kPresent);
+ v = instance->getIndexed(k - 1, &kPresent);
if (kPresent) {
callData->args[0] = acc;
callData->args[1] = v;
if (len) {
if (arr->protoHasArray() || arr->hasAccessorProperty) {
for (quint32 i = 0; i < len; ++i)
- callData->args[i] = arr->getIndexed(i);
+ callData->args[i] = Value::fromReturnedValue(arr->getIndexed(i));
} else {
int alen = qMin(len, arr->arrayDataLen);
for (quint32 i = 0; i < alen; ++i)
if (stack.contains(a))
ctx->throwTypeError();
+ Scope scope(a->engine());
+
QString result;
stack.push(a);
QString stepback = indent;
QStringList partial;
uint len = a->arrayLength();
+ ScopedValue v(scope);
for (uint i = 0; i < len; ++i) {
bool exists;
- Value v = a->getIndexed(i, &exists);
+ v = a->getIndexed(i, &exists);
if (!exists) {
partial += QStringLiteral("null");
continue;
if (!a)
return result;
+ Scope scope(a->engine());
+
if (visitedObjects.contains(a)) {
// Avoid recursion.
// For compatibility with QVariant{List,Map} conversion, we return an
visitedObjects.insert(a);
+ ScopedValue v(scope);
quint32 length = a->arrayLength();
for (quint32 i = 0; i < length; ++i) {
- Value v = a->getIndexed(i);
- result.append(toJsonValue(v.asFunctionObject() ? QV4::Value::nullValue() : v, visitedObjects));
+ v = a->getIndexed(i);
+ result.append(toJsonValue(v->asFunctionObject() ? QV4::Value::nullValue() : v, visitedObjects));
}
visitedObjects.remove(a);
return vtbl->get(this, name, hasProperty);
}
-Value Managed::getIndexed(uint index, bool *hasProperty)
+ReturnedValue Managed::getIndexed(uint index, bool *hasProperty)
{
return vtbl->getIndexed(this, index, hasProperty);
}
void (*collectDeletables)(Managed *, GCDeletable **deletable);
bool (*hasInstance)(Managed *, const Value &value);
ReturnedValue (*get)(Managed *, String *name, bool *hasProperty);
- Value (*getIndexed)(Managed *, uint index, bool *hasProperty);
+ ReturnedValue (*getIndexed)(Managed *, uint index, bool *hasProperty);
void (*put)(Managed *, String *name, const Value &value);
void (*putIndexed)(Managed *, uint index, const Value &value);
PropertyAttributes (*query)(const Managed *, String *name);
ReturnedValue construct(CallData *d);
ReturnedValue call(CallData *d);
ReturnedValue get(String *name, bool *hasProperty = 0);
- Value getIndexed(uint index, bool *hasProperty = 0);
+ ReturnedValue getIndexed(uint index, bool *hasProperty = 0);
void put(String *name, const Value &value)
{ vtbl->put(this, name, value); }
void putIndexed(uint index, const Value &value)
return static_cast<Object *>(m)->internalGet(name, hasProperty);
}
-Value Object::getIndexed(Managed *m, uint index, bool *hasProperty)
+ReturnedValue Object::getIndexed(Managed *m, uint index, bool *hasProperty)
{
return static_cast<Object *>(m)->internalGetIndexed(index, hasProperty);
}
{
uint idx = name->asArrayIndex();
if (idx != UINT_MAX)
- return getIndexed(idx, hasProperty).asReturnedValue();
+ return getIndexed(idx, hasProperty);
name->makeIdentifier();
return Value::undefinedValue().asReturnedValue();
}
-Value Object::internalGetIndexed(uint index, bool *hasProperty)
+ReturnedValue Object::internalGetIndexed(uint index, bool *hasProperty)
{
Property *pd = 0;
PropertyAttributes attrs = Attr_Data;
if (pd) {
if (hasProperty)
*hasProperty = true;
- return Value::fromReturnedValue(getValue(pd, attrs));
+ return getValue(pd, attrs);
}
if (hasProperty)
*hasProperty = false;
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
Q_ASSERT(len);
for (uint i = 0; i < len; ++i) {
- arraySet(i, other->getIndexed(i));
+ arraySet(i, Value::fromReturnedValue(other->getIndexed(i)));
}
} else {
arrayReserve(other->arrayDataLen);
if (other->arrayAttributes) {
for (int i = 0; i < arrayDataLen; ++i) {
bool exists;
- arrayData[oldSize + i].value = const_cast<ArrayObject *>(other)->getIndexed(i, &exists);
+ arrayData[oldSize + i].value = Value::fromReturnedValue(const_cast<ArrayObject *>(other)->getIndexed(i, &exists));
if (arrayAttributes)
arrayAttributes[oldSize + i] = Attr_Data;
if (!exists) {
QStringList result;
QV4::ExecutionEngine *engine = internalClass->engine;
+ Scope scope(engine);
+ ScopedValue v(scope);
uint32_t length = arrayLength();
- for (uint32_t i = 0; i < length; ++i)
- result.append(const_cast<ArrayObject *>(this)->getIndexed(i).toString(engine->current)->toQString());
+ for (uint32_t i = 0; i < length; ++i) {
+ v = const_cast<ArrayObject *>(this)->getIndexed(i);
+ result.append(v->toString(engine->current)->toQString());
+ }
return result;
}
inline ReturnedValue get(String *name, bool *hasProperty = 0)
{ return vtbl->get(this, name, hasProperty); }
- inline Value getIndexed(uint idx, bool *hasProperty = 0)
+ inline ReturnedValue getIndexed(uint idx, bool *hasProperty = 0)
{ return vtbl->getIndexed(this, idx, hasProperty); }
inline void put(String *name, const Value &v)
{ vtbl->put(this, name, v); }
static void destroy(Managed *that);
static void markObjects(Managed *that);
static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
- static Value getIndexed(Managed *m, uint index, bool *hasProperty);
+ static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static void putIndexed(Managed *m, uint index, const Value &value);
static PropertyAttributes query(const Managed *m, String *name);
private:
ReturnedValue internalGet(String *name, bool *hasProperty);
- Value internalGetIndexed(uint index, bool *hasProperty);
+ ReturnedValue internalGetIndexed(uint index, bool *hasProperty);
void internalPut(String *name, const Value &value);
void internalPutIndexed(uint index, const Value &value);
bool internalDeleteProperty(String *name);
} else if (callType == qMetaTypeId<QList<QObject*> >()) {
qlistPtr = new (&allocData) QList<QObject *>();
if (QV4::ArrayObject *array = value.asArrayObject()) {
+ QV4::Scope scope(array->engine());
+ Scoped<QV4::QObjectWrapper> qobjectWrapper(scope);
+
uint32_t length = array->arrayLength();
for (uint32_t ii = 0; ii < length; ++ii) {
QObject *o = 0;
- if (QV4::QObjectWrapper *qobjectWrapper = array->getIndexed(ii).as<QV4::QObjectWrapper>())
+ qobjectWrapper = array->getIndexed(ii);
+ if (!!qobjectWrapper)
o = qobjectWrapper->object();
qlistPtr->append(o);
}
return Value::undefinedValue().asReturnedValue();
}
-Value RegExp::getIndexed(Managed *m, uint index, bool *hasProperty)
+ReturnedValue RegExp::getIndexed(Managed *m, uint index, bool *hasProperty)
{
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
void RegExp::put(Managed *m, String *name, const Value &value)
static void destroy(Managed *that);
static void markObjects(Managed *that);
static ReturnedValue get(Managed *, String *, bool *);
- static Value getIndexed(Managed *m, uint index, bool *hasProperty);
+ static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static void putIndexed(Managed *m, uint index, const Value &value);
static PropertyAttributes query(const Managed *m, String *name);
}
}
- return o->getIndexed(idx).asReturnedValue();
+ return o->getIndexed(idx);
}
String *name = index->toString(ctx);
Container result;
quint32 length = array->arrayLength();
for (quint32 i = 0; i < length; ++i)
- result << convertValueToElement<typename Container::value_type>(array->getIndexed(i));
+ result << convertValueToElement<typename Container::value_type>(QV4::Value::fromReturnedValue(array->getIndexed(i)));
return QVariant::fromValue(result);
}
int m_propertyIndex;
bool m_isReference;
- static QV4::Value getIndexed(QV4::Managed *that, uint index, bool *hasProperty)
- { return static_cast<QQmlSequence<Container> *>(that)->containerGetIndexed(index, hasProperty); }
+ static QV4::ReturnedValue getIndexed(QV4::Managed *that, uint index, bool *hasProperty)
+ { return static_cast<QQmlSequence<Container> *>(that)->containerGetIndexed(index, hasProperty).asReturnedValue(); }
static void putIndexed(Managed *that, uint index, const QV4::Value &value)
{ static_cast<QQmlSequence<Container> *>(that)->containerPutIndexed(index, value); }
static QV4::PropertyAttributes queryIndexed(const QV4::Managed *that, uint index)
reserve(data, sizeof(quint32) + length * sizeof(quint32));
push(data, valueheader(WorkerArray, length));
for (uint32_t ii = 0; ii < length; ++ii)
- serialize(data, array->getIndexed(ii), engine);
+ serialize(data, QV4::Value::fromReturnedValue(array->getIndexed(ii)), engine);
} else if (v.isInteger()) {
reserve(data, 2 * sizeof(quint32));
push(data, valueheader(WorkerInt32));
push(data, valueheader(WorkerSequence, length));
serialize(data, QV4::Value::fromInt32(QV4::SequencePrototype::metaTypeForSequence(o)), engine); // sequence type
for (uint32_t ii = 0; ii < seqLength; ++ii)
- serialize(data, o->getIndexed(ii), engine); // sequence elements
+ serialize(data, QV4::Value::fromReturnedValue(o->getIndexed(ii)), engine); // sequence elements
return;
}
push(data, valueheader(WorkerObject, length));
QV4::ScopedValue val(scope);
+ QV4::ScopedValue s(scope);
for (quint32 ii = 0; ii < length; ++ii) {
- QV4::String *s = properties->getIndexed(ii).asString();
- serialize(data, QV4::Value::fromString(s), engine);
+ s = properties->getIndexed(ii);
+ serialize(data, s, engine);
- bool hasCaught = false;
QV4::ExecutionContext *ctx = v4->current;
try {
- val = o->get(s);
+ val = o->get(s->asString());
} catch (QV4::Exception &e) {
e.accept(ctx);
}
return v4->stringClass->prototype->getValue(Value::fromString(that), pd, attrs);
}
-Value String::getIndexed(Managed *m, uint index, bool *hasProperty)
+ReturnedValue String::getIndexed(Managed *m, uint index, bool *hasProperty)
{
String *that = static_cast<String *>(m);
ExecutionEngine *engine = that->engine();
if (index < that->_text.length()) {
if (hasProperty)
*hasProperty = true;
- return Value::fromString(engine->newString(that->toQString().mid(index, 1)));
+ return Value::fromString(engine->newString(that->toQString().mid(index, 1))).asReturnedValue();
}
PropertyAttributes attrs;
Property *pd = engine->stringClass->prototype->__getPropertyDescriptor__(index, &attrs);
if (!pd || attrs.isGeneric()) {
if (hasProperty)
*hasProperty = false;
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
if (hasProperty)
*hasProperty = true;
- return Value::fromReturnedValue(engine->stringClass->prototype->getValue(Value::fromString(that), pd, attrs));
+ return engine->stringClass->prototype->getValue(Value::fromString(that), pd, attrs);
}
void String::put(Managed *m, String *name, const Value &value)
protected:
static void destroy(Managed *);
static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
- static Value getIndexed(Managed *m, uint index, bool *hasProperty);
+ static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static void putIndexed(Managed *m, uint index, const Value &value);
static PropertyAttributes query(const Managed *m, String *name);
uint idx = name->asArrayIndex();
if (idx != UINT_MAX)
- return getIndexed(m, idx, hasProperty).asReturnedValue();
+ return getIndexed(m, idx, hasProperty);
return Object::get(m, name, hasProperty);
}
-Value QmlListWrapper::getIndexed(Managed *m, uint index, bool *hasProperty)
+ReturnedValue QmlListWrapper::getIndexed(Managed *m, uint index, bool *hasProperty)
{
QV4::ExecutionEngine *e = m->engine();
QmlListWrapper *w = m->as<QmlListWrapper>();
quint32 count = w->property.count ? w->property.count(&w->property) : 0;
if (index < count && w->property.at)
- return QV4::QObjectWrapper::wrap(e, w->property.at(&w->property, index));
+ return QV4::QObjectWrapper::wrap(e, w->property.at(&w->property, index)).asReturnedValue();
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
void QmlListWrapper::put(Managed *m, String *name, const Value &value)
QVariant toVariant() const;
static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
- static Value getIndexed(Managed *m, uint index, bool *hasProperty);
+ static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
static Property *advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes);
static void destroy(Managed *that);
Q_ASSERT(id >= firstVarPropertyIndex);
if (ensureVarPropertiesAllocated())
- return varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex);
+ return QV4::Value::fromReturnedValue(varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex));
return QV4::Value::emptyValue();
}
if (id >= firstVarPropertyIndex) {
if (ensureVarPropertiesAllocated())
return QQmlEnginePrivate::get(ctxt->engine)->v8engine()->toVariant(
- varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex), -1);
+ QV4::Value::fromReturnedValue(varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex)), -1);
return QVariant();
} else {
if (data[id].dataType() == QMetaType::QObjectStar) {
if (!ensureVarPropertiesAllocated())
return;
+ QV4::Scope scope(varProperties.engine());
// Importantly, if the current value is a scarce resource, we need to ensure that it
// gets automatically released by the engine if no other references to it exist.
- QV4::Value oldv = varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex);
- if (QV4::VariantObject *v = oldv.as<QV4::VariantObject>())
- v->removeVmePropertyReference();
+ QV4::Scoped<QV4::VariantObject> oldv(scope, varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex));
+ if (!!oldv)
+ oldv->removeVmePropertyReference();
QObject *valueObject = 0;
QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id);
if (!ensureVarPropertiesAllocated())
return;
+ QV4::Scope scope(varProperties.engine());
+
// Importantly, if the current value is a scarce resource, we need to ensure that it
// gets automatically released by the engine if no other references to it exist.
- QV4::Value oldv = varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex);
- if (QV4::VariantObject *v = oldv.as<QV4::VariantObject>())
- v->removeVmePropertyReference();
+ QV4::Scoped<QV4::VariantObject> oldv(scope, varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex));
+ if (!!oldv)
+ oldv->removeVmePropertyReference();
// And, if the new value is a scarce resource, we need to ensure that it does not get
// automatically released by the engine until no other references to it exist.
that->as<NamedNodeMap>()->~NamedNodeMap();
}
static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
- static Value getIndexed(Managed *m, uint index, bool *hasProperty);
+ static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
QList<NodeImpl *> list; // Only used in NamedNodeMap
NodeImpl *d;
that->as<NodeList>()->~NodeList();
}
static ReturnedValue get(Managed *m, String *name, bool *hasProperty);
- static Value getIndexed(Managed *m, uint index, bool *hasProperty);
+ static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
// C++ API
static Value create(QV8Engine *, NodeImpl *);
return d == 0;
}
-Value NamedNodeMap::getIndexed(Managed *m, uint index, bool *hasProperty)
+ReturnedValue NamedNodeMap::getIndexed(Managed *m, uint index, bool *hasProperty)
{
QV4::ExecutionEngine *v4 = m->engine();
NamedNodeMap *r = m->as<NamedNodeMap>();
if ((int)index < r->list.count()) {
if (hasProperty)
*hasProperty = true;
- return Node::create(engine, r->list.at(index));
+ return Node::create(engine, r->list.at(index)).asReturnedValue();
}
if (hasProperty)
*hasProperty = false;
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
ReturnedValue NamedNodeMap::get(Managed *m, String *name, bool *hasProperty)
return Value::fromObject(instance);
}
-Value NodeList::getIndexed(Managed *m, uint index, bool *hasProperty)
+ReturnedValue NodeList::getIndexed(Managed *m, uint index, bool *hasProperty)
{
QV4::ExecutionEngine *v4 = m->engine();
NodeList *r = m->as<NodeList>();
if ((int)index < r->d->children.count()) {
if (hasProperty)
*hasProperty = true;
- return Node::create(engine, r->d->children.at(index));
+ return Node::create(engine, r->d->children.at(index)).asReturnedValue();
}
if (hasProperty)
*hasProperty = false;
- return Value::undefinedValue();
+ return Value::undefinedValue().asReturnedValue();
}
ReturnedValue NodeList::get(Managed *m, String *name, bool *hasProperty)
}
if (QV4::ArrayObject *a = value.asArrayObject()) {
+ QV4::Scope scope(a->engine());
if (typeHint == qMetaTypeId<QList<QObject *> >()) {
QList<QObject *> list;
uint32_t length = a->arrayLength();
+ QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope);
for (uint32_t ii = 0; ii < length; ++ii) {
- QV4::Value arrayItem = a->getIndexed(ii);
- if (QV4::QObjectWrapper *qobjectWrapper = arrayItem.as<QV4::QObjectWrapper>()) {
+ qobjectWrapper = a->getIndexed(ii);
+ if (!!qobjectWrapper) {
list << qobjectWrapper->object();
} else {
list << 0;
if (QV4::RegExpObject *re = value.as<QV4::RegExpObject>())
return re->toQRegExp();
if (QV4::ArrayObject *a = value.asArrayObject()) {
+ QV4::Scope scope(a->engine());
+ QV4::ScopedValue v(scope);
QVariantList rv;
int length = a->arrayLength();
- for (int ii = 0; ii < length; ++ii)
- rv << toVariant(a->getIndexed(ii), -1);
+ for (int ii = 0; ii < length; ++ii) {
+ v = a->getIndexed(ii);
+ rv << toVariant(v, -1);
+ }
return rv;
}
if (!value.asFunctionObject())
visitedObjects.insert(a);
+ QV4::Scope scope(a->engine());
+ QV4::ScopedValue v(scope);
+
quint32 length = a->arrayLength();
for (quint32 i = 0; i < length; ++i) {
- QV4::Value v = a->getIndexed(i);
+ v = a->getIndexed(i);
result.append(variantFromJS(v, visitedObjects));
}
if (index != -1)
groupFlags |= 2 << index;
} else if (QV4::ArrayObject *array = groups.asArrayObject()) {
+ QV4::Scope scope(array->engine());
+ QV4::ScopedValue v(scope);
uint arrayLength = array->arrayLength();
for (uint i = 0; i < arrayLength; ++i) {
- const QString groupName = array->getIndexed(i).toQStringNoThrow();
+ v = array->getIndexed(i);
+ const QString groupName = v->toQStringNoThrow();
int index = groupNames.indexOf(groupName);
if (index != -1)
groupFlags |= 2 << index;
virtual quint32 count() const = 0;
virtual const QQmlChangeSet::Change &at(int index) const = 0;
- static QV4::Value getIndexed(QV4::Managed *m, uint index, bool *hasProperty)
+ static QV4::ReturnedValue getIndexed(QV4::Managed *m, uint index, bool *hasProperty)
{
QV4::ExecutionEngine *v4 = m->engine();
QQmlDelegateModelGroupChangeArray *array = m->as<QQmlDelegateModelGroupChangeArray>();
if (index >= array->count()) {
if (hasProperty)
*hasProperty = false;
- return QV4::Value::undefinedValue();
+ return QV4::Value::undefinedValue().asReturnedValue();
}
const QQmlChangeSet::Change &change = array->at(index);
if (hasProperty)
*hasProperty = true;
- return QV4::Value::fromObject(object);
+ return QV4::Value::fromObject(object).asReturnedValue();
}
static QV4::ReturnedValue get(QV4::Managed *m, QV4::String *name, bool *hasProperty)
ListElement *e = elements[elementIndex];
QV4::ExecutionEngine *v4 = object->engine();
+ QV4::Scope scope(v4);
+ QV4::Scoped<QV4::Object> o(scope);
+
QV4::ObjectIterator it(object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly);
while (1) {
QV4::Value propertyValue;
int arrayLength = a->arrayLength();
for (int j=0 ; j < arrayLength ; ++j) {
- QV4::Object *subObject = a->getIndexed(j).asObject();
- subModel->append(subObject, eng);
+ o = a->getIndexed(j);
+ subModel->append(o.getPointer(), eng);
}
roleIndex = e->setListProperty(r, subModel);
ListElement *e = elements[elementIndex];
QV4::ExecutionEngine *v4 = object->engine();
+ QV4::Scope scope(v4);
+ QV4::Scoped<QV4::Object> o(scope);
+
QV4::ObjectIterator it(object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly);
while (1) {
QV4::Value propertyValue;
int arrayLength = a->arrayLength();
for (int j=0 ; j < arrayLength ; ++j) {
- QV4::Object *subObject = a->getIndexed(j).asObject();
- subModel->append(subObject, eng);
+ o = a->getIndexed(j);
+ subModel->append(o.getPointer(), eng);
}
e->setListPropertyFast(r, subModel);
roleIndex = setDoubleProperty(role, d.asDouble());
} else if (QV4::ArrayObject *a = d.asArrayObject()) {
if (role.type == ListLayout::Role::List) {
+ QV4::Scope scope(a->engine());
+ QV4::Scoped<QV4::Object> o(scope);
+
ListModel *subModel = new ListModel(role.subLayout, 0, -1);
int arrayLength = a->arrayLength();
for (int j=0 ; j < arrayLength ; ++j) {
- QV4::Object *subObject = a->getIndexed(j).asObject();
- subModel->append(subObject, eng);
+ o = a->getIndexed(j);
+ subModel->append(o.getPointer(), eng);
}
roleIndex = setListProperty(role, subModel);
} else {
QV4::Value arg1 = (*args)[1];
if (QV4::ArrayObject *objectArray = arg1.asArrayObject()) {
+ QV4::Scope scope(objectArray->engine());
+ QV4::Scoped<QV4::Object> argObject(scope);
+
int objectArrayLength = objectArray->arrayLength();
for (int i=0 ; i < objectArrayLength ; ++i) {
- QV4::Object *argObject = objectArray->getIndexed(i).asObject();
+ argObject = objectArray->getIndexed(i);
if (m_dynamicRoles) {
- m_modelObjects.insert(index+i, DynamicRoleModelNode::create(args->engine()->variantMapFromJS(argObject), this));
+ m_modelObjects.insert(index+i, DynamicRoleModelNode::create(args->engine()->variantMapFromJS(argObject.getPointer()), this));
} else {
- m_listModel->insert(index+i, argObject, args->engine());
+ m_listModel->insert(index+i, argObject.getPointer(), args->engine());
}
}
emitItemsInserted(index, objectArrayLength);
QV4::Value arg = (*args)[0];
if (QV4::ArrayObject *objectArray = arg.asArrayObject()) {
+ QV4::Scope scope(objectArray->engine());
+ QV4::Scoped<QV4::Object> argObject(scope);
+
int objectArrayLength = objectArray->arrayLength();
int index = count();
for (int i=0 ; i < objectArrayLength ; ++i) {
- QV4::Object *argObject = objectArray->getIndexed(i).asObject();
+ argObject = objectArray->getIndexed(i);
if (m_dynamicRoles) {
- m_modelObjects.append(DynamicRoleModelNode::create(args->engine()->variantMapFromJS(argObject), this));
+ m_modelObjects.append(DynamicRoleModelNode::create(args->engine()->variantMapFromJS(argObject.getPointer()), this));
} else {
- m_listModel->append(argObject, args->engine());
+ m_listModel->append(argObject.getPointer(), args->engine());
}
}
static void destroy(QV4::Managed *that) {
static_cast<QQuickJSContext2DPixelData *>(that)->~QQuickJSContext2DPixelData();
}
- static QV4::Value getIndexed(QV4::Managed *m, uint index, bool *hasProperty);
+ static QV4::ReturnedValue getIndexed(QV4::Managed *m, uint index, bool *hasProperty);
static void putIndexed(QV4::Managed *m, uint index, const QV4::Value &value);
static QV4::Value proto_get_length(QV4::SimpleCallContext *ctx);
return QV4::Value::fromInt32(r->image.width() * r->image.height() * 4);
}
-QV4::Value QQuickJSContext2DPixelData::getIndexed(QV4::Managed *m, uint index, bool *hasProperty)
+QV4::ReturnedValue QQuickJSContext2DPixelData::getIndexed(QV4::Managed *m, uint index, bool *hasProperty)
{
QQuickJSContext2DPixelData *r = m->as<QQuickJSContext2DPixelData>();
if (!m)
pixel += col;
switch (index % 4) {
case 0:
- return QV4::Value::fromInt32(qRed(*pixel));
+ return QV4::Value::fromInt32(qRed(*pixel)).asReturnedValue();
case 1:
- return QV4::Value::fromInt32(qGreen(*pixel));
+ return QV4::Value::fromInt32(qGreen(*pixel)).asReturnedValue();
case 2:
- return QV4::Value::fromInt32(qBlue(*pixel));
+ return QV4::Value::fromInt32(qBlue(*pixel)).asReturnedValue();
case 3:
- return QV4::Value::fromInt32(qAlpha(*pixel));
+ return QV4::Value::fromInt32(qAlpha(*pixel)).asReturnedValue();
}
}
if (hasProperty)
*hasProperty = false;
- return QV4::Value::undefinedValue();
+ return QV4::Value::undefinedValue().asReturnedValue();
}
void QQuickJSContext2DPixelData::putIndexed(QV4::Managed *m, uint index, const QV4::Value &value)
if (!array)
return QMatrix4x4();
+ QV4::Scope scope(array->engine());
+
if (array->arrayLength() != 16)
return QMatrix4x4();
float matVals[16];
+ QV4::ScopedValue v(scope);
for (quint32 i = 0; i < 16; ++i) {
- QV4::Value v = array->getIndexed(i);
- if (!v.isNumber())
+ v = array->getIndexed(i);
+ if (!v->isNumber())
return QMatrix4x4();
- matVals[i] = v.asDouble();
+ matVals[i] = v->asDouble();
}
if (ok) *ok = true;