QObject *parent = 0;
QV4::Value valuemap = QV4::Value::emptyValue();
- if (args->length() >= 1)
- parent = args->engine()->toQObject((*args)[0]);
+ if (args->length() >= 1) {
+ if (QV4::QObjectWrapper *qobjectWrapper = (*args)[0].as<QV4::QObjectWrapper>())
+ parent = qobjectWrapper->object();
+ }
if (args->length() >= 2) {
QV4::Value v = (*args)[1];
QV4::Value valuemap = QV4::Value::emptyValue();
QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
- if (args->length() >= 1)
- parent = args->engine()->toQObject((*args)[0]);
+ if (args->length() >= 1) {
+ if (QV4::QObjectWrapper *qobjectWrapper = (*args)[0].as<QV4::QObjectWrapper>())
+ parent = qobjectWrapper->object();
+ }
if (args->length() >= 2) {
QV4::Value v = (*args)[1];
v->addVmePropertyReference();
} else if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) {
// We need to track this QObject to signal its deletion
- valueObject = wrapper->object;
+ valueObject = wrapper->object();
// Do we already have a QObject guard for this property?
if (valueObject && !guard) {
QObjectWrapper *qobjectWrapper = weak->value.as<QObjectWrapper>();
if (!qobjectWrapper)
continue;
- QObject *qobject = qobjectWrapper->object;
+ QObject *qobject = qobjectWrapper->object();
if (!qobject)
continue;
bool keepAlive = QQmlData::keepAliveDuringGarbageCollection(qobject);
} else if (QV4::QObjectWrapper *qobjectWrapper = v.as<QV4::QObjectWrapper>()) {
// XXX TODO: Generalize passing objects between the main thread and worker scripts so
// that others can trivially plug in their elements.
- QQmlListModel *lm = qobject_cast<QQmlListModel *>(qobjectWrapper->object);
+ QQmlListModel *lm = qobject_cast<QQmlListModel *>(qobjectWrapper->object());
if (lm && lm->agent()) {
QQmlListModelWorkerAgent *agent = lm->agent();
agent->addref();
*/
QObject *QJSValue::toQObject() const
{
- Object *o = d->value.asObject();
+ QV4::QObjectWrapper *o = d->value.as<QV4::QObjectWrapper>();
if (!o)
return 0;
- QV8Engine *v8 = d->engine()->publicEngine->handle();
- return v8->toQObject(d->value);
+ return o->object();
}
/*!
*/
bool QJSValue::isQObject() const
{
- Object *o = d->value.asObject();
- if (!o)
- return false;
-
- return o->as<QV4::QObjectWrapper>() != 0;
+ return d->value.as<QV4::QObjectWrapper>() != 0;
}
QT_END_NAMESPACE
if (url.isValid() && url.isRelative())
url = context->resolvedUrl(url);
- QObject *parentArg = v8engine->toQObject(ctx->arguments[1]);
+ QObject *parentArg = 0;
+ if (QV4::QObjectWrapper *qobjectWrapper = ctx->arguments[1].as<QV4::QObjectWrapper>())
+ parentArg = qobjectWrapper->object();
if (!parentArg)
V4THROW_ERROR("Qt.createQmlObject(): Missing parent object");
if (consumedCount < ctx->argumentCount) {
if (lastArg.isObject()) {
- parentArg = v8engine->toQObject(lastArg);
+ if (QV4::QObjectWrapper *qobjectWrapper = lastArg.as<QV4::QObjectWrapper>())
+ parentArg = qobjectWrapper->object();
if (!parentArg)
ctx->throwError(invalidParent);
} else if (lastArg.isNull()) {
&& !value.asArrayObject() && !value.asFunctionObject()) {
return QVariant::fromValue(jsonObjectFromJS(value));
} else if (QV4::QObjectWrapper *wrapper = object->as<QV4::QObjectWrapper>()) {
- return qVariantFromValue<QObject *>(wrapper->object);
+ return qVariantFromValue<QObject *>(wrapper->object());
} else if (QV4::QmlContextWrapper *wrapper = object->as<QV4::QmlContextWrapper>()) {
return QVariant();
} else if (QV4::QmlTypeWrapper *w = object->as<QV4::QmlTypeWrapper>()) {
uint32_t length = a->arrayLength();
for (uint32_t ii = 0; ii < length; ++ii) {
QV4::Value arrayItem = a->getIndexed(m_v4Engine->current, ii);
- if (arrayItem.isObject()) {
- list << toQObject(arrayItem);
+ if (QV4::QObjectWrapper *qobjectWrapper = arrayItem.as<QV4::QObjectWrapper>()) {
+ list << qobjectWrapper->object();
} else {
list << 0;
}
QV4::QObjectWrapper *wrapper = value.as<QV4::QObjectWrapper>();
if (!wrapper)
return 0;
- return wrapper->object;
+ return wrapper->object();
}
void QV8Engine::startTimer(const QString &timerName)
// Return a JS wrapper for the given QObject \a object
inline QV4::Value newQObject(QObject *object);
inline QV4::Value newQObject(QObject *object, const ObjectOwnership ownership);
- inline QObject *toQObject(const QV4::Value &value);
// Return a JS string for the given QString \a string
QV4::Value toString(const QString &string);
Q_DISABLE_COPY(QV8Engine)
};
-QObject *QV8Engine::toQObject(const QV4::Value &value)
-{
- return value.isObject() ? m_qobjectWrapper.toQObject(value) : 0;
-}
-
QV4::Value QV8Engine::newQObject(QObject *object)
{
return m_qobjectWrapper.newQObject(object)->v4Value();
QObjectWrapper::QObjectWrapper(ExecutionEngine *engine, QObject *object)
: Object(engine)
- , object(object)
+ , m_object(object)
{
this->v8Engine = QV8Engine::get(engine->publicEngine);
vtbl = &static_vtbl;
void QObjectWrapper::deleteQObject(bool deleteInstantly)
{
- if (!object)
+ if (!m_object)
return;
- QQmlData *ddata = QQmlData::get(object, false);
+ QQmlData *ddata = QQmlData::get(m_object, false);
if (!ddata)
return;
- if (!object->parent() && !ddata->indestructible) {
+ if (!m_object->parent() && !ddata->indestructible) {
// This object is notionally destroyed now
if (ddata->ownContext && ddata->context)
ddata->context->emitDestruction();
ddata->isQueuedForDeletion = true;
if (deleteInstantly)
- delete object;
+ delete m_object;
else
- object->deleteLater();
+ m_object->deleteLater();
}
}
{
QObjectWrapper *that = static_cast<QObjectWrapper*>(m);
- if (QQmlData::wasDeleted(that->object)) {
+ if (QQmlData::wasDeleted(that->m_object)) {
if (hasProperty)
*hasProperty = false;
return QV4::Value::undefinedValue();
if (!hasProp) {
int index = name->isEqualTo(that->m_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
- method = QV4::Value::fromObject(new (ctx->engine->memoryManager) QV4::QObjectMethod(ctx->engine->rootContext, that->object, index, QV4::Value::undefinedValue()));
+ method = QV4::Value::fromObject(new (ctx->engine->memoryManager) QV4::QObjectMethod(ctx->engine->rootContext, that->m_object, index, QV4::Value::undefinedValue()));
QV4::Object::put(m, ctx, name, method);
}
QV8Engine *v8engine = that->v8Engine;
QQmlContextData *context = v8engine->callingContext();
- v8::Handle<v8::Value> result = QV8QObjectWrapper::GetProperty(v8engine, that->object, propertystring,
+ v8::Handle<v8::Value> result = QV8QObjectWrapper::GetProperty(v8engine, that->m_object, propertystring,
context, QV8QObjectWrapper::IgnoreRevision);
if (!result.IsEmpty()) {
if (hasProperty)
if (r.scriptIndex != -1) {
return QV4::Value::undefinedValue();
} else if (r.type) {
- return QmlTypeWrapper::create(v8engine, that->object, r.type, QmlTypeWrapper::ExcludeEnums);
+ return QmlTypeWrapper::create(v8engine, that->m_object, r.type, QmlTypeWrapper::ExcludeEnums);
} else if (r.importNamespace) {
- return QmlTypeWrapper::create(v8engine, that->object, context->imports, r.importNamespace, QmlTypeWrapper::ExcludeEnums);
+ return QmlTypeWrapper::create(v8engine, that->m_object, context->imports, r.importNamespace, QmlTypeWrapper::ExcludeEnums);
}
Q_ASSERT(!"Unreachable");
}
{
QObjectWrapper *that = static_cast<QObjectWrapper*>(m);
- if (QQmlData::wasDeleted(that->object))
+ if (QQmlData::wasDeleted(that->m_object))
return;
- QObject *object = that->object;
+ QObject *object = that->m_object;
QHashedV4String propertystring(QV4::Value::fromString(name));
{
QObjectWrapper *that = static_cast<QObjectWrapper*>(object);
- if (that->object.isNull())
+ if (that->m_object.isNull())
return QV4::Value::undefinedValue();
QStringList result;
: 0;
QQmlPropertyCache *cache = 0;
- QQmlData *ddata = QQmlData::get(that->object);
+ QQmlData *ddata = QQmlData::get(that->m_object);
if (ddata)
cache = ddata->propertyCache;
if (!cache) {
- cache = ep ? ep->cache(that->object) : 0;
+ cache = ep ? ep->cache(that->m_object) : 0;
if (cache) {
if (ddata) { cache->addref(); ddata->propertyCache = cache; }
} else {
// Not cachable - fall back to QMetaObject (eg. dynamic meta object)
- const QMetaObject *mo = that->object->metaObject();
+ const QMetaObject *mo = that->m_object->metaObject();
int pc = mo->propertyCount();
int po = mo->propertyOffset();
for (int i=po; i<pc; ++i)
{
QObjectWrapper *This = static_cast<QObjectWrapper*>(that);
- QQmlVMEMetaObject *vme = QQmlVMEMetaObject::get(This->object);
+ QQmlVMEMetaObject *vme = QQmlVMEMetaObject::get(This->m_object);
if (vme)
vme->mark();
v4->functionPrototype->defineDefaultProperty(v4, QStringLiteral("disconnect"), Disconnect);
}
-QObject *QV8QObjectWrapper::toQObject(v8::Handle<v8::Object> obj)
-{
- QV4::QObjectWrapper *wrapper = obj->v4Value().as<QObjectWrapper>();
- return wrapper?wrapper->object:0;
-}
-
// Load value properties
template<void (*ReadFunction)(QObject *, const QQmlPropertyData &,
void *, QQmlNotifier **)>
{
QV4::QObjectWrapper *wrapper = info.This()->v4Value().as<QObjectWrapper>();
- if (QQmlData::wasDeleted(wrapper->object))
+ if (QQmlData::wasDeleted(wrapper->object()))
return;
- QObject *object = wrapper->object;
+ QObject *object = wrapper->object();
QQmlPropertyData *property =
(QQmlPropertyData *)v8::External::Cast(info.Data().get())->Value();
{
QV4::QObjectWrapper *wrapper = info.This()->v4Value().as<QObjectWrapper>();
- if (QQmlData::wasDeleted(wrapper->object))
+ if (QQmlData::wasDeleted(wrapper->object()))
return;
QV8Engine *v8engine = wrapper->v8Engine;
qstringPtr = new (&allocData) QString(value.toQString());
type = callType;
} else if (callType == QMetaType::QObjectStar) {
- qobjectPtr = engine->toQObject(value);
+ qobjectPtr = 0;
+ if (QV4::QObjectWrapper *qobjectWrapper = value.as<QV4::QObjectWrapper>())
+ qobjectPtr = qobjectWrapper->object();
type = callType;
} else if (callType == qMetaTypeId<QVariant>()) {
qvariantPtr = new (&allocData) QVariant(engine->toVariant(value, -1));
qlistPtr = new (&allocData) QList<QObject *>();
if (QV4::ArrayObject *array = value.asArrayObject()) {
uint32_t length = array->arrayLength();
- for (uint32_t ii = 0; ii < length; ++ii)
- qlistPtr->append(engine->toQObject(array->getIndexed(ii)));
+ for (uint32_t ii = 0; ii < length; ++ii) {
+ QObject *o = 0;
+ if (QV4::QObjectWrapper *qobjectWrapper = array->getIndexed(ii).as<QV4::QObjectWrapper>())
+ o = qobjectWrapper->object();
+ qlistPtr->append(o);
+ }
} else {
- qlistPtr->append(engine->toQObject(value));
+ QObject *o = 0;
+ if (QV4::QObjectWrapper *qobjectWrapper = value.as<QV4::QObjectWrapper>())
+ o = qobjectWrapper->object();
+ qlistPtr->append(o);
}
type = callType;
} else if (callType == qMetaTypeId<QQmlV4Handle>()) {
} else if (type == -1 || type == qMetaTypeId<QVariant>()) {
QVariant value = *qvariantPtr;
QV4::Value rv = engine->fromVariant(value);
- if (QObject *object = engine->toQObject(rv))
- QQmlData::get(object, true)->setImplicitDestructible();
+ if (QV4::QObjectWrapper *qobjectWrapper = rv.as<QV4::QObjectWrapper>()) {
+ if (QObject *object = qobjectWrapper->object())
+ QQmlData::get(object, true)->setImplicitDestructible();
+ }
return rv;
} else {
return QV4::Value::undefinedValue();
{
Q_MANAGED
- QObjectWrapper(ExecutionEngine *v8Engine, QObject *object);
+ QObjectWrapper(ExecutionEngine *v8Engine, QObject *m_object);
~QObjectWrapper();
QV8Engine *v8Engine; // ### Remove again.
- QQmlGuard<QObject> object;
+
+ QObject *object() const { return m_object.data(); }
void deleteQObject(bool deleteInstantly = false);
private:
+ QQmlGuard<QObject> m_object;
String *m_destroy;
String *m_toString;
static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value);
static void markObjects(Managed *that);
- static Value enumerateProperties(Object *object);
+ static Value enumerateProperties(Object *m_object);
static void destroy(Managed *that)
{
void destroy();
v8::Handle<v8::Value> newQObject(QObject *object);
- QObject *toQObject(v8::Handle<v8::Object>);
enum RevisionMode { IgnoreRevision, CheckRevision };
inline v8::Handle<v8::Value> getProperty(QObject *, const QHashedV4String &, QQmlContextData *, RevisionMode);
roleIndex = e->setDateTimeProperty(r, dt);
} else if (propertyValue->IsObject()) {
if (QV4::QObjectWrapper *wrapper = propertyValue->v4Value().as<QV4::QObjectWrapper>()) {
- QObject *o = wrapper->object;
+ QObject *o = wrapper->object();
const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject);
if (role.type == ListLayout::Role::QObject)
roleIndex = e->setQObjectProperty(role, o);
}
} else if (propertyValue->IsObject()) {
if (QV4::QObjectWrapper *wrapper = propertyValue->v4Value().as<QV4::QObjectWrapper>()) {
- QObject *o = wrapper->object;
+ QObject *o = wrapper->object();
const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject);
if (r.type == ListLayout::Role::QObject)
e->setQObjectPropertyFast(r, o);
} else if (d->IsObject()) {
QV4::QObjectWrapper *wrapper = d->v4Value().as<QV4::QObjectWrapper>();
if (role.type == ListLayout::Role::QObject && wrapper) {
- QObject *o = wrapper->object;
+ QObject *o = wrapper->object();
roleIndex = setQObjectProperty(role, o);
} else if (role.type == ListLayout::Role::VariantMap) {
roleIndex = setVariantMapProperty(role, d->ToObject(), eng);
r->context->beginPath();
if (value->IsObject()) {
- QQuickPath* path = qobject_cast<QQuickPath*>(engine->toQObject(value->v4Value()));
- if (path)
- r->context->m_path = path->path();
+ if (QV4::QObjectWrapper *qobjectWrapper = value->v4Value().as<QV4::QObjectWrapper>()) {
+ if (QQuickPath *path = qobject_cast<QQuickPath*>(qobjectWrapper->object()))
+ r->context->m_path = path->path();
+ }
} else {
QString path = value->v4Value().toQString();
QQuickSvgParser::parsePathDataFast(path, r->context->m_path);
pixmap = r->context->createPixmap(url);
} else if (args[0]->IsObject()) {
- QQuickImage *imageItem = qobject_cast<QQuickImage*>(engine->toQObject(args[0]->v4Value()));
- QQuickCanvasItem *canvas = qobject_cast<QQuickCanvasItem*>(engine->toQObject(args[0]->v4Value()));
+ QQuickImage *imageItem = 0;
+ if (QV4::QObjectWrapper *qobjectWrapper = args[0]->v4Value().as<QV4::QObjectWrapper>())
+ imageItem = qobject_cast<QQuickImage*>(qobjectWrapper->object());
+ QQuickCanvasItem *canvas = 0;
+ if (QV4::QObjectWrapper *qobjectWrapper = args[0]->v4Value().as<QV4::QObjectWrapper>())
+ canvas = qobject_cast<QQuickCanvasItem*>(qobjectWrapper->object());
QV8Context2DPixelArrayResource *pix = v8_resource_cast<QV8Context2DPixelArrayResource>(args[0]->ToObject()->GetInternalField(0)->ToObject());
if (pix && !pix->image.isNull()) {
{
if (args->length() != 0) {
v8::Handle<v8::Value> item = (*args)[0];
- QV8Engine *engine = args->engine();
QQuickItem *itemObj = 0;
- if (!item->IsNull())
- itemObj = qobject_cast<QQuickItem*>(engine->toQObject(item->v4Value()));
+ if (!item->IsNull()) {
+ if (QV4::QObjectWrapper *qobjectWrapper = item->v4Value().as<QV4::QObjectWrapper>())
+ itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
+ }
if (!itemObj && !item->IsNull()) {
qmlInfo(this) << "mapFromItem() given argument \"" << item->v4Value().toQString()
{
if (args->length() != 0) {
v8::Handle<v8::Value> item = (*args)[0];
- QV8Engine *engine = args->engine();
QQuickItem *itemObj = 0;
- if (!item->IsNull())
- itemObj = qobject_cast<QQuickItem*>(engine->toQObject(item->v4Value()));
+ if (!item->IsNull()) {
+ if (QV4::QObjectWrapper *qobjectWrapper = item->v4Value().as<QV4::QObjectWrapper>())
+ itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
+ }
if (!itemObj && !item->IsNull()) {
qmlInfo(this) << "mapToItem() given argument \"" << item->v4Value().toQString()
o->reset();
{
v8::Handle<v8::Value> ret = EVALUATE("object.method_NoArgs_QObject()");
- QCOMPARE(engine->toQObject(ret->v4Value()), (QObject *)o);
+ QV4::QObjectWrapper *qobjectWrapper = ret->v4Value().as<QV4::QObjectWrapper>();
+ QVERIFY(qobjectWrapper);
+ QCOMPARE(qobjectWrapper->object(), (QObject *)o);
QCOMPARE(o->error(), false);
QCOMPARE(o->invoked(), 4);
QCOMPARE(o->actuals().count(), 0);