// allow assignment of "special" values (null, undefined, function) to var properties
QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(object);
Q_ASSERT(vmemo);
- vmemo->setVMEProperty(result->coreIndex, *value);
+ vmemo->setVMEProperty(result->coreIndex, value);
return true;
}
} else if (result->isVarProperty()) {
QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(object);
Q_ASSERT(vmemo);
- vmemo->setVMEProperty(result->coreIndex, *value);
+ vmemo->setVMEProperty(result->coreIndex, value);
} else {
QVariant v;
if (result->isQList())
ptr->argc = argc;
#ifndef QT_NO_DEBUG
scope.size += size;
+ for (int ii = 0; ii < qMax(argc, (int)QV4::Global::ReservedArgumentCount); ++ii)
+ ptr->args[ii] = QV4::Primitive::undefinedValue();
#endif
}
int *argsTypes = QQmlPropertyCache::methodParameterTypes(m_target, methodIndex, dummy, 0);
int argCount = argsTypes ? *argsTypes : 0;
- QV4::Value *args = (QV4::Value *)alloca(qMax(argCount, (int)QV4::Global::ReservedArgumentCount)*sizeof(QV4::Value));
-#ifndef QT_NO_DEBUG
- for (int ii = 0; ii < qMax(argCount, (int)QV4::Global::ReservedArgumentCount); ++ii)
- args[ii] = QV4::Primitive::undefinedValue();
-#endif
+ QV4::ScopedValue f(scope, m_v8function.value());
+ QV4::ScopedCallData callData(scope, argCount);
for (int ii = 0; ii < argCount; ++ii) {
int type = argsTypes[ii + 1];
//### ideally we would use metaTypeToJS, however it currently gives different results
// for several cases (such as QVariant type and QObject-derived types)
//args[ii] = engine->metaTypeToJS(type, a[ii + 1]);
if (type == QMetaType::QVariant) {
- args[ii] = QV4::Value::fromReturnedValue(engine->fromVariant(*((QVariant *)a[ii + 1])));
+ callData->args[ii] = engine->fromVariant(*((QVariant *)a[ii + 1]));
} else if (type == QMetaType::Int) {
//### optimization. Can go away if we switch to metaTypeToJS, or be expanded otherwise
- args[ii] = QV4::Primitive::fromInt32(*reinterpret_cast<const int*>(a[ii + 1]));
+ callData->args[ii] = QV4::Primitive::fromInt32(*reinterpret_cast<const int*>(a[ii + 1]));
} else if (type == qMetaTypeId<QQmlV4Handle>()) {
- args[ii] = QV4::Value::fromReturnedValue(*reinterpret_cast<QQmlV4Handle *>(a[ii + 1]));
+ callData->args[ii] = *reinterpret_cast<QQmlV4Handle *>(a[ii + 1]);
} else if (ep->isQObject(type)) {
if (!*reinterpret_cast<void* const *>(a[ii + 1]))
- args[ii] = QV4::Primitive::nullValue();
+ callData->args[ii] = QV4::Primitive::nullValue();
else
- args[ii] = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(ep->v4engine(), *reinterpret_cast<QObject* const *>(a[ii + 1])));
+ callData->args[ii] = QV4::QObjectWrapper::wrap(ep->v4engine(), *reinterpret_cast<QObject* const *>(a[ii + 1]));
} else {
- args[ii] = QV4::Value::fromReturnedValue(engine->fromVariant(QVariant(type, a[ii + 1])));
+ callData->args[ii] = engine->fromVariant(QVariant(type, a[ii + 1]));
}
}
- QV4::ScopedValue f(scope, m_v8function.value());
- QQmlJavaScriptExpression::evaluate(context(), f, argCount, args, 0);
+ QQmlJavaScriptExpression::evaluate(context(), f, callData, 0);
}
ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
}
QV8Engine *v8;
QPointer<QObject> parent;
- QV4::Value valuemap;
+ QV4::SafeValue valuemap;
QV4::SafeValue qmlGlobal;
- QV4::Value m_statusChanged;
+ QV4::SafeValue m_statusChanged;
protected:
virtual void statusChanged(Status);
virtual void setInitialState(QObject *);
}
// XXX used by QSGLoader
-void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::Value &valuemap, QObject *toCreate)
+void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::ValueRef valuemap, QObject *toCreate)
{
QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
QV8Engine *v8engine = ep->v8engine();
QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate));
Q_ASSERT(object->asObject());
- if (!valuemap.isUndefined()) {
+ if (!valuemap->isUndefined()) {
QQmlComponentExtension *e = componentExtension(v8engine);
QV4::ScopedObject qmlGlobalObj(scope, qmlGlobal);
QV4::Scoped<QV4::FunctionObject> f(scope, QV4::Script::evaluate(QV8Engine::getV4(v8engine),
QV4::Scoped<QV4::FunctionObject> f(scope, QV4::Script::evaluate(v4, QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlGlobal));
QV4::ScopedCallData callData(scope, 2);
callData->thisObject = v4->globalObject;
- callData->args[0] = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(v4, o));
+ callData->args[0] = QV4::QObjectWrapper::wrap(v4, o);
callData->args[1] = valuemap;
f->call(callData);
}
QQmlData::get(object())->indestructible = false;
}
- QV4::Value callback = m_statusChanged;
-
- if (QV4::FunctionObject *f = callback.asFunctionObject()) {
- QV4::ExecutionContext *ctx = f->engine()->current;
- QV4::Scope scope(ctx);
+ QV4::Scope scope(QV8Engine::getV4(v8));
+ QV4::ScopedFunctionObject f(scope, m_statusChanged);
+ if (f) {
+ QV4::ExecutionContext *ctx = scope.engine->current;
try {
QV4::ScopedCallData callData(scope, 1);
callData->thisObject = this;
QObject *beginCreate(QQmlContextData *);
void completeCreate();
- void initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::Value &valuemap, QObject *toCreate);
+ void initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::ValueRef valuemap, QObject *toCreate);
QQmlTypeData *typeData;
virtual void typeDataReady(QQmlTypeData *);
return !!c ? c->getContext() : 0;
}
-QQmlContextData *QmlContextWrapper::getContext(const Value &value)
+QQmlContextData *QmlContextWrapper::getContext(const ValueRef value)
{
- QV4::ExecutionEngine *v4 = value.engine();
+ QV4::ExecutionEngine *v4 = value->engine();
if (!v4)
return 0;
Scope scope(v4);
- QV4::Scoped<QmlContextWrapper> c(scope, value.as<QmlContextWrapper>());
+ QV4::Scoped<QmlContextWrapper> c(scope, value);
- return !!c ? c->getContext():0;
+ return c ? c->getContext() : 0;
}
-void QmlContextWrapper::takeContextOwnership(const Value &qmlglobal)
+void QmlContextWrapper::takeContextOwnership(const ValueRef qmlglobal)
{
- Object *o = qmlglobal.asObject();
- QmlContextWrapper *c = o ? o->as<QmlContextWrapper>() : 0;
- assert(c);
+ QV4::ExecutionEngine *v4 = qmlglobal->engine();
+ Q_ASSERT(v4);
+
+ Scope scope(v4);
+ QV4::Scoped<QmlContextWrapper> c(scope, qmlglobal);
+ Q_ASSERT(c);
c->ownsContext = true;
}
static ReturnedValue urlScope(QV8Engine *e, const QUrl &);
static QQmlContextData *callingContext(ExecutionEngine *v4);
- static void takeContextOwnership(const QV4::Value &qmlglobal);
+ static void takeContextOwnership(const ValueRef qmlglobal);
inline QObject *getScopeObject() const { return scopeObject; }
inline QQmlContextData *getContext() const { return context; }
- static QQmlContextData *getContext(const Value &value);
+ static QQmlContextData *getContext(const ValueRef value);
void setReadOnly(bool b) { readOnly = b; }
}
QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context,
- const QV4::Value &function, bool *isUndefined)
+ const QV4::ValueRef function, bool *isUndefined)
{
- return evaluate(context, function, 0, 0, isUndefined);
+ QV4::ExecutionEngine *v4 = QV8Engine::getV4(context->engine);
+ QV4::Scope scope(v4);
+ QV4::ScopedCallData callData(scope, 0);
+
+ return evaluate(context, function, callData, isUndefined);
}
QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context,
- const QV4::Value &function,
- int argc, QV4::Value *args,
+ const QV4::ValueRef function,
+ QV4::CallData *callData,
bool *isUndefined)
{
Q_ASSERT(context && context->engine);
- if (function.isUndefined()) {
+ if (function->isUndefined()) {
if (isUndefined)
*isUndefined = true;
- return QV4::Primitive::undefinedValue().asReturnedValue();
+ return QV4::Encode::undefined();
}
QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context->engine);
QV4::ScopedValue result(scope, QV4::Primitive::undefinedValue());
QV4::ExecutionContext *ctx = v4->current;
try {
- QV4::ScopedCallData callData(scope, argc);
callData->thisObject = ep->v8engine()->global();
if (scopeObject() && requiresThisObject()) {
QV4::ScopedValue value(scope, QV4::QObjectWrapper::wrap(ctx->engine, scopeObject()));
callData->thisObject = value;
}
- memcpy(callData->args, args, argc*sizeof(QV4::Value));
- result = function.asFunctionObject()->call(callData);
+ result = function->asFunctionObject()->call(callData);
if (isUndefined)
*isUndefined = result->isUndefined();
QQmlJavaScriptExpression(VTable *vtable);
- QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::Value &function,
- bool *isUndefined);
- QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::Value &function,
- int argc, QV4::Value *args,
- bool *isUndefined);
+ QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::ValueRef function, bool *isUndefined);
+ QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::ValueRef function, QV4::CallData *callData, bool *isUndefined);
inline bool requiresThisObject() const;
inline void setRequiresThisObject(bool v);
*attrs = QV4::Attr_Data;
*index = it->arrayIndex;
++it->arrayIndex;
- it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(w->engine(), w->property.at(&w->property, *index)));
+ it->tmpDynamicProperty.value = QV4::QObjectWrapper::wrap(w->engine(), w->property.at(&w->property, *index));
return &it->tmpDynamicProperty;
}
return QV4::Object::advanceIterator(m, it, name, index, attrs);
if (!r) \
V4THROW_ERROR("Not a valid Locale object")
-static bool isLocaleObject(const QV4::Value &val)
+static bool isLocaleObject(const QV4::ValueRef val)
{
- return val.as<QQmlLocaleData>();
+ return val->as<QQmlLocaleData>();
}
//--------------
QString stringValue = binding->valueAsString(&qmlUnit->header);
if (property->isVarProperty()) {
QV4::ScopedString s(scope, v4->newString(stringValue));
- _vmeMetaObject->setVMEProperty(property->coreIndex, s.asValue());
+ _vmeMetaObject->setVMEProperty(property->coreIndex, s);
} else {
QVariant value = QQmlStringConverters::variantFromString(stringValue);
argv[0] = &value;
QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(object);
Q_ASSERT(vmemo);
- vmemo->setVMEProperty(core.coreIndex, *result);
+ vmemo->setVMEProperty(core.coreIndex, result);
} else if (isUndefined && core.isResettable()) {
void *args[] = { 0 };
QMetaObject::metacall(object, QMetaObject::ResetProperty, core.coreIndex, args);
#define QML_STORE_VAR(name, value) \
QML_BEGIN_INSTR(name) \
- QV4::Value v4value = value; \
+ QV4::ValueRef valueref = value; \
QObject *target = objects.top(); \
CLEAN_PROPERTY(target, instr.propertyIndex); \
QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(target); \
Q_ASSERT(vmemo); \
- vmemo->setVMEProperty(instr.propertyIndex, v4value); \
+ vmemo->setVMEProperty(instr.propertyIndex, valueref); \
QML_END_INSTR(name)
#define QML_STORE_POINTER(name, value) \
QQmlEngine *engine = states.at(0).context->engine;
QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
+ QV4::ExecutionEngine *v4 = ep->v4engine();
+ QV4::Scope valueScope(v4);
+ QV4::ScopedValue tmpValue(valueScope);
int status = -1; // needed for dbus
QQmlPropertyPrivate::WriteFlags flags = QQmlPropertyPrivate::BypassInterceptor |
// Store a created object in a property. These all pop from the objects stack.
QML_STORE_VALUE(StoreObject, QObject *, objects.pop());
QML_STORE_VALUE(StoreVariantObject, QVariant, QVariant::fromValue(objects.pop()));
- QML_STORE_VAR(StoreVarObject, QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(ep->v4engine(), objects.pop())));
+ QML_STORE_VAR(StoreVarObject, (tmpValue = QV4::QObjectWrapper::wrap(ep->v4engine(), objects.pop())));
// Store a literal value in a corresponding property
QML_STORE_VALUE(StoreFloat, float, instr.value);
// Store a literal value in a var property.
// We deliberately do not use string converters here
- QML_STORE_VAR(StoreVar, QV4::Value::fromReturnedValue(ep->v8engine()->fromVariant(PRIMITIVES.at(instr.value))));
+ QML_STORE_VAR(StoreVar, (tmpValue = ep->v8engine()->fromVariant(PRIMITIVES.at(instr.value))));
QML_STORE_VAR(StoreVarInteger, QV4::Primitive::fromInt32(instr.value));
QML_STORE_VAR(StoreVarDouble, QV4::Primitive::fromDouble(instr.value));
QML_STORE_VAR(StoreVarBool, QV4::Primitive::fromBoolean(instr.value));
callData->thisObject = ep->v8engine()->global();
for (int ii = 0; ii < data->parameterCount; ++ii)
- callData->args[ii] = QV4::Value::fromReturnedValue(ep->v8engine()->fromVariant(*(QVariant *)a[ii + 1]));
+ callData->args[ii] = ep->v8engine()->fromVariant(*(QVariant *)a[ii + 1]);
QV4::ScopedValue result(scope);
QV4::ExecutionContext *ctx = function->engine()->current;
}
}
-void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value)
+void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::ValueRef value)
{
Q_ASSERT(id >= firstVarPropertyIndex);
if (!ensureVarPropertiesAllocated())
QObject *valueObject = 0;
QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id);
- QV4::ScopedValue v(scope, value);
- QV4::ScopedObject o(scope, v);
+ QV4::ScopedObject o(scope, value);
if (o) {
// 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.
}
// Write the value and emit change signal as appropriate.
- vp->putIndexed(id - firstVarPropertyIndex, v);
+ vp->putIndexed(id - firstVarPropertyIndex, value);
activate(object, methodOffset() + id, 0);
}
return readVarProperty(index - propOffset());
}
-void QQmlVMEMetaObject::setVMEProperty(int index, const QV4::Value &v)
+void QQmlVMEMetaObject::setVMEProperty(int index, const QV4::ValueRef v)
{
if (index < propOffset()) {
Q_ASSERT(parentVMEMetaObject());
quint16 vmeMethodLineNumber(int index);
void setVmeMethod(int index, QV4::ValueRef function);
QV4::ReturnedValue vmeProperty(int index);
- void setVMEProperty(int index, const QV4::Value &v);
+ void setVMEProperty(int index, const QV4::ValueRef v);
void connectAliasSignal(int index, bool indexInSignalRange);
QV4::ReturnedValue method(int);
QV4::ReturnedValue readVarProperty(int);
- void writeVarProperty(int, const QV4::Value &);
+ void writeVarProperty(int, const QV4::ValueRef);
QVariant readPropertyAsVariant(int);
void writeProperty(int, const QVariant &);
return (QQmlXMLHttpRequestData *)engine->xmlHttpRequestData();
}
-static ReturnedValue constructMeObject(const Value &thisObj, QV8Engine *e)
+static ReturnedValue constructMeObject(const ValueRef thisObj, QV8Engine *e)
{
ExecutionEngine *v4 = QV8Engine::getV4(e);
Scope scope(v4);
Scoped<Object> meObj(scope, v4->newObject());
- meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ThisObject"))), ScopedValue(scope, thisObj));
+ meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ThisObject"))), thisObj);
ScopedValue v(scope, QmlContextWrapper::qmlScope(e, e->callingContext(), 0));
meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ActivationObject"))), v);
return meObj.asReturnedValue();
if (!activationObject)
v4->current->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ActivationObject"));
- QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject.asValue());
+ QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject);
if (callingContext) {
QV4::ScopedCallData callData(scope, 0);
callData->thisObject = activationObject.asValue();
*/
ReturnedValue QtObject::method_createComponent(SimpleCallContext *ctx)
{
- const QString invalidArgs = QStringLiteral("Qt.createComponent(): Invalid arguments");
- const QString invalidParent = QStringLiteral("Qt.createComponent(): Invalid parent object");
if (ctx->callData->argc < 1 || ctx->callData->argc > 3)
- ctx->throwError(invalidArgs);
+ ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments"));
+
+ Scope scope(ctx);
QV8Engine *v8engine = ctx->engine->v8Engine;
QQmlEngine *engine = v8engine->engine();
int consumedCount = 1;
if (ctx->callData->argc > 1) {
- Value lastArg = ctx->callData->args[ctx->callData->argc-1];
+ ScopedValue lastArg(scope, ctx->callData->args[ctx->callData->argc-1]);
// The second argument could be the mode enum
if (ctx->callData->args[1].isInteger()) {
int mode = ctx->callData->args[1].integerValue();
if (mode != int(QQmlComponent::PreferSynchronous) && mode != int(QQmlComponent::Asynchronous))
- ctx->throwError(invalidArgs);
+ ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments"));
compileMode = QQmlComponent::CompilationMode(mode);
consumedCount += 1;
} else {
// The second argument could be the parent only if there are exactly two args
- if ((ctx->callData->argc != 2) || !(lastArg.isObject() || lastArg.isNull()))
- ctx->throwError(invalidArgs);
+ if ((ctx->callData->argc != 2) || !(lastArg->isObject() || lastArg->isNull()))
+ ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments"));
}
if (consumedCount < ctx->callData->argc) {
- if (lastArg.isObject()) {
- if (QV4::QObjectWrapper *qobjectWrapper = lastArg.as<QV4::QObjectWrapper>())
+ if (lastArg->isObject()) {
+ Scoped<QObjectWrapper> qobjectWrapper(scope, lastArg);
+ if (qobjectWrapper)
parentArg = qobjectWrapper->object();
if (!parentArg)
- ctx->throwError(invalidParent);
- } else if (lastArg.isNull()) {
+ ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object"));
+ } else if (lastArg->isNull()) {
parentArg = 0;
} else {
- ctx->throwError(invalidParent);
+ ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object"));
}
}
}
if (i != 0)
result.append(QLatin1Char(' '));
- QV4::Value value = ctx->callData->args[i];
- if (value.asArrayObject())
- result.append(QStringLiteral("[") + value.toQStringNoThrow() + QStringLiteral("]"));
+ if (ctx->callData->args[i].asArrayObject())
+ result.append(QStringLiteral("[") + ctx->callData->args[i].toQStringNoThrow() + QStringLiteral("]"));
else
- result.append(value.toQStringNoThrow());
+ result.append(ctx->callData->args[i].toQStringNoThrow());
}
if (printStack) {
ReturnedValue GlobalExtensions::method_string_arg(SimpleCallContext *ctx)
{
- QString value = ctx->callData->thisObject.toQStringNoThrow();
if (ctx->callData->argc != 1)
V4THROW_ERROR("String.arg(): Invalid arguments");
- QV4::Value arg = ctx->callData->args[0];
- if (arg.isInteger())
- return ctx->engine->newString(value.arg(arg.integerValue()))->asReturnedValue();
- else if (arg.isDouble())
- return ctx->engine->newString(value.arg(arg.doubleValue()))->asReturnedValue();
- else if (arg.isBoolean())
- return ctx->engine->newString(value.arg(arg.booleanValue()))->asReturnedValue();
+ QString value = ctx->callData->thisObject.toQString();
+
+ QV4::Scope scope(ctx);
+ QV4::ScopedValue arg(scope, ctx->callData->args[0]);
+ if (arg->isInteger())
+ return ctx->engine->newString(value.arg(arg->integerValue()))->asReturnedValue();
+ else if (arg->isDouble())
+ return ctx->engine->newString(value.arg(arg->doubleValue()))->asReturnedValue();
+ else if (arg->isBoolean())
+ return ctx->engine->newString(value.arg(arg->booleanValue()))->asReturnedValue();
- return ctx->engine->newString(value.arg(arg.toQStringNoThrow()))->asReturnedValue();
+ return ctx->engine->newString(value.arg(arg->toQString()))->asReturnedValue();
}
int len = list.count();
a->arrayReserve(len);
for (int ii = 0; ii < len; ++ii) {
- a->arrayData[ii].value = QV4::Value::fromReturnedValue(engine->fromVariant(list.at(ii)));
+ a->arrayData[ii].value = engine->fromVariant(list.at(ii));
a->arrayDataLen = ii + 1;
}
a->setArrayLengthUnchecked(len);
QV4::Scoped<QV4::ArrayObject> a(scope, m_v4Engine->newArrayObject());
a->arrayReserve(list.count());
for (int ii = 0; ii < list.count(); ++ii) {
- a->arrayData[ii].value = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(m_v4Engine, list.at(ii)));
+ a->arrayData[ii].value = QV4::QObjectWrapper::wrap(m_v4Engine, list.at(ii));
a->arrayDataLen = ii + 1;
}
a->setArrayLengthUnchecked(list.count());
QV4::ScopedFunctionObject f(scope, m_freezeObject.value());
QV4::ScopedCallData callData(scope, 1);
callData->args[0] = value;
- callData->thisObject = QV4::Value::fromObject(m_v4Engine->globalObject);
+ callData->thisObject = m_v4Engine->globalObject;
f->call(callData);
}
QV4::Scoped<QV4::ArrayObject> a(scope, m_v4Engine->newArrayObject());
a->arrayReserve(lst.size());
for (int i = 0; i < lst.size(); i++) {
- a->arrayData[i].value = QV4::Value::fromReturnedValue(variantToJS(lst.at(i)));
+ a->arrayData[i].value = variantToJS(lst.at(i));
a->arrayDataLen = i + 1;
}
a->setArrayLengthUnchecked(lst.size());
for (it = vmap.constBegin(); it != vmap.constEnd(); ++it) {
s = m_v4Engine->newIdentifier(it.key());
QV4::Property *p = o->insertMember(s, QV4::Attr_Data);
- p->value = QV4::Value::fromReturnedValue(variantToJS(it.value()));
+ p->value = variantToJS(it.value());
}
return o.asReturnedValue();
}
{
Q_MANAGED
- QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg);
+ QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::ValueRef arg);
uint flag;
- DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg))
+ DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::ValueRef arg))
: FunctionObject(scope, /*name*/0)
, code(code)
, flag(flag)
QQmlDelegateModelEngineData(QV8Engine *engine);
~QQmlDelegateModelEngineData();
- QV4::Value array(QV8Engine *engine, const QVector<QQmlChangeSet::Remove> &changes);
- QV4::Value array(QV8Engine *engine, const QVector<QQmlChangeSet::Insert> &changes);
+ QV4::ReturnedValue array(QV8Engine *engine, const QVector<QQmlChangeSet::Remove> &changes);
+ QV4::ReturnedValue array(QV8Engine *engine, const QVector<QQmlChangeSet::Insert> &changes);
QV4::PersistentValue changeProto;
};
return new QQmlDelegateModelAttached(obj);
}
-bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups)
+bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const QV4::ValueRef object, int groups)
{
if (!m_context->isValid())
return false;
QQmlDelegateModelItem *cacheItem = m_adaptorModel.createItem(m_cacheMetaType, m_context->engine(), -1);
if (!cacheItem)
return false;
- QV4::Object *o = object.asObject();
- if (!o)
+ QV4::ExecutionEngine *v4 = object->engine();
+ if (!v4)
return false;
- QV4::Scope scope(o->engine());
+ QV4::Scope scope(v4);
+ QV4::ScopedObject o(scope, object);
+ if (!o)
+ return false;
- QV4::ObjectIterator it(o, QV4::ObjectIterator::EnumerableOnly|QV4::ObjectIterator::WithProtoChain);
+ QV4::ObjectIterator it(o.getPointer(), QV4::ObjectIterator::EnumerableOnly|QV4::ObjectIterator::WithProtoChain);
QV4::ScopedValue propertyName(scope);
while (1) {
QV4::Value value;
return groupFlags;
}
-int QQmlDelegateModelItemMetaType::parseGroups(const QV4::Value &groups) const
+int QQmlDelegateModelItemMetaType::parseGroups(const QV4::ValueRef groups) const
{
int groupFlags = 0;
- if (QV4::String *s = groups.asString()) {
+ QV4::Scope scope(QV8Engine::getV4(v8Engine));
+
+ QV4::ScopedString s(scope, groups);
+ if (s) {
const QString groupName = s->toQString();
int index = groupNames.indexOf(groupName);
if (index != -1)
groupFlags |= 2 << index;
- } else if (QV4::ArrayObject *array = groups.asArrayObject()) {
- QV4::Scope scope(array->engine());
+ return groupFlags;
+ }
+
+ QV4::ScopedArrayObject array(scope, groups);
+ if (array) {
QV4::ScopedValue v(scope);
uint arrayLength = array->arrayLength();
for (uint i = 0; i < arrayLength; ++i) {
v = array->getIndexed(i);
- const QString groupName = v->toQStringNoThrow();
+ const QString groupName = v->toQString();
int index = groupNames.indexOf(groupName);
if (index != -1)
groupFlags |= 2 << index;
return QV4::Encode::undefined();
}
-QV4::ReturnedValue QQmlDelegateModelItem::get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &)
+QV4::ReturnedValue QQmlDelegateModelItem::get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef)
{
return QV4::Encode(bool(thisItem->groups & (1 << flag)));
}
-QV4::ReturnedValue QQmlDelegateModelItem::set_member(QQmlDelegateModelItem *cacheItem, uint flag, const QV4::Value &arg)
+QV4::ReturnedValue QQmlDelegateModelItem::set_member(QQmlDelegateModelItem *cacheItem, uint flag, const QV4::ValueRef arg)
{
if (!cacheItem->metaType->model)
return QV4::Encode::undefined();
QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(cacheItem->metaType->model);
- bool member = arg.toBoolean();
+ bool member = arg->toBoolean();
uint groupFlag = (1 << flag);
if (member == ((cacheItem->groups & groupFlag) != 0))
return QV4::Encode::undefined();
return QV4::Encode::undefined();
}
-QV4::ReturnedValue QQmlDelegateModelItem::get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &)
+QV4::ReturnedValue QQmlDelegateModelItem::get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef)
{
return QV4::Encode((int)thisItem->groupIndex(Compositor::Group(flag)));
}
return QQmlV4Handle(o);
}
-bool QQmlDelegateModelGroupPrivate::parseIndex(const QV4::Value &value, int *index, Compositor::Group *group) const
+bool QQmlDelegateModelGroupPrivate::parseIndex(const QV4::ValueRef value, int *index, Compositor::Group *group) const
{
- if (value.isNumber()) {
- *index = value.toInt32();
+ if (value->isNumber()) {
+ *index = value->toInt32();
return true;
- } else if (QQmlDelegateModelItemObject *object = value.as<QQmlDelegateModelItemObject>()) {
+ }
+
+ QV4::ExecutionEngine *v4 = value->engine();
+ if (!v4)
+ return false;
+
+ QV4::Scope scope(v4);
+ QV4::Scoped<QQmlDelegateModelItemObject> object(scope, value);
+
+ if (object) {
QQmlDelegateModelItem * const cacheItem = object->item;
if (QQmlDelegateModelPrivate *model = cacheItem->metaType->model
? QQmlDelegateModelPrivate::get(cacheItem->metaType->model)
{
}
-QV4::Value QQmlDelegateModelEngineData::array(
- QV8Engine *engine, const QVector<QQmlChangeSet::Remove> &changes)
+QV4::ReturnedValue QQmlDelegateModelEngineData::array(QV8Engine *engine, const QVector<QQmlChangeSet::Remove> &changes)
{
QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
- QV4::Object *array = new (v4->memoryManager) QQmlDelegateModelGroupRemoveArray(v4, changes);
- return QV4::Value::fromObject(array);
+ return (new (v4->memoryManager) QQmlDelegateModelGroupRemoveArray(v4, changes))->asReturnedValue();
}
-QV4::Value QQmlDelegateModelEngineData::array(
- QV8Engine *engine, const QVector<QQmlChangeSet::Insert> &changes)
+QV4::ReturnedValue QQmlDelegateModelEngineData::array(QV8Engine *engine, const QVector<QQmlChangeSet::Insert> &changes)
{
QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
- QV4::Object *array = new (v4->memoryManager) QQmlDelegateModelGroupInsertArray(v4, changes);
- return QV4::Value::fromObject(array);
+ return (new (v4->memoryManager) QQmlDelegateModelGroupInsertArray(v4, changes))->asReturnedValue();
}
QT_END_NAMESPACE
void initializePrototype();
int parseGroups(const QStringList &groupNames) const;
- int parseGroups(const QV4::Value &groupNames) const;
+ int parseGroups(const QV4::ValueRef groupNames) const;
QPointer<QQmlDelegateModel> model;
const int groupCount;
static QV4::ReturnedValue get_model(QV4::SimpleCallContext *ctx);
static QV4::ReturnedValue get_groups(QV4::SimpleCallContext *ctx);
static QV4::ReturnedValue set_groups(QV4::SimpleCallContext *ctx);
- static QV4::ReturnedValue get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &);
- static QV4::ReturnedValue set_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg);
- static QV4::ReturnedValue get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg);
+ static QV4::ReturnedValue get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef);
+ static QV4::ReturnedValue set_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef arg);
+ static QV4::ReturnedValue get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef arg);
QV4::ExecutionEngine *v4;
QQmlDelegateModelItemMetaType * const metaType;
void initPackage(int index, QQuickPackage *package);
void destroyingPackage(QQuickPackage *package);
- bool parseIndex(const QV4::Value &value, int *index, Compositor::Group *group) const;
+ bool parseIndex(const QV4::ValueRef value, int *index, Compositor::Group *group) const;
bool parseGroupArgs(
QQmlV4Function *args, Compositor::Group *group, int *index, int *count, int *groups) const;
void emitChanges();
void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset);
- bool insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups);
+ bool insert(Compositor::insert_iterator &before, const QV4::ValueRef object, int groups);
static void group_append(QQmlListProperty<QQmlDelegateModelGroup> *property, QQmlDelegateModelGroup *group);
static int group_count(QQmlListProperty<QQmlDelegateModelGroup> *property);