コード例 #1
0
KJS::List KJSEmbedPart::constructorList() const
{
    KJS::List items;

    KJS::Object obj = js->globalObject();
    KJS::ExecState *exec = js->globalExec();

    KJS::ReferenceList l = obj.propList( exec );
    KJS::ReferenceListIterator propIt = l.begin();
    while ( propIt != l.end() ) {

	KJS::Identifier name = propIt->getPropertyName( exec );

	if ( obj.hasProperty( exec, name ) ) {
	    KJS::Value v = obj.get( exec, name );
	    KJS::Object vobj = v.toObject( exec );

	    if ( vobj.implementsConstruct() )
		items.append( KJS::String( name.ustring() ) );
	}

	propIt++;
    }

    return items;
}
コード例 #2
0
    void JSObjectProxy::addBindingsClass( KJS::ExecState *exec, KJS::Object & /*object*/ ) {
        KJS::Identifier clazzid;
        QObject *o = obj;
        Bindings::BindingObject *bo = dynamic_cast<Bindings::BindingObject *>( o );
        if ( bo ) {
            clazzid = KJS::Identifier( bo->jsClassName() ? bo->jsClassName() : obj->className() );
        } else {
            clazzid = KJS::Identifier( obj->className() );
        }

        KJS::Object global = js->globalObject();
        if ( global.hasProperty( exec, clazzid ) ) {
            kdDebug( 80001 ) << "addBindingsClass() " << clazzid.qstring() << " already known" << endl;

            KJS::Object clazz = global.get( exec, clazzid ).toObject( exec );
            Bindings::JSFactoryImp *imp = dynamic_cast<Bindings::JSFactoryImp *>( clazz.imp() );
            if ( !imp ) {
                kdWarning() << "addBindingsClass() Class was not created by normal means" << endl;
                return ;
            }

            kdDebug( 80001 ) << "addBindingsClass() Adding enums" << endl;
            imp->setDefaultValue( js->builtinObject().construct( exec, KJS::List() ) );
            addBindingsEnum( exec, clazz );
        } else {
            kdWarning() << "addBindingsClass() " << clazzid.qstring() << " not known" << endl;
        }
    }
