V8: Minor cleanup
authorSimon Hausmann <simon.hausmann@nokia.com>
Mon, 12 Dec 2011 14:32:17 +0000 (15:32 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 12 Dec 2011 15:52:08 +0000 (16:52 +0100)
Moved context creation into the QV8Engine constructor body. That will make
it easier to execute other initialization stuff in the future, such as
per-thread isolate creation.

Change-Id: Id4aef76d3664a3810143907d2201203b18745a47
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
src/declarative/qml/v8/qscriptoriginalglobalobject_p.h
src/declarative/qml/v8/qv8engine.cpp

index c0a761f..8156e22 100644 (file)
@@ -49,7 +49,8 @@ class QV8Engine;
 class QScriptOriginalGlobalObject
 {
 public:
-    inline QScriptOriginalGlobalObject(v8::Handle<v8::Context> context);
+    inline QScriptOriginalGlobalObject() {}
+    inline void init(v8::Handle<v8::Context> context);
     inline void destroy();
 
     inline QJSValue::PropertyFlags getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property);
@@ -63,7 +64,7 @@ private:
     v8::Persistent<v8::Object> m_globalObject;
 };
 
-QScriptOriginalGlobalObject::QScriptOriginalGlobalObject(v8::Handle<v8::Context> context)
+void QScriptOriginalGlobalObject::init(v8::Handle<v8::Context> context)
 {
     // Please notice that engine is not fully initialized at this point.
 
index e5bb26c..9ed14d3 100644 (file)
@@ -120,8 +120,6 @@ QV8Engine::QV8Engine(QJSEngine* qq, QJSEngine::ContextOwnership ownership)
     : q(qq)
     , m_engine(0)
     , m_ownsV8Context(ownership == QJSEngine::CreateNewContext)
-    , m_context((ownership == QJSEngine::CreateNewContext) ? v8::Context::New() : v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()))
-    , m_originalGlobalObject(m_context)
     , m_xmlHttpRequestData(0)
     , m_sqlDatabaseData(0)
     , m_listModelData(0)
@@ -136,7 +134,9 @@ QV8Engine::QV8Engine(QJSEngine* qq, QJSEngine::ContextOwnership ownership)
     v8::V8::SetFlagsFromString(v8args.constData(), v8args.length());
 
     v8::HandleScope handle_scope;
+    m_context = (ownership == QJSEngine::CreateNewContext) ? v8::Context::New() : v8::Persistent<v8::Context>::New(v8::Context::GetCurrent());
     qPersistentRegister(m_context);
+    m_originalGlobalObject.init(m_context);
     v8::Context::Scope context_scope(m_context);
 
     v8::V8::SetUserObjectComparisonCallbackFunction(ObjectComparisonCallback);