[Kst] kdeextragear-2/kst/kst/extensions/js
George Staikos
staikos at kde.org
Tue Mar 29 06:59:49 CEST 2005
CVS commit by staikos:
indexing for vectors - to set and get values
M +52 -0 bind_vector.cpp 1.4
M +3 -0 bind_vector.h 1.4
--- kdeextragear-2/kst/kst/extensions/js/bind_vector.cpp #1.3:1.4
@@ -94,4 +94,56 @@ KJS::Value KstBindVector::call(KJS::Exec
+KJS::Value KstBindVector::get(KJS::ExecState *exec, const KJS::Identifier &propertyName) const {
+ return KstBinding::get(exec, propertyName);
+}
+
+
+KJS::Value KstBindVector::getPropertyByIndex(KJS::ExecState *exec, unsigned propertyName) const {
+ double rc = KST::NOPOINT;
+ if (!_v) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+ exec->setException(eobj);
+ return KJS::Number(rc);
+ }
+
+ _v->readLock();
+ if (propertyName < unsigned(_v->length())) {
+ rc = _v->value()[propertyName];
+ } else {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::RangeError);
+ exec->setException(eobj);
+ }
+ _v->readUnlock();
+
+ return KJS::Number(rc);
+}
+
+
+void KstBindVector::putPropertyByIndex(KJS::ExecState *exec, unsigned propertyName, const KJS::Value &value, int attr) {
+ Q_UNUSED(attr)
+ if (!_v) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+ exec->setException(eobj);
+ return;
+ }
+
+ if (value.type() != KJS::NumberType) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+ exec->setException(eobj);
+ return;
+ }
+
+ _v->writeLock();
+ if (propertyName < unsigned(_v->length())) {
+ _v->value()[propertyName] = value.toNumber(exec);
+ } else {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::RangeError);
+ exec->setException(eobj);
+ }
+
+ _v->writeUnlock();
+}
+
+
void KstBindVector::addBindings(KJS::ExecState *exec, KJS::Object& obj) {
for (int i = 0; Bindings[i].name != 0L; ++i) {
--- kdeextragear-2/kst/kst/extensions/js/bind_vector.h #1.3:1.4
@@ -36,4 +36,7 @@ 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);
KJS::Value length(KJS::ExecState *exec, const KJS::List& args);
More information about the Kst
mailing list