[Kst] kdeextragear-2/kst/kst/extensions/js

George Staikos staikos at kde.org
Tue Mar 29 08:06:05 CEST 2005


CVS commit by staikos: 

implement .length since we implement array indexing
-> length() is renamed to size() to avoid conflict


  M +17 -1     bind_vector.cpp   1.7
  M +1 -0      bind_vector.h   1.7


--- kdeextragear-2/kst/kst/extensions/js/bind_vector.cpp  #1.6:1.7
@@ -69,5 +69,5 @@ struct VBindings {
 static VBindings Bindings[] = {
   { "resize", &KstBindVector::resize },
-  { "length", &KstBindVector::length },
+  { "size", &KstBindVector::length },
   { "tagName", &KstBindVector::tagName },
   { "setTagName", &KstBindVector::setTagName },
@@ -102,4 +102,20 @@ KJS::Value KstBindVector::call(KJS::Exec
 
 
+KJS::Value KstBindVector::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
+  if (propertyName.qstring() == "length") {
+    if (!_v) {
+      KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+      exec->setException(eobj);
+      return KJS::Undefined();
+    }
+
+    _v->readLock();
+    int len = _v->length();
+    _v->readUnlock();
+    return KJS::Number(len);
+  }
+  return KstBinding::get(exec, propertyName);
+}
+
 KJS::Value KstBindVector::getPropertyByIndex(KJS::ExecState *exec, unsigned propertyName) const {
   double rc = KST::NOPOINT;

--- kdeextragear-2/kst/kst/extensions/js/bind_vector.h  #1.6:1.7
@@ -36,4 +36,5 @@ class KstBindVector : public KstBinding 
     KJS::Object construct(KJS::ExecState *exec, const KJS::List& args);
     KJS::Value call(KJS::ExecState *exec, KJS::Object& self, const KJS::List& args);
+    KJS::Value get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const;
     KJS::Value getPropertyByIndex(KJS::ExecState *exec, unsigned propertyName) const;
     void putPropertyByIndex(KJS::ExecState *exec, unsigned propertyName, const KJS::Value &value, int attr = KJS::None);




More information about the Kst mailing list