Move the internalClass pointer from Object to Managed
authorLars Knoll <lars.knoll@digia.com>
Mon, 6 May 2013 09:37:53 +0000 (11:37 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 6 May 2013 11:08:58 +0000 (13:08 +0200)
This allows us to get back the ExecutionEngine for all
memeory managed objects, so we can avoid lots of special
handling for String objects.

Simplify and cleanup QV4::PersistentValue and make use
of the available engine pointer in Managed.

Change-Id: Ia2e08b6207f7e706c23be219d5f6e74b414035a3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
19 files changed:
src/qml/qml/v4/qv4codegen.cpp
src/qml/qml/v4/qv4engine.cpp
src/qml/qml/v4/qv4managed.cpp
src/qml/qml/v4/qv4managed_p.h
src/qml/qml/v4/qv4mm.cpp
src/qml/qml/v4/qv4object.cpp
src/qml/qml/v4/qv4object_p.h
src/qml/qml/v4/qv4regexp.cpp
src/qml/qml/v4/qv4runtime.cpp
src/qml/qml/v4/qv4string.cpp
src/qml/qml/v4/qv4string_p.h
src/qml/qml/v4/qv4value.cpp
src/qml/qml/v4/qv4value_p.h
src/qml/qml/v8/qjsengine.cpp
src/qml/qml/v8/qjsvalue.cpp
src/qml/qml/v8/qjsvalue_p.h
src/qml/qml/v8/qjsvalueiterator.cpp
src/qml/qml/v8/qv8engine.cpp
src/qml/qml/v8/qv8qobjectwrapper.cpp

index 6196a03..2b796b3 100644 (file)
@@ -2113,7 +2113,7 @@ bool Codegen::visit(ObjectLiteral *ast)
     if (!valueMap.isEmpty()) {
         V4IR::ExprList *current;
         for (QMap<QString, ObjectPropertyValue>::iterator it = valueMap.begin(); it != valueMap.end(); ) {
-            if (QV4::String(it.key()).asArrayIndex() != UINT_MAX) {
+            if (QV4::String(0, it.key()).asArrayIndex() != UINT_MAX) {
                 ++it;
                 continue;
             }
index 074a8e5..a507cab 100644 (file)
@@ -374,7 +374,7 @@ Object *ExecutionEngine::newObject(InternalClass *internalClass)
 
 String *ExecutionEngine::newString(const QString &s)
 {
-    return new (memoryManager) String(s);
+    return new (memoryManager) String(this, s);
 }
 
 String *ExecutionEngine::newIdentifier(const QString &text)
index 8347674..77e36a7 100644 (file)
@@ -91,6 +91,11 @@ void Managed::operator delete(void *ptr, MemoryManager *mm)
     operator delete(ptr);
 }
 
+ExecutionEngine *Managed::engine() const
+{
+    return internalClass ? internalClass->engine : 0;
+}
+
 QString Managed::className() const
 {
     const char *s = 0;
index 678c034..46030bf 100644 (file)
@@ -56,6 +56,7 @@ struct Object;
 struct ObjectPrototype;
 struct ExecutionContext;
 struct ScriptFunction;
+struct InternalClass;
 
 struct BooleanObject;
 struct NumberObject;
@@ -72,6 +73,7 @@ struct Managed;
 struct Value;
 class RegExp;
 struct Lookup;
+struct ExecutionEngine;
 
 struct ManagedVTable
 {
@@ -123,8 +125,8 @@ private:
     void operator = (const Managed &other);
 
 protected:
-    Managed()
-        : _data(0), vtbl(&static_vtbl)
+    Managed(InternalClass *internal)
+        : _data(0), vtbl(&static_vtbl), internalClass(internal)
     { inUse = 1; extensible = 1; }
 
 public:
@@ -159,6 +161,8 @@ public:
         Type_RegExp
     };
 
+    ExecutionEngine *engine() const;
+
     String *asString() { return reinterpret_cast<String *>(this); }
     Object *asObject() { return reinterpret_cast<Object *>(this); }
     ArrayObject *asArrayObject() { return type == Type_ArrayObject ? reinterpret_cast<ArrayObject *>(this) : 0; }
@@ -243,6 +247,8 @@ protected:
     static const ManagedVTable static_vtbl;
 
     const ManagedVTable *vtbl;
+public:
+    InternalClass *internalClass;
 
 private:
     friend class MemoryManager;
index 572a90f..b59100d 100644 (file)
@@ -400,8 +400,7 @@ MemoryManager::~MemoryManager()
     PersistentValuePrivate *persistent = m_persistentValues;
     while (persistent) {
         if (Managed *m = persistent->value.asManaged())
-            persistent->value = Value::undefinedValue();
-        persistent->engine = 0;
+            persistent->value = Value::deletedValue();
         PersistentValuePrivate *n = persistent->next;
         persistent->next = 0;
         persistent = n;
index f5462b6..19b5146 100644 (file)
@@ -68,8 +68,8 @@ using namespace QV4;
 DEFINE_MANAGED_VTABLE(Object);
 
 Object::Object(ExecutionEngine *engine)
-    : prototype(0)
-    , internalClass(engine->emptyClass)
+    : Managed(engine->emptyClass)
+    , prototype(0)
     , memberDataAlloc(InlinePropertySize), memberData(inlineProperties)
     , arrayOffset(0), arrayDataLen(0), arrayAlloc(0), arrayAttributes(0), arrayData(0), sparseArray(0)
     , externalResource(0)
@@ -79,8 +79,8 @@ Object::Object(ExecutionEngine *engine)
 }
 
 Object::Object(ExecutionContext *context)
-    : prototype(0)
-    , internalClass(context->engine->emptyClass)
+    : Managed(context->engine->emptyClass)
+    , prototype(0)
     , memberDataAlloc(InlinePropertySize), memberData(inlineProperties)
     , arrayOffset(0), arrayDataLen(0), arrayAlloc(0), arrayAttributes(0), arrayData(0), sparseArray(0)
     , externalResource(0)
@@ -90,8 +90,8 @@ Object::Object(ExecutionContext *context)
 }
 
 Object::Object(ExecutionEngine *engine, InternalClass *internalClass)
-    : prototype(0)
-    , internalClass(internalClass)
+    : Managed(internalClass)
+    , prototype(0)
     , memberDataAlloc(InlinePropertySize), memberData(inlineProperties)
     , arrayOffset(0), arrayDataLen(0), arrayAlloc(0), arrayAttributes(0), arrayData(0), sparseArray(0)
     , externalResource(0)
index aef9367..b8d3b1c 100644 (file)
@@ -108,7 +108,6 @@ struct Q_QML_EXPORT Object: Managed {
     };
 
     Object *prototype;
-    InternalClass *internalClass;
     uint memberDataAlloc;
     Property *memberData;
 
index 0dfbad3..6ea9841 100644 (file)
@@ -92,7 +92,8 @@ RegExp* RegExp::create(ExecutionEngine* engine, const QString& pattern, bool ign
 }
 
 RegExp::RegExp(ExecutionEngine* engine, const QString &pattern, bool ignoreCase, bool multiline)
-    : m_pattern(pattern)
+    : Managed(engine->emptyClass)
+    , m_pattern(pattern)
     , m_cache(0)
     , m_subPatternCount(0)
     , m_ignoreCase(ignoreCase)
index b85fbeb..d21399a 100644 (file)
@@ -69,7 +69,7 @@ using namespace QV4;
 
 
 Exception::Exception(ExecutionContext *throwingContext, const Value &exceptionValue)
-    : exception(PersistentValue(throwingContext->engine, exceptionValue))
+    : exception(exceptionValue)
 {
     this->throwingContext = throwingContext->engine->current;
     accepted = false;
index 9288afd..4168212 100644 (file)
@@ -174,6 +174,14 @@ bool String::deleteIndexedProperty(Managed *m, ExecutionContext *ctx, uint index
     return false;
 }
 
+String::String(ExecutionEngine *engine, const QString &text)
+    : Managed(engine ? engine->emptyClass : 0), _text(text), stringHash(UINT_MAX), identifier(UINT_MAX)
+{
+    vtbl = &static_vtbl;
+    type = Type_String;
+    subtype = StringType_Unknown;
+}
+
 uint String::toUInt(bool *ok) const
 {
     *ok = true;
index a681330..f5864fc 100644 (file)
@@ -58,9 +58,9 @@ struct String : public Managed {
         StringType_ArrayIndex
     };
 
-    String(const QString &text)
-        : _text(text), stringHash(UINT_MAX), identifier(UINT_MAX)
+    String() : Managed(0), stringHash(UINT_MAX), identifier(UINT_MAX)
     { vtbl = &static_vtbl; type = Type_String; subtype = StringType_Unknown; }
+    String(ExecutionEngine *engine, const QString &text);
     ~String() { _data = 0; }
 
     inline bool isEqualTo(const String *other) const {
index 6722e4d..7e2f164 100644 (file)
@@ -222,8 +222,8 @@ PersistentValue::PersistentValue()
 {
 }
 
-PersistentValue::PersistentValue(ExecutionEngine *e, const Value &val)
-    : d(new PersistentValuePrivate(e, val))
+PersistentValue::PersistentValue(const Value &val)
+    : d(new PersistentValuePrivate(val))
 {
 }
 
@@ -244,6 +244,11 @@ PersistentValue &PersistentValue::operator=(const PersistentValue &other)
     d->ref();
 }
 
+PersistentValue &PersistentValue::operator =(const Value &other)
+{
+    d->value = other;
+}
+
 PersistentValue::~PersistentValue()
 {
     d->deref();
@@ -252,26 +257,26 @@ PersistentValue::~PersistentValue()
 PersistentValuePrivate::PersistentValuePrivate(const Value &v)
     : value(v)
     , refcount(1)
-    , engine(0)
     , next(0)
 {
-    assert(!v.asManaged());
-}
-
-
-PersistentValuePrivate::PersistentValuePrivate(ExecutionEngine *e, const Value &v)
-    : value(v)
-    , refcount(1)
-    , engine(e)
-    , next(engine->memoryManager->m_persistentValues)
-{
-    engine->memoryManager->m_persistentValues = this;
+    if (Managed *m = v.asManaged()) {
+        ExecutionEngine *engine = m->engine();
+        if (engine) {
+            next = engine->memoryManager->m_persistentValues;
+            engine->memoryManager->m_persistentValues = this;
+        }
+    }
 }
 
 void PersistentValuePrivate::deref()
 {
     // if engine is not 0, they are registered with the memory manager
     // and will get cleaned up in the next gc run
-    if (!--refcount && !engine)
-        delete this;
+    if (!--refcount && !next) {
+        ExecutionEngine *e = 0;
+        if (Managed *m = value.asManaged())
+            e = m->engine();
+        if (!e)
+            delete this;
+    }
 }
index 6207458..fb63935 100644 (file)
@@ -274,6 +274,11 @@ struct Q_QML_EXPORT Value
 
     Value property(ExecutionContext *ctx, String *name) const;
 
+    ExecutionEngine *engine() const {
+        Managed *m = asManaged();
+        return m ? m->engine() : 0;
+    }
+
     // Section 9.12
     bool sameValue(Value other) const;
 
@@ -549,14 +554,11 @@ struct PersistentValuePrivate
     PersistentValuePrivate()
         : value(Value::undefinedValue())
         , refcount(1)
-        , engine(0)
         , next(0)
     {}
-    PersistentValuePrivate(ExecutionEngine *e, const Value &v);
     PersistentValuePrivate(const Value &v);
     Value value;
     int refcount;
-    ExecutionEngine *engine;
     PersistentValuePrivate *next;
 
     void ref() { ++refcount; }
@@ -567,14 +569,20 @@ class PersistentValue
 {
 public:
     PersistentValue();
-    PersistentValue(ExecutionEngine *e, const Value &val);
+    PersistentValue(const Value &val);
     PersistentValue(const PersistentValue &other);
     PersistentValue &operator=(const PersistentValue &other);
+    PersistentValue &operator=(const Value &other);
     ~PersistentValue();
 
     Value *operator->() { return &d->value; }
     Value *operator*() { return &d->value; }
 
+    ExecutionEngine *engine() {
+        Managed *m = d->value.asManaged();
+        return m ? m->engine() : 0;
+    }
+
     operator Value() const { return d->value; }
 
 private:
index b5dc1d1..39aae96 100644 (file)
@@ -254,17 +254,18 @@ void QJSEngine::collectGarbage()
 */
 QJSValue QJSEngine::evaluate(const QString& program, const QString& fileName, int lineNumber)
 {
+    QV4::ExecutionContext *ctx = d->m_v4Engine->current;
     try {
-        QV4::Function *f = QV4::EvalFunction::parseSource(d->m_v4Engine->current, fileName, program, QQmlJS::Codegen::EvalCode,
-                                                                        d->m_v4Engine->current->strictMode, true);
+        QV4::Function *f = QV4::EvalFunction::parseSource(ctx, fileName, program, QQmlJS::Codegen::EvalCode,
+                                                          d->m_v4Engine->current->strictMode, true);
         if (!f)
             return QJSValue();
 
         QV4::Value result = d->m_v4Engine->run(f);
-        return new QJSValuePrivate(d->m_v4Engine, result);
+        return new QJSValuePrivate(result);
     } catch (QV4::Exception& ex) {
-        ex.accept(d->m_v4Engine->current);
-        return new QJSValuePrivate(d->m_v4Engine, ex.value());
+        ex.accept(ctx);
+        return new QJSValuePrivate(ex.value());
     }
 }
 
@@ -278,7 +279,7 @@ QJSValue QJSEngine::evaluate(const QString& program, const QString& fileName, in
 */
 QJSValue QJSEngine::newObject()
 {
-    return new QJSValuePrivate(d->m_v4Engine, d->m_v4Engine->newObject());
+    return new QJSValuePrivate(d->m_v4Engine->newObject());
 }
 
 /*!
@@ -292,7 +293,7 @@ QJSValue QJSEngine::newArray(uint length)
     if (length < 0x1000)
         array->arrayReserve(length);
     array->setArrayLengthUnchecked(length);
-    return new QJSValuePrivate(d->m_v4Engine, array);
+    return new QJSValuePrivate(array);
 }
 
 /*!
@@ -334,7 +335,7 @@ QJSValue QJSEngine::newQObject(QObject *object)
 */
 QJSValue QJSEngine::globalObject() const
 {
-    return new QJSValuePrivate(d->m_v4Engine, d->m_v4Engine->globalObject);
+    return new QJSValuePrivate(d->m_v4Engine->globalObject);
 }
 
 /*!
@@ -344,7 +345,7 @@ QJSValue QJSEngine::globalObject() const
 QJSValue QJSEngine::create(int type, const void *ptr)
 {
     Q_D(QJSEngine);
-    return new QJSValuePrivate(QV8Engine::getV4(d), d->metaTypeToJS(type, ptr));
+    return new QJSValuePrivate(d->metaTypeToJS(type, ptr));
 }
 
 /*!
@@ -354,7 +355,7 @@ QJSValue QJSEngine::create(int type, const void *ptr)
 bool QJSEngine::convertV2(const QJSValue &value, int type, void *ptr)
 {
     QJSValuePrivate *vp = QJSValuePrivate::get(value);
-    QV4::ExecutionEngine *e = vp->engine;
+    QV4::ExecutionEngine *e = vp->engine();
     QV8Engine *engine = e ? QV8Engine::get(e->publicEngine) : 0;
     if (engine) {
         return engine->metaTypeFromJS(vp->getValue(engine->m_v4Engine), type, ptr);
index 839bdab..ed75edc 100644 (file)
@@ -352,7 +352,8 @@ QString QJSValue::toString() const
 */
 double QJSValue::toNumber() const
 {
-    QV4::ExecutionContext *ctx = d->engine ? d->engine->current : 0;
+    QV4::ExecutionEngine *e = d->engine();
+    QV4::ExecutionContext *ctx = e ? e->current : 0;
     try {
         return d->value.toNumber();
     } catch (Exception &e) {
@@ -375,7 +376,8 @@ double QJSValue::toNumber() const
 */
 bool QJSValue::toBool() const
 {
-    QV4::ExecutionContext *ctx = d->engine ? d->engine->current : 0;
+    QV4::ExecutionEngine *e = d->engine();
+    QV4::ExecutionContext *ctx = e ? e->current : 0;
     try {
         return d->value.toBoolean();
     } catch (Exception &e) {
@@ -398,7 +400,8 @@ bool QJSValue::toBool() const
 */
 qint32 QJSValue::toInt() const
 {
-    QV4::ExecutionContext *ctx = d->engine ? d->engine->current : 0;
+    QV4::ExecutionEngine *e = d->engine();
+    QV4::ExecutionContext *ctx = e ? e->current : 0;
     try {
         return d->value.toInt32();
     } catch (Exception &e) {
@@ -421,7 +424,8 @@ qint32 QJSValue::toInt() const
 */
 quint32 QJSValue::toUInt() const
 {
-    QV4::ExecutionContext *ctx = d->engine ? d->engine->current : 0;
+    QV4::ExecutionEngine *e = d->engine();
+    QV4::ExecutionContext *ctx = e ? e->current : 0;
     try {
         return d->value.toUInt32();
     } catch (Exception &e) {
@@ -479,7 +483,7 @@ QJSValue QJSValue::call(const QJSValueList &args)
     if (!f)
         return QJSValue();
 
-    ExecutionEngine *engine = d->engine;
+    ExecutionEngine *engine = d->engine();
     assert(engine);
 
     QVarLengthArray<Value> arguments(args.length());
@@ -487,15 +491,15 @@ QJSValue QJSValue::call(const QJSValueList &args)
         arguments[i] = args.at(i).d->getValue(engine);
 
     Value result;
-    QV4::ExecutionContext *ctx = d->engine->current;
+    QV4::ExecutionContext *ctx = engine->current;
     try {
-        result = f->call(ctx, Value::fromObject(d->engine->globalObject), arguments.data(), arguments.size());
+        result = f->call(ctx, Value::fromObject(engine->globalObject), arguments.data(), arguments.size());
     } catch (Exception &e) {
         e.accept(ctx);
         result = e.value();
     }
 
-    return new QJSValuePrivate(engine, result);
+    return new QJSValuePrivate(result);
 }
 
 /*!
@@ -524,7 +528,7 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList
     if (!f)
         return QJSValue();
 
-    ExecutionEngine *engine = d->engine;
+    ExecutionEngine *engine = d->engine();
     assert(engine);
 
     QVarLengthArray<Value> arguments(args.length());
@@ -532,7 +536,7 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList
         arguments[i] = args.at(i).d->getValue(engine);
 
     Value result;
-    QV4::ExecutionContext *ctx = d->engine->current;
+    QV4::ExecutionContext *ctx = engine->current;
     try {
         result = f->call(ctx, instance.d->getValue(engine), arguments.data(), arguments.size());
     } catch (Exception &e) {
@@ -540,7 +544,7 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList
         result = e.value();
     }
 
-    return new QJSValuePrivate(engine, result);
+    return new QJSValuePrivate(result);
 }
 
 /*!
@@ -567,7 +571,7 @@ QJSValue QJSValue::callAsConstructor(const QJSValueList &args)
     if (!f)
         return QJSValue();
 
-    ExecutionEngine *engine = d->engine;
+    ExecutionEngine *engine = d->engine();
     assert(engine);
 
     QVarLengthArray<Value> arguments(args.length());
@@ -575,7 +579,7 @@ QJSValue QJSValue::callAsConstructor(const QJSValueList &args)
         arguments[i] = args.at(i).d->getValue(engine);
 
     Value result;
-    QV4::ExecutionContext *ctx = d->engine->current;
+    QV4::ExecutionContext *ctx = engine->current;
     try {
         result = f->construct(ctx, arguments.data(), arguments.size());
     } catch (Exception &e) {
@@ -583,7 +587,7 @@ QJSValue QJSValue::callAsConstructor(const QJSValueList &args)
         result = e.value();
     }
 
-    return new QJSValuePrivate(engine, result);
+    return new QJSValuePrivate(result);
 }
 
 #ifdef QT_DEPRECATED
@@ -597,8 +601,9 @@ QJSValue QJSValue::callAsConstructor(const QJSValueList &args)
 */
 QJSEngine* QJSValue::engine() const
 {
-    if (d->engine)
-        return d->engine->publicEngine;
+    QV4::ExecutionEngine *engine = d->engine();
+    if (engine)
+        return engine->publicEngine;
 }
 
 #endif // QT_DEPRECATED
@@ -615,7 +620,7 @@ QJSValue QJSValue::prototype() const
     Object *o = d->value.asObject();
     if (!o)
         return QJSValue();
-    return new QJSValuePrivate(d->engine, Value::fromObject(o->prototype));
+    return new QJSValuePrivate(Value::fromObject(o->prototype));
 }
 
 /*!
@@ -731,16 +736,17 @@ QJSValue QJSValue::property(const QString& name) const
     if (!o)
         return QJSValue();
 
-    String *s = d->engine->newString(name);
+    ExecutionEngine *engine = d->engine();
+    String *s = engine->newString(name);
     uint idx = s->asArrayIndex();
     if (idx < UINT_MAX)
         return property(idx);
 
-    s->makeIdentifier(d->engine->current);
-    QV4::ExecutionContext *ctx = d->engine->current;
+    s->makeIdentifier(engine->current);
+    QV4::ExecutionContext *ctx = engine->current;
     try {
         QV4::Value v = o->get(ctx, s);
-        return new QJSValuePrivate(d->engine, v);
+        return new QJSValuePrivate(v);
     } catch (QV4::Exception &e) {
         e.accept(ctx);
         return QJSValue();
@@ -765,10 +771,11 @@ QJSValue QJSValue::property(quint32 arrayIndex) const
     if (!o)
         return QJSValue();
 
-    QV4::ExecutionContext *ctx = d->engine->current;
+    ExecutionEngine *engine = d->engine();
+    QV4::ExecutionContext *ctx = engine->current;
     try {
-        QV4::Value v = arrayIndex == UINT_MAX ? o->get(ctx, ctx->engine->id_uintMax) : o->getIndexed(ctx, arrayIndex);
-        return new QJSValuePrivate(d->engine, v);
+        QV4::Value v = arrayIndex == UINT_MAX ? o->get(ctx, engine->id_uintMax) : o->getIndexed(ctx, arrayIndex);
+        return new QJSValuePrivate(v);
     } catch (QV4::Exception &e) {
         e.accept(ctx);
         return QJSValue();
@@ -792,14 +799,15 @@ void QJSValue::setProperty(const QString& name, const QJSValue& value)
     if (!o)
         return;
 
-    String *s = d->engine->newString(name);
+    ExecutionEngine *engine = d->engine();
+    String *s = engine->newString(name);
     uint idx = s->asArrayIndex();
     if (idx < UINT_MAX) {
         setProperty(idx, value);
         return;
     }
 
-    QV4::ExecutionContext *ctx = d->engine->current;
+    QV4::ExecutionContext *ctx = engine->current;
     s->makeIdentifier(ctx);
     try {
         o->put(ctx, s, value.d->value);
@@ -826,12 +834,13 @@ void QJSValue::setProperty(quint32 arrayIndex, const QJSValue& value)
     if (!o)
         return;
 
-    QV4::ExecutionContext *ctx = d->engine->current;
+    ExecutionEngine *engine = d->engine();
+    QV4::ExecutionContext *ctx = engine->current;
     try {
         if (arrayIndex != UINT_MAX)
             o->putIndexed(ctx, arrayIndex, value.d->value);
         else
-            o->put(ctx, ctx->engine->id_uintMax, value.d->value);
+            o->put(ctx, engine->id_uintMax, value.d->value);
     } catch (QV4::Exception &e) {
         e.accept(ctx);
     }
@@ -863,8 +872,9 @@ bool QJSValue::deleteProperty(const QString &name)
     if (!o)
         return false;
 
-    String *s = d->engine->newIdentifier(name);
-    return o->deleteProperty(d->engine->current, s);
+    ExecutionEngine *engine = d->engine();
+    String *s = engine->newIdentifier(name);
+    return o->deleteProperty(engine->current, s);
 }
 
 /*!
@@ -879,7 +889,8 @@ bool QJSValue::hasProperty(const QString &name) const
     if (!o)
         return false;
 
-    String *s = d->engine->newIdentifier(name);
+    ExecutionEngine *engine = d->engine();
+    String *s = engine->newIdentifier(name);
     return o->__hasProperty__(s);
 }
 
@@ -895,7 +906,8 @@ bool QJSValue::hasOwnProperty(const QString &name) const
     if (!o)
         return false;
 
-    String *s = d->engine->newIdentifier(name);
+    ExecutionEngine *engine = d->engine();
+    String *s = engine->newIdentifier(name);
     return o->__getOwnProperty__(s);
 }
 
index c085f39..441ab1a 100644 (file)
@@ -67,40 +67,35 @@ QT_BEGIN_NAMESPACE
 class QJSValuePrivate : public QV4::PersistentValuePrivate
 {
 public:
-    QJSValuePrivate(QV4::ExecutionEngine *e, const QV4::Value &v)
-        : PersistentValuePrivate(e, v)
-        , string(QString())
+    QJSValuePrivate(const QV4::Value &v)
+        : PersistentValuePrivate(v)
     {
         if (value.isDeleted())
             value = QV4::Value::undefinedValue();
     }
-    QJSValuePrivate(QV4::ExecutionEngine *e, QV4::Object *o)
-        : PersistentValuePrivate(e, QV4::Value::fromObject(o))
-        , string(QString())
+    QJSValuePrivate(QV4::Object *o)
+        : PersistentValuePrivate(QV4::Value::fromObject(o))
     {}
-    QJSValuePrivate(QV4::ExecutionEngine *e, QV4::String *s)
-        : PersistentValuePrivate(e, QV4::Value::fromString(s))
-        , string(QString())
-    {}
-    QJSValuePrivate(const QV4::Value &v)
-        : PersistentValuePrivate(v)
-        , string(QString())
+    QJSValuePrivate(QV4::String *s)
+        : PersistentValuePrivate(QV4::Value::fromString(s))
     {}
     QJSValuePrivate(const QString &s)
         : PersistentValuePrivate()
-        , string(s)
+        , string(0, s)
     {
         value = QV4::Value::fromString(&string);
     }
 
     QV4::Value getValue(QV4::ExecutionEngine *e) {
-        if (value.asString() == &string) {
-            engine = e;
+        if (value.asString() == &string)
             value = QV4::Value::fromString(e->newString(string.toQString()));
-        }
         return value;
     }
 
+    QV4::ExecutionEngine *engine() const {
+        return value.engine();
+    }
+
     static QJSValuePrivate *get(const QJSValue &v) { return v.d; }
 
     QV4::String string;
index ecc2cd7..a547918 100644 (file)
@@ -176,10 +176,12 @@ QJSValue QJSValueIterator::value() const
         return QJSValue();
 
     QV4::Object *o = d_ptr->iterator.object;
+    QV4::ExecutionContext *ctx = o->internalClass->engine->current;
     try {
-        QV4::Value v = o->getValue(o->internalClass->engine->current, d_ptr->currentValue, d_ptr->currentAttributes);
-        return new QJSValuePrivate(o->internalClass->engine, v);
+        QV4::Value v = o->getValue(ctx, d_ptr->currentValue, d_ptr->currentAttributes);
+        return new QJSValuePrivate(v);
     } catch (QV4::Exception &e) {
+        e.accept(ctx);
         return QJSValue();
     }
 }
index 5295ff9..de1637c 100644 (file)
@@ -150,7 +150,7 @@ QV8Engine::QV8Engine(QJSEngine* qq)
     QV8GCCallback::registerGcPrologueCallback();
     m_strongReferencer = qPersistentNew(v8::Object::New());
 
-    m_bindingFlagKey = QV4::PersistentValue(m_v4Engine, QV4::Value::fromString(m_v4Engine->current, QStringLiteral("qml::binding")));
+    m_bindingFlagKey = QV4::Value::fromString(m_v4Engine->current, QStringLiteral("qml::binding"));
 
     m_contextWrapper.init(this);
     m_qobjectWrapper.init(this);
@@ -383,8 +383,7 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant)
         } else if (type == qMetaTypeId<QJSValue>()) {
             const QJSValue *value = reinterpret_cast<const QJSValue *>(ptr);
             QJSValuePrivate *valuep = QJSValuePrivate::get(*value);
-            valuep->engine = m_v4Engine;
-            return valuep->getValue(valuep->engine);
+            return valuep->getValue(m_v4Engine);
         } else if (type == qMetaTypeId<QList<QObject *> >()) {
             // XXX Can this be made more by using Array as a prototype and implementing
             // directly against QList<QObject*>?
@@ -677,7 +676,7 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
 
         QV4::Value result = evaluateScript(QStringLiteral(FREEZE_SOURCE), 0);
         Q_ASSERT(result.asFunctionObject());
-        m_freezeObject = QV4::PersistentValue(m_v4Engine, result);
+        m_freezeObject = result;
 #undef FREEZE_SOURCE
     }
 }
@@ -1226,7 +1225,7 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) {
         *reinterpret_cast<void* *>(data) = 0;
         return true;
     } else if (type == qMetaTypeId<QJSValue>()) {
-        *reinterpret_cast<QJSValue*>(data) = QJSValuePrivate::get(new QJSValuePrivate(m_v4Engine, value));
+        *reinterpret_cast<QJSValue*>(data) = QJSValuePrivate::get(new QJSValuePrivate(value));
         return true;
     }
 
@@ -1348,12 +1347,12 @@ QObject *QV8Engine::qtObjectFromJS(const QV4::Value &value)
 
 QJSValue QV8Engine::scriptValueFromInternal(const QV4::Value &value) const
 {
-    return new QJSValuePrivate(m_v4Engine, value);
+    return new QJSValuePrivate(value);
 }
 
 QJSValue QV8Engine::newArray(uint length)
 {
-    return new QJSValuePrivate(m_v4Engine, v8::Array::New(length).get()->v4Value());
+    return new QJSValuePrivate(v8::Array::New(length).get()->v4Value());
 }
 
 void QV8Engine::startTimer(const QString &timerName)
index 6fe8721..e863747 100644 (file)
@@ -2141,7 +2141,7 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, v8::Handle<v8::Val
     if (type != 0) { cleanup(); type = 0; }
 
     if (callType == qMetaTypeId<QJSValue>()) {
-        qjsValuePtr = new (&allocData) QJSValue(new QJSValuePrivate(QV8Engine::getV4(engine), value.get()->v4Value()));
+        qjsValuePtr = new (&allocData) QJSValue(new QJSValuePrivate(value.get()->v4Value()));
         type = qMetaTypeId<QJSValue>();
     } else if (callType == QMetaType::Int) {
         intValue = quint32(value->Int32Value());