コード例 #3
0
ファイル: slotproxy.cpp プロジェクト: KDE/kjsembed
KJS::JSValue *SlotProxy::callMethod(const QByteArray &methodName, void **_a)
{
#ifdef DEBUG_SLOTPROXY
    qDebug() << "SlotProxy::callMethod(" << methodName << ",_a) obj=" << this;
#endif
    KJS::ExecState *exec = m_interpreter->globalExec();
    exec->clearException();

    // Crash
    // KJS::Interpreter::globalExec()->context().thisValue()
    KJS::List args = convertArguments(exec, _a);
    KJS::Identifier id = KJS::Identifier(KJS::UString(methodName.data()));
    KJS::JSObject *fun = m_object->get(exec, id)->toObject(exec);
    KJS::JSValue *retValue;
    if (!fun->implementsCall()) {
#ifdef DEBUG_SLOTPROXY
        qDebug() << "SlotProxy::callMethod got bad handler";
#endif
        QString msg = i18n("Bad slot handler: Object %1 Identifier %2 Method %3 Signature: %4.",
                           m_object->className().ascii(),
                           id.ascii(),
                           methodName.data(),
                           QString(m_signature));

        retValue = throwError(exec, KJS::TypeError, msg);
    } else {
        retValue = fun->call(exec, m_object, args);
    }

    if (exec->hadException()) {
#ifdef DEBUG_SLOTPROXY
        qDebug() << "SlotProxy::callMethod had exception";
#endif
        if (m_interpreter->shouldPrintExceptions()) {
            KJS::JSLock lock;
            KJS::JSObject *exceptObj = exec->exception()->toObject(exec);//retValue->toObject(exec);
            QString message = toQString(exceptObj->toString(exec));
            QString sourceURL = toQString(exceptObj->get(exec, "sourceURL")->toString(exec));
            int sourceId = exceptObj->get(exec, "sourceId")->toUInt32(exec);
            // would include the line number, but it's always last line of file
            int line = exceptObj->get(exec, "line")->toUInt32(exec);
            (*KJSEmbed::conerr()) << i18n("Exception calling '%1' slot from %2:%3:%4", QString(methodName), !sourceURL.isEmpty() ? sourceURL : QString::number(sourceId), line, message) << endl;
        }

        // clear it so it doesn't stop other things
        exec->clearException();

        return KJS::jsNull();
    } else {
        if (retValue->type() == 1 || retValue->type() == 0) {
            return KJS::jsNull();
        }
    }
    return retValue;
}
コード例 #4
0
ファイル: eventproxy.cpp プロジェクト: vasi/kdelibs
bool EventProxy::callHandler( QEvent *e )
{
// Be careful enabling this as if there are a lot of events then the event loop times
// out and the app crashes with 'Alarm Clock'.
//    qDebug("JSObjectEventProxy::callHandler() event type %d" , e->type() );

    KJS::ExecState *exec = m_interpreter->globalExec();
    KJS::Identifier id = JSEventMapper::mapper()->findEventHandler( e->type() );

    KJS::JSObject *jsobj(m_watch);
    KJS::JSObject *fun = jsobj->get(exec, id )->toObject( exec );

    KJS::JSValue *retValue;
    if ( !fun->implementsCall() )
    {
        QString msg = i18n( "Bad event handler: Object %1 Identifier %2 Method %3 Type: %4.",
          jsobj->className().ascii(),
          id.ascii(),
          fun->className().ascii(),
          e->type());
        retValue = throwError(exec, KJS::TypeError, msg);
    }
    else
    {
        // Process args
        KJS::List args;
        args.append( JSEventUtils::event(exec, e) );
        
        // Call handler
        retValue = fun->call( exec, jsobj, args );
    }
    
    if ( exec->hadException() ) 
    {
        if (m_interpreter->shouldPrintExceptions())
        {
            KJS::JSLock lock;
            KJS::JSObject* exceptObj = retValue->toObject(exec);
            QString message = toQString(exceptObj->toString(exec));
            QString sourceURL = toQString(exceptObj->get(exec, "sourceURL")->toString(exec));
            int sourceId = exceptObj->get(exec, "sourceId")->toUInt32(exec);
            int line = exceptObj->get(exec, "line")->toUInt32(exec);
            (*KJSEmbed::conerr()) << i18n("Exception calling '%1' function from %2:%3:%4", id.ascii(), !sourceURL.isEmpty() ? sourceURL : QString::number(sourceId), line, message) << endl;
        }
        
        
        // clear it so it doesn't stop other things
        exec->clearException();
        return false;
    }
  
    return true;
}
コード例 #5
0
ファイル: AtomicString.cpp プロジェクト: Gin-Rye/duibrowser
PassRefPtr<StringImpl> AtomicString::add(const KJS::Identifier& identifier)
{
    if (identifier.isNull())
        return 0;

    UString::Rep* string = identifier.ustring().rep();
    unsigned length = string->size();
    if (!length)
        return StringImpl::empty();

    HashAndCharacters buffer = { string->computedHash(), string->data(), length }; 
    pair<HashSet<StringImpl*>::iterator, bool> addResult = stringTable->add<HashAndCharacters, HashAndCharactersTranslator>(buffer);
    if (!addResult.second)
        return *addResult.first;
    return adoptRef(*addResult.first);
}
コード例 #6
0
KJS::Value KstBindWindowCollection::extract(KJS::ExecState *exec, const KJS::Identifier& item) const {
  KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(item.qstring()));
  if (w) {
    return KJS::Object(new KstBindWindow(exec, w));
  }
  return KJS::Undefined();
}
コード例 #7
0
KJS::Value KstBindPluginModuleCollection::extract(KJS::ExecState *exec, const KJS::Identifier& item) const {
  QString plugin = item.qstring();

  const QMap<QString,Plugin::Data>& pluginList = PluginCollection::self()->pluginList();

  for (QMap<QString,Plugin::Data>::ConstIterator it = pluginList.begin(); it != pluginList.end(); ++it) {
    if (it.data()._name == plugin) {
      return KJS::Object(new KstBindPluginModule(exec, it.data()));
    }
  }

  const KstPluginInfoList pluginInfo = KstDataObject::pluginInfoList();

  for (KstPluginInfoList::ConstIterator it = pluginInfo.begin(); it != pluginInfo.end(); ++it) {
    if (it.key() == plugin) {
      KstDataObjectPtr ptr = KstDataObject::plugin(it.key());
      if (ptr) {
        KstBasicPluginPtr bp = kst_cast<KstBasicPlugin>(ptr);
        if (bp) {
          return KJS::Object(new KstBindPluginModule(exec, bp));
        }
      }
    }
  }

  return KJS::Undefined();
}
コード例 #8
0
KJS::Value KstBindDataObjectCollection::extract(KJS::ExecState *exec, const KJS::Identifier& item) const {
    KstReadLocker rl(&KST::dataObjectList.lock());
    KstDataObjectPtr d = *KST::dataObjectList.findTag(item.qstring());
    if (d) {
        return KJS::Object(KstBindDataObject::bind(exec, d));
    }
    return KJS::Undefined();
}
コード例 #9
0
bool KstBindLegend::hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  QString prop = propertyName.qstring();
  for (int i = 0; legendProperties[i].name; ++i) {
    if (prop == legendProperties[i].name) {
      return true;
    }
  }

  return KstBindBorderedViewObject::hasProperty(exec, propertyName);
}
コード例 #10
0
bool KstBindTimeInterpretation::hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  QString prop = propertyName.qstring();
  for (int i = 0; timeInterpretationProperties[i].name; ++i) {
    if (prop == timeInterpretationProperties[i].name) {
      return true;
    }
  }

  return KstBinding::hasProperty(exec, propertyName);
}
コード例 #11
0
bool KstBindDataObjectCollection::hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
    QString prop = propertyName.qstring();
    for (int i = 0; dataObjectCollectionProperties[i].name; ++i) {
        if (prop == dataObjectCollectionProperties[i].name) {
            return true;
        }
    }

    return KstBindCollection::hasProperty(exec, propertyName);
}
コード例 #12
0
bool KstBindEllipse::hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  QString prop = propertyName.qstring();
  for (int i = 0; ellipseProperties[i].name; ++i) {
    if (prop == ellipseProperties[i].name) {
      return true;
    }
  }

  return KstBindViewObject::hasProperty(exec, propertyName);
}
コード例 #13
0
bool KstBindPoint::hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  QString prop = propertyName.qstring();
  for (int i = 0; pointProperties[i].name; ++i) {
    if (prop == pointProperties[i].name) {
      return true;
    }
  }

  return KstBinding::hasProperty(exec, propertyName);
}
コード例 #14
0
KJS::Value KstBindPluginModuleCollection::extract(KJS::ExecState *exec, const KJS::Identifier& item) const {
  const QMap<QString,Plugin::Data>& pluginList = PluginCollection::self()->pluginList();
  QString i = item.qstring();
  for (QMap<QString,Plugin::Data>::ConstIterator it = pluginList.begin(); it != pluginList.end(); ++it) {
    if (it.data()._name == i) {
      return KJS::Object(new KstBindPluginModule(exec, it.data()));
    }
  }
  return KJS::Undefined();
}
コード例 #15
0
    void JSObjectProxy::put( KJS::ExecState *exec,
                             const KJS::Identifier &p, const KJS::Value &v,
                             int attr ) {
        if ( !isAllowed( exec->interpreter() ) ) {
            kdWarning() << "JS put request from unknown interpreter, ignoring" << endl;
            return ;
        }

        if ( !policy->hasCapability( JSSecurityPolicy::CapabilitySetProperties ) ) {
            ObjectImp::put( exec, p, v, attr );
            return ;
        }

        if ( !obj ) {
            kdDebug( 80001 ) << "JS setting '" << p.ascii() << "' but qobj has died" << endl;
            ObjectImp::put( exec, p, v, attr );
            return ;
        }

        // Properties
        QMetaObject *meta = obj->metaObject();
        int propIndex = meta->findProperty( p.ascii(), true );
        if ( propIndex != -1 ) {
            QVariant val = convertToVariant( exec, v );
            if ( meta->property(propIndex, true)->isEnumType() ) {
                obj->setProperty( p.ascii(), val.toUInt() );
            } else if ( val.isValid() ) {
                obj->setProperty( p.ascii(), val );
            } else {
                kdWarning(80001) << "Error setting value." << endl;
            }
        } else {
            ObjectImp::put( exec, p, v, attr );
        }

        if ( jspart->factory() ->eventMapper() ->isEventHandler( p ) ) {
            if ( evproxy.isNull() )
                evproxy = new KJSEmbed::JSObjectEventProxy( this );
            evproxy->addFilter( jspart->factory() ->eventMapper() ->findEventType( p ) );
            kdDebug( 80001 ) << "Adding event handler " << p.ascii() << endl;
        }
    }
