Implemented Template::Set
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 8 Mar 2013 09:47:18 +0000 (10:47 +0100)
committerLars Knoll <lars.knoll@digia.com>
Fri, 8 Mar 2013 16:03:03 +0000 (17:03 +0100)
Change-Id: I237fdf6acdfad9805306e4fc5f437457efa8eb7f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/v4/qv4v8.cpp
src/v4/qv4v8.h

index 15d0aed..1b96ffc 100644 (file)
@@ -1106,12 +1106,16 @@ void *External::Value() const
 
 void Template::Set(Handle<String> name, Handle<Value> value, PropertyAttribute attributes)
 {
-    Q_UNIMPLEMENTED();
+    Property p;
+    p.name = Persistent<String>::New(name);
+    p.value = Persistent<Value>::New(value);
+    p.attributes = attributes;
+    m_properties << p;
 }
 
 void Template::Set(const char *name, Handle<Value> value)
 {
-    Q_UNIMPLEMENTED();
+    Set(String::New(name), value);
 }
 
 
@@ -1486,6 +1490,14 @@ Local<Object> ObjectTemplate::NewInstance()
         pd->enumerable = acc.attribute & DontEnum ? VM::PropertyDescriptor::Disabled : VM::PropertyDescriptor::Enabled;
     }
 
+    foreach (const Property &p, m_properties) {
+        VM::PropertyDescriptor *pd = o->insertMember(p.name->asVMString());
+        *pd = VM::PropertyDescriptor::fromValue(p.value->vmValue());
+        pd->writable = p.attributes & ReadOnly ? VM::PropertyDescriptor::Disabled : VM::PropertyDescriptor::Enabled;
+        pd->configurable = p.attributes & DontDelete ? VM::PropertyDescriptor::Disabled : VM::PropertyDescriptor::Enabled;
+        pd->enumerable = p.attributes & DontEnum ? VM::PropertyDescriptor::Disabled : VM::PropertyDescriptor::Enabled;
+    }
+
     return Local<Object>::New(Value::fromVmValue(VM::Value::fromObject(o)));
 }
 
index 3a2966d..2b3fa7e 100644 (file)
@@ -1650,6 +1650,13 @@ class V8EXPORT Template : public Data {
   void Set(Handle<String> name, Handle<Value> value,
            PropertyAttribute attributes = None);
   void Set(const char* name, Handle<Value> value);
+
+  struct Property {
+      Persistent<String> name;
+      Persistent<Value> value;
+      PropertyAttribute attributes;
+  };
+  QVector<Property> m_properties;
  };
 
 DEFINE_REFCOUNTED_HANDLE_OPERATIONS(Template)