return qmlsqldatabase_databasesPath(engine) + QDir::separator() + connectionName;
}
-static ReturnedValue qmlsqldatabase_rows_index(QV4::Referenced<QQmlSqlDatabaseWrapper> r, ExecutionEngine *v4, quint32 index, bool *hasProperty = 0)
+static ReturnedValue qmlsqldatabase_rows_index(QV4::ManagedRef<QQmlSqlDatabaseWrapper> r, ExecutionEngine *v4, quint32 index, bool *hasProperty = 0)
{
Scope scope(v4);
QV8Engine *v8 = v4->v8Engine;
return newRegExpObject(re, global);
}
-Returned<RegExpObject> *ExecutionEngine::newRegExpObject(Referenced<RegExp> re, bool global)
+Returned<RegExpObject> *ExecutionEngine::newRegExpObject(ManagedRef<RegExp> re, bool global)
{
RegExpObject *object = new (memoryManager) RegExpObject(this, re, global);
return object->asReturned<RegExpObject>();
Returned<DateObject> *newDateObject(const QDateTime &dt);
Returned<RegExpObject> *newRegExpObject(const QString &pattern, int flags);
- Returned<RegExpObject> *newRegExpObject(Referenced<RegExp> re, bool global);
+ Returned<RegExpObject> *newRegExpObject(ManagedRef<RegExp> re, bool global);
Returned<RegExpObject> *newRegExpObject(const QRegExp &re);
Returned<Object> *newErrorObject(const ValueRef value);
typedef Returned<String> ReturnedString;
typedef Returned<Object> ReturnedObject;
typedef Returned<FunctionObject> ReturnedFunctionObject;
-template<typename T> struct Referenced;
-typedef Referenced<Managed> ManagedRef;
-typedef Referenced<String> StringRef;
-typedef Referenced<Object> ObjectRef;
-typedef Referenced<ArrayObject> ArrayObjectRef;
-typedef Referenced<FunctionObject> FunctionObjectRef;
+template<typename T> struct ManagedRef;
+typedef ManagedRef<String> StringRef;
+typedef ManagedRef<Object> ObjectRef;
+typedef ManagedRef<ArrayObject> ArrayObjectRef;
+typedef ManagedRef<FunctionObject> FunctionObjectRef;
struct PersistentValuePrivate;
class PersistentValue;
};
template<typename T>
-struct Referenced {
- // Important: Do NOT add a copy constructor to this class
+struct ManagedRef {
+ // Important: Do NOT add a copy constructor to this class or any derived class
// adding a copy constructor actually changes the calling convention, ie.
// is not even binary compatible. Adding it would break assumptions made
// in the jit'ed code.
- Referenced(const Scoped<T> &v);
- Referenced(TypedValue<T> &v) { ptr = &v; }
- Referenced(Value &v) {
+ ManagedRef(const ScopedValue);
+ ManagedRef(const Scoped<T> &v);
+ ManagedRef(TypedValue<T> &v) { ptr = &v; }
+ ManagedRef(Value &v) {
ptr = value_cast<T>(v) ? &v : 0;
}
- static Referenced fromValuePointer(Value *s) {
- return Referenced(s);
+ static ManagedRef fromValuePointer(Value *s) {
+ ManagedRef r(s);
+ if (sizeof(void *) == 8)
+ r.ptr->val = 0;
+ else
+ *r.ptr = Value::fromManaged(0);
+ return r;
}
- Referenced &operator=(const Referenced &o)
- { *ptr = *o.ptr; return *this; }
- Referenced &operator=(T *t)
+ ManagedRef &operator=(T *t)
{
-#if QT_POINTER_SIZE == 4
- ptr->tag = Value::Managed_Type;
-#endif
+ if (sizeof(void *) == 4)
+ ptr->tag = Value::Managed_Type;
ptr->m = t;
return *this;
}
- Referenced &operator=(Returned<T> *t) {
-#if QT_POINTER_SIZE == 4
- ptr->tag = Value::Managed_Type;
-#endif
+ ManagedRef &operator=(Returned<T> *t) {
+ if (sizeof(void *) == 4)
+ ptr->tag = Value::Managed_Type;
ptr->m = t->getPointer();
return *this;
}
ReturnedValue asReturnedValue() const { return ptr ? ptr->val : Primitive::undefinedValue().asReturnedValue(); }
operator Returned<T> *() const { return ptr ? Returned<T>::create(getPointer()) : 0; }
- bool operator==(const Referenced<T> &other) {
+ bool operator==(const ManagedRef<T> &other) {
if (ptr == other.ptr)
return true;
return ptr && other.ptr && ptr->m == other.ptr->m;
}
- bool operator!=(const Referenced<T> &other) {
- if (ptr == other.ptr)
- return false;
- return !ptr || ptr->m != other.ptr->m;
+ bool operator!=(const ManagedRef<T> &other) {
+ return !operator==(other);
}
bool operator!() const { return !ptr || !ptr->managed(); }
- static Referenced null() { return Referenced(Null); }
+ static ManagedRef null() { return ManagedRef((Value *)0); }
bool isNull() const { return !ptr; }
-private:
- Referenced(Value *v) {
+protected:
+ ManagedRef(Value *v) {
ptr = v;
-#if QT_POINTER_SIZE == 8
- ptr->val = 0;
-#else
- *ptr = Value::fromManaged(0);
-#endif
}
- enum _Null { Null };
- Referenced(_Null) { ptr = 0; }
Value *ptr;
};
-typedef Referenced<Managed> ManagedRef;
-
-
template<>
inline Managed *value_cast(const Value &v) {
return v.asManaged();
template<typename T>
PersistentValue(Returned<T> *obj);
template<typename T>
- PersistentValue(const Referenced<T> obj);
+ PersistentValue(const ManagedRef<T> obj);
PersistentValue &operator=(const ValueRef other);
PersistentValue &operator =(ReturnedValue other);
template<typename T>
PersistentValue &operator=(Returned<T> *obj);
template<typename T>
- PersistentValue &operator=(const Referenced<T> obj);
+ PersistentValue &operator=(const ManagedRef<T> obj);
~PersistentValue();
ReturnedValue value() const {
} else if (type == -1 || type == qMetaTypeId<QVariant>()) {
QVariant value = *qvariantPtr;
QV4::ScopedValue rv(scope, engine->fromVariant(value));
- if (QV4::Referenced<QObjectWrapper> qobjectWrapper = rv->asRef<QV4::QObjectWrapper>()) {
+ if (QV4::ManagedRef<QObjectWrapper> qobjectWrapper = rv) {
if (QObject *object = qobjectWrapper->object())
QQmlData::get(object, true)->setImplicitDestructible();
}
init(ic->engine);
}
-RegExpObject::RegExpObject(ExecutionEngine *engine, Referenced<RegExp> value, bool global)
+RegExpObject::RegExpObject(ExecutionEngine *engine, ManagedRef<RegExp> value, bool global)
: Object(engine->regExpClass)
, value(value)
, global(global)
Property *lastIndexProperty(ExecutionContext *ctx);
bool global;
- RegExpObject(ExecutionEngine *engine, Referenced<RegExp> value, bool global);
+ RegExpObject(ExecutionEngine *engine, ManagedRef<RegExp> value, bool global);
RegExpObject(ExecutionEngine *engine, const QRegExp &re);
~RegExpObject() {}
};
-typedef Referenced<String> StringRef;
-typedef Referenced<Object> ObjectRef;
-typedef Referenced<FunctionObject> FunctionObjectRef;
+typedef ManagedRef<String> StringRef;
+typedef ManagedRef<Object> ObjectRef;
+typedef ManagedRef<FunctionObject> FunctionObjectRef;
template<typename T>
inline Scoped<T>::Scoped(const Scope &scope, const ValueRef &v)
return Returned<T>::create(value_cast<T>(*this));
}
-template<typename T> inline
-Referenced<T> Value::asRef()
-{
- return Referenced<T>(*this);
-}
-
template<typename T>
inline TypedValue<T> &TypedValue<T>::operator =(T *t)
{
}
template<typename T>
-inline TypedValue<T> &TypedValue<T>::operator =(const Referenced<T> &v)
+inline TypedValue<T> &TypedValue<T>::operator =(const ManagedRef<T> &v)
{
val = v.asReturnedValue();
return *this;
}
template<typename T>
-inline PersistentValue::PersistentValue(const Referenced<T> obj)
+inline PersistentValue::PersistentValue(const ManagedRef<T> obj)
: d(new PersistentValuePrivate(*obj.ptr))
{
}
}
template<typename T>
-inline PersistentValue &PersistentValue::operator=(const Referenced<T> obj)
+inline PersistentValue &PersistentValue::operator=(const ManagedRef<T> obj)
{
return operator=(*obj.ptr);
}
return *this;
}
+
+template<typename T>
+ManagedRef<T>::ManagedRef(const ScopedValue v)
+{
+ ptr = value_cast<T>(*v.ptr) ? v.ptr : 0;
+}
+
template<typename T>
-Referenced<T>::Referenced(const Scoped<T> &v)
+ManagedRef<T>::ManagedRef(const Scoped<T> &v)
: ptr(v.ptr)
{}
}
template<typename T>
inline Returned<T> *as();
- template<typename T>
- inline Referenced<T> asRef();
-
};
inline Managed *Value::asManaged() const
}
TypedValue &operator =(T *t);
TypedValue &operator =(const Scoped<T> &v);
- TypedValue &operator =(const Referenced<T> &v);
+ TypedValue &operator =(const ManagedRef<T> &v);
TypedValue &operator =(Returned<T> *t);
TypedValue &operator =(const TypedValue<T> &t);
// 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.
QV4::ScopedValue newv(scope, QQmlEnginePrivate::get(ctxt->engine)->v8engine()->fromVariant(value));
- if (QV4::Referenced<QV4::VariantObject> v = newv->asRef<QV4::VariantObject>())
+ if (QV4::ManagedRef<QV4::VariantObject> v = newv)
v->addVmePropertyReference();
// Write the value and emit change signal as appropriate.
QV4::ScopedValue value(scope, ctx->argument(0));
r->context->beginPath();
- if (QV4::Referenced<QV4::QObjectWrapper> qobjectWrapper = value->asRef<QV4::QObjectWrapper>()) {
+ if (QV4::ManagedRef<QV4::QObjectWrapper> qobjectWrapper = value) {
if (QQuickPath *path = qobject_cast<QQuickPath*>(qobjectWrapper->object()))
r->context->m_path = path->path();
} else {
pixmap = r->context->createPixmap(url);
} else if (arg->isObject()) {
- if (QV4::Referenced<QV4::QObjectWrapper> qobjectWrapper = arg->asRef<QV4::QObjectWrapper>()) {
+ if (QV4::ManagedRef<QV4::QObjectWrapper> qobjectWrapper = arg) {
if (QQuickImage *imageItem = qobject_cast<QQuickImage*>(qobjectWrapper->object())) {
pixmap = r->context->createPixmap(imageItem->source());
} else if (QQuickCanvasItem *canvas = qobject_cast<QQuickCanvasItem*>(qobjectWrapper->object())) {
} else {
V4THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
}
- } else if (QV4::Referenced<QQuickJSContext2DImageData> imageData = arg->asRef<QQuickJSContext2DImageData>()) {
+ } else if (QV4::ManagedRef<QQuickJSContext2DImageData> imageData = arg) {
QV4::Scoped<QQuickJSContext2DPixelData> pix(scope, imageData->pixelData.as<QQuickJSContext2DPixelData>());
if (pix && !pix->image.isNull()) {
pixmap.take(new QQuickCanvasPixmap(pix->image));
if (ctx->callData->argc == 1) {
QV4::ScopedValue arg0(scope, ctx->callData->args[0]);
- if (QV4::Referenced<QQuickJSContext2DImageData> imgData = arg0->asRef<QQuickJSContext2DImageData>()) {
+ if (QV4::ManagedRef<QQuickJSContext2DImageData> imgData = arg0) {
QV4::Scoped<QQuickJSContext2DPixelData> pa(scope, imgData->pixelData.as<QQuickJSContext2DPixelData>());
if (pa) {
qreal w = pa->image.width();
if (!qIsFinite(dx) || !qIsFinite(dy))
V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments");
- QV4::Referenced<QQuickJSContext2DImageData> imageData = arg0->asRef<QQuickJSContext2DImageData>();
+ QV4::ManagedRef<QQuickJSContext2DImageData> imageData = arg0;
if (!imageData)
return ctx->callData->thisObject.asReturnedValue();