Move QV8Engine::freezeObject over to use v4 APIs
authorLars Knoll <lars.knoll@digia.com>
Sun, 28 Apr 2013 01:13:28 +0000 (03:13 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 29 Apr 2013 11:11:49 +0000 (13:11 +0200)
Change-Id: I5ce76404db4ab386535df598a2528b0c3201f2ba
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/qqmlxmlhttprequest.cpp
src/qml/qml/v4vm/qv4value.cpp
src/qml/qml/v4vm/qv4value_p.h
src/qml/qml/v8/qv8engine.cpp
src/qml/qml/v8/qv8engine_p.h

index a0242db..ca2871d 100644 (file)
@@ -515,7 +515,7 @@ v8::Handle<v8::Object> Node::prototype(QV8Engine *engine)
                                       0, v8::External::New(engine));
         d->nodePrototype->SetAccessor(v8::String::New("attributes"), attributes,
                                       0, v8::External::New(engine));
-        engine->freezeObject(d->nodePrototype);
+        engine->freezeObject(d->nodePrototype->v4Value());
     }
     return d->nodePrototype;
 }
@@ -565,7 +565,7 @@ v8::Handle<v8::Object> Element::prototype(QV8Engine *engine)
         d->elementPrototype->SetPrototype(Node::prototype(engine));
         d->elementPrototype->SetAccessor(v8::String::New("tagName"), nodeName,
                                          0, v8::External::New(engine));
-        engine->freezeObject(d->elementPrototype);
+        engine->freezeObject(d->elementPrototype->v4Value());
     }
     return d->elementPrototype;
 }
@@ -582,7 +582,7 @@ v8::Handle<v8::Object> Attr::prototype(QV8Engine *engine)
                                       0, v8::External::New(engine));
         d->attrPrototype->SetAccessor(v8::String::New("ownerElement"), ownerElement,
                                       0, v8::External::New(engine));
-        engine->freezeObject(d->attrPrototype);
+        engine->freezeObject(d->attrPrototype->v4Value());
     }
     return d->attrPrototype;
 }
@@ -633,7 +633,7 @@ v8::Handle<v8::Object> CharacterData::prototype(QV8Engine *engine)
                                                0, v8::External::New(engine));
         d->characterDataPrototype->SetAccessor(v8::String::New("length"), length,
                                                0, v8::External::New(engine));
-        engine->freezeObject(d->characterDataPrototype);
+        engine->freezeObject(d->characterDataPrototype->v4Value());
     }
     return d->characterDataPrototype;
 }
@@ -666,7 +666,7 @@ v8::Handle<v8::Object> Text::prototype(QV8Engine *engine)
                                                0, v8::External::New(engine));
         d->textPrototype->SetAccessor(v8::String::New("wholeText"), wholeText,
                                                0, v8::External::New(engine));
-        engine->freezeObject(d->textPrototype);
+        engine->freezeObject(d->textPrototype->v4Value());
     }
     return d->textPrototype;
 }
@@ -677,7 +677,7 @@ v8::Handle<v8::Object> CDATA::prototype(QV8Engine *engine)
     if (d->cdataPrototype.IsEmpty()) {
         d->cdataPrototype = qPersistentNew<v8::Object>(v8::Object::New());
         d->cdataPrototype->SetPrototype(Text::prototype(engine));
-        engine->freezeObject(d->cdataPrototype);
+        engine->freezeObject(d->cdataPrototype->v4Value());
     }
     return d->cdataPrototype;
 }
@@ -696,7 +696,7 @@ v8::Handle<v8::Object> Document::prototype(QV8Engine *engine)
                                           0, v8::External::New(engine));
         d->documentPrototype->SetAccessor(v8::String::New("documentElement"), documentElement, 
                                           0, v8::External::New(engine));
-        engine->freezeObject(d->documentPrototype);
+        engine->freezeObject(d->documentPrototype->v4Value());
     }
     return d->documentPrototype;
 }
@@ -858,7 +858,7 @@ v8::Handle<v8::Object> NamedNodeMap::prototype(QV8Engine *engine)
         ot->SetIndexedPropertyHandler(indexed, 0, 0, 0, 0, v8::External::New(engine));
         ot->SetFallbackPropertyHandler(named, 0, 0, 0, 0, v8::External::New(engine));
         d->namedNodeMapPrototype = qPersistentNew<v8::Object>(ot->NewInstance());
-        engine->freezeObject(d->namedNodeMapPrototype);
+        engine->freezeObject(d->namedNodeMapPrototype->v4Value());
     }
     return d->namedNodeMapPrototype;
 }
