Implement gc() method
authorAaron Kennedy <aaron.kennedy@nokia.com>
Wed, 8 Jun 2011 00:40:14 +0000 (10:40 +1000)
committerAaron Kennedy <aaron.kennedy@nokia.com>
Wed, 8 Jun 2011 00:40:14 +0000 (10:40 +1000)
src/declarative/qml/qdeclarativeengine.cpp
src/declarative/qml/v8/qv8engine.cpp
src/declarative/qml/v8/qv8engine_p.h

index fa606ab..c34987e 100644 (file)
@@ -824,8 +824,7 @@ void QDeclarativeEngine::setOutputWarningsToStandardError(bool enabled)
 */
 void QDeclarativeEngine::collectGarbage()
 {
-    v8::V8::LowMemoryNotification();
-    while (!v8::V8::IdleNotification()) {}
+    QV8Engine::gc();
 }
 
 /*!
index 87bb1fc..693c8aa 100644 (file)
@@ -571,6 +571,7 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
     global->Set(v8::String::New("print"), printFn);
     global->Set(v8::String::New("console"), console);
     global->Set(v8::String::New("Qt"), qt);
+    global->Set(v8::String::New("gc"), V8FUNCTION(gc, this));
 
     // XXX mainthread only
     m_xmlHttpRequestData = qt_add_qmlxmlhttprequest(this);
@@ -608,6 +609,18 @@ void QV8Engine::freezeGlobal()
     test->Run();
 }
 
+void QV8Engine::gc()
+{
+    v8::V8::LowMemoryNotification();
+    while (!v8::V8::IdleNotification()) {}
+}
+
+v8::Handle<v8::Value> QV8Engine::gc(const v8::Arguments &args)
+{
+    gc();
+    return v8::Undefined();
+}
+
 v8::Handle<v8::Value> QV8Engine::print(const v8::Arguments &args)
 {
     QString result;
index 5aec866..5810b3e 100644 (file)
@@ -238,6 +238,8 @@ public:
     // Return the list of illegal id names (the names of the properties on the global object)
     const QSet<QString> &illegalNames() const;
 
+    static void gc();
+
 private:
     QDeclarativeEngine *m_engine;
     v8::Persistent<v8::Context> m_context;
@@ -263,6 +265,7 @@ private:
     void initializeGlobal(v8::Handle<v8::Object>);
     void freezeGlobal();
 
+    static v8::Handle<v8::Value> gc(const v8::Arguments &args);
     static v8::Handle<v8::Value> print(const v8::Arguments &args);
     static v8::Handle<v8::Value> isQtObject(const v8::Arguments &args);
     static v8::Handle<v8::Value> rgba(const v8::Arguments &args);