Convert context wrapper to QV4::PersistentValue
authorLars Knoll <lars.knoll@digia.com>
Wed, 8 May 2013 05:30:20 +0000 (07:30 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 8 May 2013 09:24:03 +0000 (11:24 +0200)
Change-Id: Ied2ac64aacf92ebaa606e478f51505d97953e6c0
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/v8/qv8contextwrapper.cpp
src/qml/qml/v8/qv8contextwrapper_p.h

index cc0e010..4bb89b8 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <private/qv4engine_p.h>
 #include <private/qv4value_p.h>
+#include <private/qv4functionobject_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -143,9 +144,6 @@ QV8ContextWrapper::~QV8ContextWrapper()
 
 void QV8ContextWrapper::destroy()
 {
-    qPersistentDispose(m_sharedContext);
-    qPersistentDispose(m_urlConstructor);
-    qPersistentDispose(m_constructor);
 }
 
 void QV8ContextWrapper::init(QV8Engine *engine)
@@ -155,27 +153,27 @@ void QV8ContextWrapper::init(QV8Engine *engine)
     v8::Handle<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
     ft->InstanceTemplate()->SetHasExternalResource(true);
     ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter);
-    m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+    m_constructor = ft->GetFunction()->v4Value();
     }
     {
     v8::Handle<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
     ft->InstanceTemplate()->SetHasExternalResource(true);
     ft->InstanceTemplate()->SetFallbackPropertyHandler(NullGetter, NullSetter);
-    m_urlConstructor = qPersistentNew<v8::Function>(ft->GetFunction());
+    m_urlConstructor = ft->GetFunction()->v4Value();
     }
     {
-    v8::Handle<v8::Object> sharedContext = m_constructor->NewInstance();
+    v8::Handle<v8::Object> sharedContext = m_constructor.value().asFunctionObject()->newInstance();
     QV8ContextResource *r = new QV8ContextResource(engine, 0, 0);
     r->isSharedContext = true;
     sharedContext->SetExternalResource(r);
-    m_sharedContext = qPersistentNew<v8::Object>(sharedContext);
+    m_sharedContext = sharedContext->v4Value();
     }
 }
 
 v8::Handle<v8::Object> QV8ContextWrapper::qmlScope(QQmlContextData *ctxt, QObject *scope)
 {
     // XXX NewInstance() should be optimized
-    v8::Handle<v8::Object> rv = m_constructor->NewInstance();
+    v8::Handle<v8::Object> rv = m_constructor.value().asFunctionObject()->newInstance();
     QV8ContextResource *r = new QV8ContextResource(m_engine, ctxt, scope);
     rv->SetExternalResource(r);
     return rv;
@@ -189,7 +187,7 @@ v8::Handle<v8::Object> QV8ContextWrapper::urlScope(const QUrl &url)
     context->isJSContext = true;
 
     // XXX NewInstance() should be optimized
-    v8::Handle<v8::Object> rv = m_urlConstructor->NewInstance();
+    v8::Handle<v8::Object> rv = m_urlConstructor.value().asFunctionObject()->newInstance();
     QV8ContextResource *r = new QV8ContextResource(m_engine, context, 0, true);
     rv->SetExternalResource(r);
     return rv;
index 8a0fbae..be62a0b 100644 (file)
@@ -57,6 +57,8 @@
 #include <private/qtqmlglobal_p.h>
 #include <private/qv8_p.h>
 
+#include <private/qv4value_p.h>
+
 QT_BEGIN_NAMESPACE
 
 class QUrl;
@@ -83,7 +85,7 @@ public:
     QQmlContextData *callingContext();
     QQmlContextData *context(v8::Handle<v8::Value>);
 
-    inline v8::Handle<v8::Object> sharedContext() const;
+    inline QV4::Value sharedContext() const;
 
     void takeContextOwnership(v8::Handle<v8::Object> qmlglobal);
 
@@ -100,12 +102,12 @@ private:
                                         const v8::AccessorInfo &info);
 
     QV8Engine *m_engine;
-    v8::Persistent<v8::Function> m_constructor;
-    v8::Persistent<v8::Function> m_urlConstructor;
-    v8::Persistent<v8::Object> m_sharedContext;
+    QV4::PersistentValue m_constructor;
+    QV4::PersistentValue m_urlConstructor;
+    QV4::PersistentValue m_sharedContext;
 };
 
-v8::Handle<v8::Object> QV8ContextWrapper::sharedContext() const
+QV4::Value QV8ContextWrapper::sharedContext() const
 {
     return m_sharedContext;
 }