@@ -906,7 +906,7 @@ v8::Handle<v8::Object> NodeList::prototype(QV8Engine *engine)
         ot->SetAccessor(v8::String::New("length"), length, 0, v8::External::New(engine));
         ot->SetIndexedPropertyHandler(indexed, 0, 0, 0, 0, v8::External::New(engine));
         d->nodeListPrototype = qPersistentNew<v8::Object>(ot->NewInstance());
-        engine->freezeObject(d->nodeListPrototype);
+        engine->freezeObject(d->nodeListPrototype->v4Value());
     }
     return d->nodeListPrototype;
 }
index 28c609c..73ed5d3 100644 (file)
@@ -211,6 +211,11 @@ Value Value::property(ExecutionContext *ctx, String *name) const
 }
 
 
+PersistentValue::PersistentValue()
+    : d(new PersistentValuePrivate)
+{
+}
+
 PersistentValue::PersistentValue(ExecutionEngine *e, const Value &val)
     : d(new PersistentValuePrivate(e, val))
 {
index 16a01c8..0100b6b 100644 (file)
@@ -565,6 +565,7 @@ struct PersistentValuePrivate
 class PersistentValue
 {
 public:
+    PersistentValue();
     PersistentValue(ExecutionEngine *e, const Value &val);
     PersistentValue(const PersistentValue &other);
     PersistentValue &operator=(const PersistentValue &other);
index 421cfbe..4794c22 100644 (file)
@@ -186,8 +186,6 @@ QV8Engine::~QV8Engine()
     delete m_listModelData;
     m_listModelData = 0;
 
-    qPersistentDispose(m_freezeObject);
-
     qPersistentDispose(m_strongReferencer);
 
     m_jsonWrapper.destroy();
@@ -697,18 +695,17 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
                       "    }"\
                       "})"
 
-    v8::Local<v8::Script> freeze = v8::Script::New(v8::String::New(FREEZE_SOURCE));
-    v8::Local<v8::Value> result = freeze->Run();
-    Q_ASSERT(result->IsFunction());
-    m_freezeObject = qPersistentNew(v8::Local<v8::Function>::Cast(result));
+        QV4::Value result = evaluateScript(QStringLiteral(FREEZE_SOURCE), 0);
+        Q_ASSERT(result.asFunctionObject());
+        m_freezeObject = QV4::PersistentValue(m_v4Engine, result);
 #undef FREEZE_SOURCE
     }
 }
 
-void QV8Engine::freezeObject(v8::Handle<v8::Value> value)
+void QV8Engine::freezeObject(const QV4::Value &value)
 {
-    v8::Handle<v8::Value> args[] = { value };
-    m_freezeObject->Call(global(), 1, args);
+    QV4::Value args = value;
+    m_freezeObject->asFunctionObject()->call(m_v4Engine->rootContext, QV4::Value::fromObject(m_v4Engine->globalObject), &args, 1);
 }
 
 void QV8Engine::gc()
@@ -891,7 +888,7 @@ void QV8Engine::initQmlGlobalObject()
     v8::HandleScope handels;
     v8::Context::Scope contextScope(m_context);
     initializeGlobal(m_context->Global());
-    freezeObject(m_context->Global());
+    freezeObject(QV4::Value::fromObject(m_v4Engine->globalObject));
 }
 
 void QV8Engine::setEngine(QQmlEngine *engine)
index 163ed0a..8cb6d02 100644 (file)
@@ -79,6 +79,7 @@
 #include "qv8valuetypewrapper_p.h"
 #include "qv8sequencewrapper_p.h"
 #include "qv4jsonwrapper_p.h"
+#include <private/qv4value_p.h>
 
 namespace QV4 {
 struct ArrayObject;
@@ -309,7 +310,7 @@ public:
     QQmlContextData *callingContext();
 
     QV4::Value getOwnPropertyNames(const QV4::Value &o);
-    void freezeObject(v8::Handle<v8::Value>);
+    void freezeObject(const QV4::Value &value);
 
     QString toString(v8::Handle<v8::Value> string);
     QString toString(v8::Handle<v8::String> string);
@@ -471,7 +472,7 @@ protected:
     QV8SequenceWrapper m_sequenceWrapper;
     QV4JsonWrapper m_jsonWrapper;
 
-    v8::Persistent<v8::Function> m_freezeObject;
+    QV4::PersistentValue m_freezeObject;
 
     void *m_xmlHttpRequestData;