Add automatic conversion from QV4::Value to v8::Handle<T>
authorLars Knoll <lars.knoll@digia.com>
Sun, 28 Apr 2013 19:25:45 +0000 (21:25 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 29 Apr 2013 11:15:09 +0000 (13:15 +0200)
This simplifies a lot of the code adaptations required to
move over to v4.

Change-Id: Id5454a2ecda9c3b7cbabf46638e7634968d24237
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/v4vm/qv4v8.cpp
src/qml/qml/v4vm/qv4v8_p.h

index a1b0aac..b476f39 100644 (file)
@@ -94,6 +94,11 @@ void gcUnprotect(void *memoryManager, void *handle)
             static_cast<QV4::MemoryManager *>(memoryManager)->unprotect(m);
 }
 
+quint64 qv8_get_value(const QV4::Value &v)
+{
+    return v.val;
+}
+
 struct V8AccessorGetter: FunctionObject {
     AccessorGetter getter;
     Persistent<Value> data;
index b46312d..5523866 100644 (file)
@@ -160,6 +160,8 @@ typedef void (*WeakReferenceCallback)(Persistent<Value> object,
     *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
   }
 
+Q_QML_EXPORT quint64 qv8_get_value(const QV4::Value &v);
+
 /**
  * An object reference managed by the v8 garbage collector.
  *
@@ -206,6 +208,11 @@ struct HandleOperations
         handle->val = *reinterpret_cast<quint64 *>(other);
     }
 
+    static void init(Handle<T> *handle, const QV4::Value &v)
+    {
+        handle->val = qv8_get_value(v);
+    }
+
     static void ref(Handle<T> *)
     {
     }
@@ -299,6 +306,10 @@ struct Handle {
         HandleOperations<T>::ref(this);
     }
 
+    Handle(const QV4::Value &v) {
+        HandleOperations<T>::init(this, v);
+    }
+
     Handle(const Handle<T> &other)
         : val(other.val)
     {