return QV4::Object::get(this, ctx, name, hasProperty);
}
+QV4::Value QObjectWrapper::wrap(ExecutionEngine *engine, QQmlData *ddata, QObject *object)
+{
+ QQmlEngine *qmlEngine = qobject_cast<QQmlEngine*>(engine->publicEngine);
+ if (!ddata->propertyCache && qmlEngine) {
+ ddata->propertyCache = QQmlEnginePrivate::get(qmlEngine)->cache(object);
+ if (ddata->propertyCache) ddata->propertyCache->addref();
+ }
+
+ return Value::fromObject(new (engine->memoryManager) QV4::QObjectWrapper(engine, object));
+}
+
QV4::Value QObjectWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty)
{
QObjectWrapper *that = static_cast<QObjectWrapper*>(m);
v8::ThrowException(v8::Exception::Error(v8engine->toString(error)));
}
-v8::Handle<v8::Object> QV8QObjectWrapper::newQObject(QObject *object, QQmlData *ddata, QV8Engine *engine)
-{
- if (!ddata->propertyCache && engine->engine()) {
- ddata->propertyCache = QQmlEnginePrivate::get(engine->engine())->cache(object);
- if (ddata->propertyCache) ddata->propertyCache->addref();
- }
-
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
- QV4::QObjectWrapper *wrapper = new (v4->memoryManager) QV4::QObjectWrapper(v4, object);
- return QV4::Value::fromObject(wrapper);
-}
-
/*
As V8 doesn't support an equality callback, for QObject's we have to return exactly the same
V8 handle for subsequent calls to newQObject for the same QObject. To do this we have a two
ddata->jsEngineId == 0 || // No one owns the QObject
!ddata->hasTaintedV8Object)) { // Someone else has used the QObject, but it isn't tainted
- v8::Handle<v8::Object> rv = newQObject(object, ddata, m_engine);
- ddata->jsWrapper = rv->v4Value();
+ QV4::Value rv = QV4::QObjectWrapper::wrap(v4, ddata, object);
+ ddata->jsWrapper = rv;
ddata->jsEngineId = v4->m_engineId;
return rv;
// If our tainted handle doesn't exist or has been collected, and there isn't
// a handle in the ddata, we can assume ownership of the ddata->v8object
if ((!found || (*iter)->jsWrapper.isEmpty()) && ddata->jsWrapper.isEmpty()) {
- v8::Handle<v8::Object> rv = newQObject(object, ddata, m_engine);
- ddata->jsWrapper = rv->v4Value();
+ QV4::Value rv = QV4::QObjectWrapper::wrap(v4, ddata, object);
+ ddata->jsWrapper = rv;
ddata->jsEngineId = v4->m_engineId;
if (found) {
}
if ((*iter)->jsWrapper.isEmpty()) {
- v8::Handle<v8::Object> rv = newQObject(object, ddata, m_engine);
- (*iter)->jsWrapper = rv->v4Value();
+ (*iter)->jsWrapper = QV4::QObjectWrapper::wrap(v4, ddata, object);
}
return (*iter)->jsWrapper.value();
enum RevisionMode { IgnoreRevision, CheckRevision };
- QObjectWrapper(ExecutionEngine *v8Engine, QObject *object);
~QObjectWrapper();
QV8Engine *v8Engine; // ### Remove again.
Value getQmlProperty(ExecutionContext *ctx, String *name, RevisionMode revisionMode, bool *hasProperty = 0, bool includeImports = false);
+ // ### Make private when QV8QObjectWrapper is gone.
+ static Value wrap(ExecutionEngine *engine, QQmlData *ddata, QObject *object);
+
private:
+ QObjectWrapper(ExecutionEngine *v8Engine, QObject *object);
+
QQmlGuard<QObject> m_object;
String *m_destroy;
String *m_toString;
friend class QV8QObjectInstance;
friend struct QV4::QObjectWrapper;
- v8::Handle<v8::Object> newQObject(QObject *, QQmlData *, QV8Engine *);
static QV4::Value GetProperty(QV8Engine *, QObject *,
const QHashedV4String &, QQmlContextData *, QV4::QObjectWrapper::RevisionMode);
static bool SetProperty(QV8Engine *, QObject *, const QHashedV4String &, QQmlContextData *,