コード例 #16
0
KJS::Value KstBindKst::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  if (propertyName.qstring() == "version") {
    return KJS::String(KSTVERSION);
  }

  if (propertyName.qstring() == "scriptVersion") {
    return KJS::Number(1);
  }

  QString prop = propertyName.qstring();
  for (int i = 0; kstProperties[i].name; ++i) {
    if (prop == kstProperties[i].name) {
      if (!kstProperties[i].get) {
        break;
      }
      return (this->*kstProperties[i].get)(exec);
    }
  }
  
  return KstBinding::get(exec, propertyName);
}
コード例 #17
0
    KJS::Value JSObjectProxy::get( KJS::ExecState *exec, const KJS::Identifier &p ) const {
            if ( !isAllowed( exec->interpreter() ) ) {
                kdWarning() << "JS get request from unknown interpreter, ignoring" << endl;
                return KJS::Null();
            }

            if ( !policy->isPropertyAllowed( this, obj, p.ascii() ) )
                return ObjectImp::get( exec, p );

            if ( !obj ) {
                kdDebug( 80001 ) << "JS getting '" << p.ustring().qstring() << "' but qobj has died" << endl;
                return ObjectImp::get( exec, p );
            }
            kdDebug( 80001 ) << "JS getting '" << p.ascii() << endl;

            // Properties
            QString prop = p.ustring().qstring();
            QMetaObject *meta = obj->metaObject();

            if ( meta->findProperty( p.ascii(), true ) != -1 ) {
                QVariant val = obj->property( prop.ascii() );
                kdDebug( 80001 ) << "JS getting '" << p.ascii() << "' ( " << val.typeName() << ")" << endl;

                return convertToValue( exec, val );
            }

            return ObjectImp::get
                       ( exec, p );
        }
