hasTaintedV8Object(false), isQueuedForDeletion(false), rootObjectInCreation(false),
hasVMEMetaObject(false), parentFrozen(false), notifyList(0), context(0), outerContext(0),
bindings(0), signalHandlers(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0),
- lineNumber(0), columnNumber(0), compiledData(0), deferredIdx(0), v8objectid(0),
+ lineNumber(0), columnNumber(0), compiledData(0), deferredIdx(0), jsEngineId(0),
propertyCache(0), guards(0), extendedData(0) {
init();
}
QQmlCompiledData *compiledData;
unsigned int deferredIdx;
- quint32 v8objectid;
- QV4::WeakValue v8object;
+ quint32 jsEngineId; // id of the engine that cerated the jsWrapper
+ QV4::WeakValue jsWrapper;
QQmlPropertyCache *propertyCache;
delete extendedData;
// Dispose the handle.
- v8object = QV4::Value::undefinedValue();
+ jsWrapper = QV4::Value::undefinedValue();
if (ownMemory)
delete this;
if (ref) {
QQmlData *ddata = QQmlData::get(ref);
if (ddata)
- ddata->v8object.markOnce();
+ ddata->jsWrapper.markOnce();
}
}
}
using namespace QV4;
+static QBasicAtomicInt engineSerial = Q_BASIC_ATOMIC_INITIALIZER(1);
+
ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory)
: memoryManager(new QV4::MemoryManager)
, executableAllocator(new QV4::ExecutableAllocator)
, globalObject(0)
, globalCode(0)
, functionsNeedSort(false)
+ , m_engineId(engineSerial.fetchAndAddOrdered(1))
, regExpCache(0)
{
MemoryManager::GCBlocker gcBlocker(memoryManager);
mutable QVector<Function *> functions;
mutable bool functionsNeedSort;
+ quint32 m_engineId;
+
RegExpCache *regExpCache;
// Scarce resources are "exceptionally high cost" QVariant types where allowing the
// if the object has JS ownership, the object's v8object owns the lifetime of the persistent value.
if (QQmlEngine::objectOwnership(object) == QQmlEngine::JavaScriptOwnership) {
*shouldBeStrong = false;
- return &(QQmlData::get(object)->v8object);
+ return &(QQmlData::get(object)->jsWrapper);
}
// no parent, and has CPP ownership - doesn't have an implicit parent.
if (QQmlEngine::objectOwnership(parent) == QQmlEngine::JavaScriptOwnership) {
// root parent is owned by JS. It's v8object owns the persistent value in question.
*shouldBeStrong = false;
- return &(QQmlData::get(parent)->v8object);
+ return &(QQmlData::get(parent)->jsWrapper);
} else {
// root parent has CPP ownership. The persistent value should not be made weak.
*shouldBeStrong = true;
delete this;
}
- QV4::WeakValue v8object;
+ QV4::WeakValue jsWrapper;
QV8QObjectWrapper *wrapper;
};
};
}
-static QAtomicInt objectIdCounter(1);
-
QV8QObjectWrapper::QV8QObjectWrapper()
-: m_engine(0), m_id(objectIdCounter.fetchAndAddOrdered(1))
+: m_engine(0)
{
}
if (!ddata)
return QV4::Value::undefinedValue();
- if (ddata->v8objectid == m_id && !ddata->v8object.isEmpty()) {
+ QV4::ExecutionEngine *v4 = QV8Engine::getV4(m_engine);
+
+ if (ddata->jsEngineId == v4->m_engineId && !ddata->jsWrapper.isEmpty()) {
// We own the v8object
- return ddata->v8object.value();
- } else if (ddata->v8object.isEmpty() &&
- (ddata->v8objectid == m_id || // We own the QObject
- ddata->v8objectid == 0 || // No one owns the QObject
+ return ddata->jsWrapper.value();
+ } else if (ddata->jsWrapper.isEmpty() &&
+ (ddata->jsEngineId == v4->m_engineId || // We own the QObject
+ 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->v8object = rv->v4Value();
- ddata->v8objectid = m_id;
+ ddata->jsWrapper = rv->v4Value();
+ ddata->jsEngineId = v4->m_engineId;
return rv;
} else {
// 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)->v8object.isEmpty()) && ddata->v8object.isEmpty()) {
+ if ((!found || (*iter)->jsWrapper.isEmpty()) && ddata->jsWrapper.isEmpty()) {
v8::Handle<v8::Object> rv = newQObject(object, ddata, m_engine);
- ddata->v8object = rv->v4Value();
- ddata->v8objectid = m_id;
+ ddata->jsWrapper = rv->v4Value();
+ ddata->jsEngineId = v4->m_engineId;
if (found) {
delete (*iter);
ddata->hasTaintedV8Object = true;
}
- if ((*iter)->v8object.isEmpty()) {
+ if ((*iter)->jsWrapper.isEmpty()) {
v8::Handle<v8::Object> rv = newQObject(object, ddata, m_engine);
- (*iter)->v8object = rv->v4Value();
+ (*iter)->jsWrapper = rv->v4Value();
}
- return (*iter)->v8object.value();
+ return (*iter)->jsWrapper.value();
}
}
static QPair<QObject *, int> ExtractQtSignal(QV8Engine *, const QV4::Value &value);
QV8Engine *m_engine;
- quint32 m_id;
QHash<QObject *, QV8QObjectConnectionList *> m_connections;
typedef QHash<QObject *, QV8QObjectInstance *> TaintedHash;
TaintedHash m_taintedObjects;
{
QQmlData *ddata = QQmlData::get(this);
assert(ddata);
- QV4::QObjectWrapper *thisObject = ddata->v8object.value().as<QV4::QObjectWrapper>();
+ QV4::QObjectWrapper *thisObject = ddata->jsWrapper.value().as<QV4::QObjectWrapper>();
assert(thisObject);
QQmlData *otherDData = QQmlData::get(other);
assert(otherDData);
- thisObject->defineDefaultProperty(thisObject->engine(), QStringLiteral("autoTestStrongRef"), otherDData->v8object.value());
+ thisObject->defineDefaultProperty(thisObject->engine(), QStringLiteral("autoTestStrongRef"), otherDData->jsWrapper.value());
}
void setEngine(QQmlEngine* declarativeEngine)