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; }
KJS::Object KstBindLegend::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() == 0 || args.size() > 2) { return createSyntaxError(exec); } KstViewObjectPtr view = extractViewObject(exec, args[0]); if (!view) { KstViewWindow *w = extractWindow(exec, args[0]); if (w) { view = w->view(); } else { return createTypeError(exec, 0); } } QString txt; if (args.size() == 2) { if (args[1].type() != KJS::StringType) { return createTypeError(exec, 1); } txt = args[1].toString(exec).qstring(); } KstViewLegendPtr b = new KstViewLegend; view->appendChild(b.data()); KstApp::inst()->paintAll(KstPainter::P_PAINT); return KJS::Object(new KstBindLegend(exec, b)); }
bool SaxHandler::startElement( const QString &ns, const QString &ln, const QString &qn, const QXmlAttributes &attrs ) { if ( !jshandler.isValid() ) { error = ErrorNoHandler; return false; } KJS::Identifier funName("startElement"); if ( !jshandler.hasProperty(exec, funName) ) return QXmlDefaultHandler::startElement( ns, ln, qn, attrs ); KJS::Object fun = jshandler.get(exec, funName).toObject( exec ); if ( !fun.implementsCall() ) { error = ErrorNotCallable; return false; } KJS::List args; args.append( KJS::String(ns) ); args.append( KJS::String(ln) ); args.append( KJS::String(qn) ); // TODO: XmlAttributes not yet supported KJS::Value ret = fun.call( exec, jshandler, args ); return ret.toBoolean( exec ); }
KJS::Value KstBindDataSource::frameCount(KJS::ExecState *exec, const KJS::List& args) { QString field; if (args.size() == 1) { if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Number(0); } field = args[0].toString(exec).qstring(); } else if (args.size() != 0) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires at most one argument."); exec->setException(eobj); return KJS::Number(0); } KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Number(0); } s->writeLock(); int rc = s->frameCount(field); s->unlock(); return KJS::Number(rc); }
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; }
static KJS::List listFromVariantArgs(KJS::ExecState *exec, const NPVariant *args, unsigned argCount) { KJS::List aList; unsigned i; const NPVariant *v = args; for (i = 0; i < argCount; i++) { aList.append (convertNPVariantToValue (exec, v)); v++; } return aList; }
KJS::Value QDirImp::entryInfoList_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; instance->entryInfoList( arg0, arg1 ); return KJS::Value(); // Returns 'const QFileInfoList *' }
KJS::Value QDirImp::encodedEntryList_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; instance->encodedEntryList( arg0, arg1 ); return KJS::Value(); // Returns 'QStrList' }
KJS::Value QDirImp::match_56( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; QString arg1 = (args.size() >= 2) ? args[1].toString(exec).qstring() : QString::null; bool ret; ret = instance->match( arg0, arg1 ); return KJS::Boolean( ret ); }
QStringList KJSEmbedPart::constructorNames() const { QStringList classes; KJS::List cons = constructorList(); KJS::ListIterator it = cons.begin(); while ( it != cons.end() ) { KJS::Value v = *it; classes += v.toString( js->globalExec() ).qstring(); it++; } return classes; }
KJS::Value QDirImp::exists_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; bool ret; ret = instance->exists( arg0, arg1 ); return KJS::Boolean( ret ); }
KJS::Value QDirImp::absFilePath_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; QString ret; ret = instance->absFilePath( arg0, arg1 ); return KJS::String( ret ); }
KJS::Object QDirLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const { JSOpaqueProxy * prx; if ( args.size() == 0 ) { prx = new JSOpaqueProxy( new QDir( QDir::current() ), "QDir" ); } else { QString arg0 = ( args.size() >= 1 ) ? args[ 0 ].toString( exec ).qstring() : QString::null; prx = new JSOpaqueProxy( new QDir( arg0 ), "QDir" ); } prx->setOwner( JSProxy::JavaScript ); KJS::Object proxyObj( prx ); addBindings( jspart, exec, proxyObj ); return proxyObj; }
KateKJSWrapperConfigPage::KateKJSWrapperConfigPage(KJS::Object pageConstructor,PluginKateKJSWrapper* parent, QWidget *parentWidget) : Kate::PluginConfigPage( parentWidget ),m_plugin(parent) { QVBoxLayout *l=new QVBoxLayout(this); l->setAutoAdd(true); l->activate(); KJS::Interpreter *js = parent->m_part->interpreter(); KJS::ExecState *exec = js->globalExec(); exec->clearException(); KJS::List param; param.append(parent->m_part->factory()->createProxy(exec,this,0)); m_pageObject=pageConstructor.construct(exec,param); }
KJS::Value KstBindDataVector::changeFrames(KJS::ExecState *exec, const KJS::List& args) { KstRVectorPtr v = makeDataVector(_d); if (!v) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Undefined(); } if (args.size() > 1) { if (args[0].type() != KJS::NumberType || args[1].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } KstWriteLocker wl(v); int start = d2i(args[0].toNumber(exec)); int count = d2i(args[1].toNumber(exec)); int skip = v->doSkip() ? v->skip() : -1; bool ave = v->doAve(); if (args.size() > 2) { if (args[2].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } skip = d2i(args[2].toNumber(exec)); if (args.size() > 3) { if (args[3].type() != KJS::BooleanType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } ave = d2i(args[3].toBoolean(exec)); } } v->changeFrames(start, count, skip, skip >= 0, ave); return KJS::Undefined(); } KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Undefined(); }
static KMDI::ToolViewAccessor *createToolView(KJSEmbed::JSFactory *factory,KJS::Interpreter *js, Kate::MainWindow *winN,KJS::Object win,KJS::Object viewConstructor) { KJS::List params; KJS::ExecState *exec = js->globalExec(); params.append(win); exec->clearException(); int dockPos; if (!viewConstructor.implementsConstruct()) return 0; KJS::Value dockPosV=viewConstructor.get(exec,KJS::Identifier("startPosition")); if (exec->hadException()) { dockPos=KDockWidget::DockLeft; exec->clearException(); } else { dockPos=dockPosV.toInteger(exec); if (exec->hadException()) { dockPos=KDockWidget::DockLeft; exec->clearException(); } } QString viewName; KJS::Value viewNameV=viewConstructor.get(exec,KJS::Identifier("name")); if (exec->hadException()) { viewName="kjs_unknown"; exec->clearException(); } else { viewName=QString( viewNameV.toString(exec).qstring() ); if (exec->hadException()) { viewName="kjs_unknown"; exec->clearException(); } } Kate::JS::ToolView *tv=new Kate::JS::ToolView(viewConstructor,exec,factory,params,viewName.utf8()); //params.append(factory->createProxy(exec,tv)); //KJS::Object otv=viewConstructor.construct(exec,params); if (exec->hadException()) { kdDebug()<<"Error while calling constructor"<<endl; delete tv; kdDebug()<<exec->exception().toString(exec).qstring()<<endl; exec->clearException(); return 0; } KMDI::ToolViewAccessor *tva=winN->toolViewManager()->addToolView((KDockWidget::DockPosition)dockPos,tv, tv->icon()?(*(tv->icon())):QPixmap(),tv->caption()); kdDebug()<<"****************************************************************************************"<<endl; kdDebug()<<"PluginKateKJSWrapper: Toolview has been added"<<endl; kdDebug()<<"****************************************************************************************"<<endl; return tva; }
KJS::Object KstBindDataSource::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() < 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Object(); } if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } QString file = args[0].toString(exec).qstring(); QString type; if (args.size() == 2) { if (args[1].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } type = args[1].toString(exec).qstring(); } bool newSource = false; KST::dataSourceList.lock().readLock(); KstDataSourcePtr ds = *KST::dataSourceList.findFileName(file); KST::dataSourceList.lock().unlock(); if (!ds) { ds = KstDataSource::loadSource(file, type); newSource = true; } if (!ds) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Object(); } if (newSource) { KST::dataSourceList.lock().writeLock(); KST::dataSourceList.append(ds); KST::dataSourceList.lock().unlock(); } return KJS::Object(new KstBindDataSource(exec, ds)); }
KJS::Value QDirImp::entryList_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; QStringList ret; ret = instance->entryList( arg0, arg1 ); return convertToValue( exec, ret ); }
KJS::Value KstBindCurve::yMinusErrorPoint(KJS::ExecState *exec, const KJS::List& args) { KstVCurvePtr d = makeCurve(_d); if (!d) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Undefined(); } if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument."); exec->setException(eobj); return KJS::Undefined(); } unsigned i = 0; if (args[0].type() != KJS::NumberType || !args[0].toUInt32(i)) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } KstReadLocker rl(d); double x, y, e; d->getEYMinusPoint(i, x, y, e); return KJS::Number(e); }
KJS::Value QDirImp::entryInfoList_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; int arg2 = (args.size() >= 3) ? args[2].toInteger(exec) : -1; instance->entryInfoList( arg0, arg1, arg2 ); return KJS::Value(); // Returns 'const QFileInfoList *' }
KJS::Value KstBindDataSource::samplesPerFrame(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument."); exec->setException(eobj); return KJS::Number(0); } if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Number(0); } KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Number(0); } s->writeLock(); int rc = s->samplesPerFrame(args[0].toString(exec).qstring()); s->unlock(); return KJS::Number(rc); }
KJS::Value KstBindDataSource::isValidField(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument."); exec->setException(eobj); return KJS::Boolean(false); } if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Boolean(false); } KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Boolean(false); } s->writeLock(); bool rc = s->isValidField(args[0].toString(exec).qstring()); s->unlock(); return KJS::Boolean(rc); }
KJS::Value KstBindKst::loadScript(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Undefined(); } if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } QString fn = args[0].toString(exec).qstring(); if (!QFile::exists(fn)) { // One day make this support KIO FIXME return KJS::Boolean(false); } if (_ext->part()->runFile(fn)) { // FIXME: add to the script registry } else { KJS::Completion c = _ext->part()->completion(); if (!c.isNull()) { QString err = c.toString(_ext->part()->globalExec()).qstring(); KstDebug::self()->log(i18n("Error running script %1: %2").arg(fn).arg(err), KstDebug::Error); } else { KstDebug::self()->log(i18n("Unknown error running script %1.").arg(fn), KstDebug::Error); } return KJS::Boolean(false); } return KJS::Boolean(true); }
KJS::Value QDirImp::rename_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; QString arg1 = (args.size() >= 2) ? args[1].toString(exec).qstring() : QString::null; bool arg2 = (args.size() >= 3) ? args[2].toBoolean(exec) : false; bool ret; ret = instance->rename( arg0, arg1, arg2 ); return KJS::Boolean( ret ); }
KJS::Value QDirImp::match_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { QStringList arg0; if ( args.size() >= 1 ) { // TODO: populate the list } QString arg1 = (args.size() >= 2) ? args[1].toString(exec).qstring() : QString::null; bool ret; ret = instance->match( arg0, arg1 ); return KJS::Boolean( ret ); }
KJS::Value KstBindDebug::clearNewError(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 0) { return createSyntaxError(exec); } KstDebug::self()->clearHasNewError(); return KJS::Undefined(); }
KJS::Value QDirImp::entryList_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) { QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; int arg2 = (args.size() >= 3) ? args[2].toInteger(exec) : -1; QStringList ret; ret = instance->entryList( arg0, arg1, arg2 ); return convertToValue( exec, ret ); }
KJS::Value KstBindDataSource::fieldList(KJS::ExecState *exec, const KJS::List& args) { Q_UNUSED(args) KJS::List rc; KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc)); } s->readLock(); QStringList l = s->fieldList(); s->unlock(); for (QStringList::ConstIterator i = l.begin(); i != l.end(); ++i) { rc.append(KJS::String(*i)); } return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc)); }
DOM::EventListener *KJSProxyImpl::createHTMLEventHandler(QString sourceUrl, QString code) { #ifdef KJS_DEBUGGER if (KJSDebugWin::instance()) KJSDebugWin::instance()->setNextSourceInfo(sourceUrl,m_handlerLineno); #else Q_UNUSED(sourceUrl); #endif initScript(); //KJS::Constructor constr(KJS::Global::current().get("Function").imp()); KJS::Object constr = m_script->builtinFunction(); KJS::List args; args.append(KJS::String("event")); args.append(KJS::String(code)); Object handlerFunc = constr.construct(m_script->globalExec(), args); // ### is globalExec ok ? return KJS::Window::retrieveWindow(m_part)->getJSEventListener(handlerFunc,true); }
KJS::Object KstBindPoint::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() == 0) { return KJS::Object(new KstBindPoint(exec, 0, 0)); } if (args.size() != 2) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Object(); } if (args[0].type() != KJS::NumberType || args[1].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } return KJS::Object(new KstBindPoint(exec, args[0].toNumber(exec), args[1].toNumber(exec))); }