コード例 #18
0
KJS::Value KstBindTimeInterpretation::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  QString prop = propertyName.qstring();
  for (int i = 0; timeInterpretationProperties[i].name; ++i) {
    if (prop == timeInterpretationProperties[i].name) {
      if (!timeInterpretationProperties[i].get) {
        break;
      }
      return (this->*timeInterpretationProperties[i].get)(exec);
    }
  }
  
  return KstBinding::get(exec, propertyName);
}
コード例 #19
0
KJS::Value KstBindPoint::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  QString prop = propertyName.qstring();
  for (int i = 0; pointProperties[i].name; ++i) {
    if (prop == pointProperties[i].name) {
      if (!pointProperties[i].get) {
        break;
      }
      return (this->*pointProperties[i].get)(exec);
    }
  }
  
  return KstBinding::get(exec, propertyName);
}
コード例 #20
0
void KstBindPlotLabel::put(KJS::ExecState *exec, const KJS::Identifier& propertyName, const KJS::Value& value, int attr) {
  QString prop = propertyName.qstring();
  for (int i = 0; plotLabelProperties[i].name; ++i) {
    if (prop == plotLabelProperties[i].name) {
      if (!plotLabelProperties[i].set) {
        break;
      }
      (this->*plotLabelProperties[i].set)(exec, value);
      return;
    }
  }

  KstBinding::put(exec, propertyName, value, attr);
}
コード例 #21
0
void KstBindTimeInterpretation::put(KJS::ExecState *exec, const KJS::Identifier& propertyName, const KJS::Value& value, int attr) {
  QString prop = propertyName.qstring();
  for (int i = 0; timeInterpretationProperties[i].name; ++i) {
    if (prop == timeInterpretationProperties[i].name) {
      if (!timeInterpretationProperties[i].set) {
        break;
      }
      (this->*timeInterpretationProperties[i].set)(exec, value);
      return;
    }
  }

  KstBinding::put(exec, propertyName, value, attr);
}
コード例 #22
0
bool KstBindKst::hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  QString prop = propertyName.qstring();
  for (int i = 0; kstProperties[i].name; ++i) {
    if (prop == kstProperties[i].name) {
      return true;
    }
  }

  if (prop == "version" || prop == "scriptVersion") {
    return true;
  }

  return KstBinding::hasProperty(exec, propertyName);
}
コード例 #23
0
KJS::Value KstBindWindow::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  if (!_d) {
    return KstBinding::get(exec, propertyName);
  }

  QString prop = propertyName.qstring();
  for (int i = 0; windowProperties[i].name; ++i) {
    if (prop == windowProperties[i].name) {
      if (!windowProperties[i].get) {
        break;
      }
      return (this->*windowProperties[i].get)(exec);
    }
  }

  return KstBinding::get(exec, propertyName);
}
コード例 #24
0
KJS::Value KstBindEllipse::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  if (!_d) {
    return KstBindViewObject::get(exec, propertyName);
  }

  QString prop = propertyName.qstring();
  for (int i = 0; ellipseProperties[i].name; ++i) {
    if (prop == ellipseProperties[i].name) {
      if (!ellipseProperties[i].get) {
        break;
      }
      return (this->*ellipseProperties[i].get)(exec);
    }
  }
  
  return KstBindViewObject::get(exec, propertyName);
}
コード例 #25
0
KJS::Value KstBindCurve::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  if (!_d) {
    return KstBindDataObject::get(exec, propertyName);
  }

  QString prop = propertyName.qstring();
  for (int i = 0; curveProperties[i].name; ++i) {
    if (prop == curveProperties[i].name) {
      if (!curveProperties[i].get) {
        break;
      }
      return (this->*curveProperties[i].get)(exec);
    }
  }
  
  return KstBindDataObject::get(exec, propertyName);
}
コード例 #26
0
KJS::Value KstBindDataObjectCollection::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
    if (id() > 0) {
        return KstBindCollection::get(exec, propertyName);
    }

    QString prop = propertyName.qstring();
    for (int i = 0; dataObjectCollectionProperties[i].name; ++i) {
        if (prop == dataObjectCollectionProperties[i].name) {
            if (!dataObjectCollectionProperties[i].get) {
                break;
            }
            return (this->*dataObjectCollectionProperties[i].get)(exec);
        }
    }

    return KstBindCollection::get(exec, propertyName);
}
コード例 #27
0
KJS::Value KstBindLegend::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
  if (!_d) {
    return KstBindBorderedViewObject::get(exec, propertyName);
  }

  QString prop = propertyName.qstring();
  for (int i = 0; legendProperties[i].name; ++i) {
    if (prop == legendProperties[i].name) {
      if (!legendProperties[i].get) {
        break;
      }
      return (this->*legendProperties[i].get)(exec);
    }
  }

  return KstBindBorderedViewObject::get(exec, propertyName);
}
コード例 #28
0
void KstBindEllipse::put(KJS::ExecState *exec, const KJS::Identifier& propertyName, const KJS::Value& value, int attr) {
  if (!_d) {
    KstBindViewObject::put(exec, propertyName, value, attr);
    return;
  }

  QString prop = propertyName.qstring();
  for (int i = 0; ellipseProperties[i].name; ++i) {
    if (prop == ellipseProperties[i].name) {
      if (!ellipseProperties[i].set) {
        break;
      }
      (this->*ellipseProperties[i].set)(exec, value);
      return;
    }
  }

  KstBindViewObject::put(exec, propertyName, value, attr);
}
コード例 #29
0
void KstBindPowerSpectrum::put(KJS::ExecState *exec, const KJS::Identifier& propertyName, const KJS::Value& value, int attr) {
  if (!_d) {
    KstBindDataObject::put(exec, propertyName, value, attr);
    return;
  }

  QString prop = propertyName.qstring();
  for (int i = 0; powerSpectrumProperties[i].name; ++i) {
    if (prop == powerSpectrumProperties[i].name) {
      if (!powerSpectrumProperties[i].set) {
        break;
      }
      (this->*powerSpectrumProperties[i].set)(exec, value);
      return;
    }
  }

  KstBindDataObject::put(exec, propertyName, value, attr);
}
コード例 #30
0
void KstBindWindow::put(KJS::ExecState *exec, const KJS::Identifier& propertyName, const KJS::Value& value, int attr) {
  if (!_d) {
    KstBinding::put(exec, propertyName, value, attr);
    return;
  }

  QString prop = propertyName.qstring();
  for (int i = 0; windowProperties[i].name; ++i) {
    if (prop == windowProperties[i].name) {
      if (!windowProperties[i].set) {
        break;
      }
      (this->*windowProperties[i].set)(exec, value);
      return;
    }
  }

  KstBinding::put(exec, propertyName, value, attr);
}