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::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; }
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); }
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; }
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); }
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::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)); }
bool SaxHandler::characters( const QString &chars ) { if ( !jshandler.isValid() ) { error = ErrorNoHandler; return false; } KJS::Identifier funName("characters"); if ( !jshandler.hasProperty(exec, funName) ) return QXmlDefaultHandler::characters( chars ); KJS::Object fun = jshandler.get(exec, funName).toObject( exec ); if ( !fun.implementsCall() ) { error = ErrorNotCallable; return false; } KJS::List args; args.append( KJS::String(chars) ); KJS::Value ret = fun.call( exec, jshandler, args ); return ret.toBoolean( exec ); }
KJS::JSValue *KJSEmbed::convertToValue(KJS::ExecState *exec, const QVariant &value) { #ifdef KJSEMBED_VARIANT_DEBUG qDebug() << "KJSEmbed::convertToValue typeid=" << value.type() << "typename=" << value.typeName() << "toString=" << value.toString(); #endif KJS::JSValue *returnValue; switch (value.type()) { case QVariant::Invalid: returnValue = KJS::jsNull(); break; case QVariant::Int: returnValue = KJS::jsNumber(value.value<int>()); break; case QVariant::UInt: returnValue = KJS::jsNumber(value.value<unsigned int>()); break; case QVariant::LongLong: returnValue = KJS::jsNumber(value.value<qlonglong>()); break; case QVariant::ULongLong: returnValue = KJS::jsNumber(value.value<qulonglong>()); break; case QVariant::Double: returnValue = KJS::jsNumber(value.value<double>()); break; case QVariant::Bool: returnValue = KJS::jsBoolean(value.value<bool>()); break; case QVariant::ByteArray: returnValue = KJS::jsString(QString(value.value<QByteArray>())); break; case QVariant::String: returnValue = KJS::jsString(value.value<QString>()); break; case QVariant::StringList: { KJS::List items; QStringList lst = value.value<QStringList>(); QStringList::Iterator idx = lst.begin(); for (; idx != lst.end(); ++idx) { items.append(KJS::jsString((*idx))); } returnValue = exec->lexicalInterpreter()->builtinArray()->construct(exec, items); break; } case QVariant::Date: // fall through case QVariant::DateTime: // fall through case QVariant::Time: { QDateTime dt = QDateTime::currentDateTime(); if (value.type() == QVariant::Date) { dt.setDate(value.toDate()); } else if (value.type() == QVariant::Time) { dt.setTime(value.toTime()); } else { dt = value.toDateTime(); } KJS::List items; items.append(KJS::jsNumber(dt.date().year())); items.append(KJS::jsNumber(dt.date().month() - 1)); items.append(KJS::jsNumber(dt.date().day())); items.append(KJS::jsNumber(dt.time().hour())); items.append(KJS::jsNumber(dt.time().minute())); items.append(KJS::jsNumber(dt.time().second())); items.append(KJS::jsNumber(dt.time().msec())); returnValue = exec->lexicalInterpreter()->builtinDate()->construct(exec, items); break; } case QVariant::List: { KJS::List items; QList<QVariant> lst = value.toList(); foreach (const QVariant &item, lst) { items.append(convertToValue(exec, item)); } returnValue = exec->lexicalInterpreter()->builtinArray()->construct(exec, items); break; } case QVariant::Map: { QMap<QString, QVariant> map = value.toMap(); QMap<QString, QVariant>::Iterator idx = map.begin(); KJS::JSObject *obj = exec->lexicalInterpreter()->builtinObject()->construct(exec, KJS::List()); for (; idx != map.end(); ++idx) { obj->put(exec, KJS::Identifier(toUString(idx.key())), convertToValue(exec, idx.value())); } returnValue = obj; break; } default: { if (value.canConvert< QWidget * >()) { QWidget *widget = qvariant_cast< QWidget * >(value); returnValue = widget ? createQObject(exec, widget, KJSEmbed::ObjectBinding::CPPOwned) : KJS::jsNull(); } else if (value.canConvert< QObject * >()) { QObject *object = qvariant_cast< QObject * >(value); returnValue = object ? createQObject(exec, object, KJSEmbed::ObjectBinding::CPPOwned) : KJS::jsNull(); } else { returnValue = createVariant(exec, value.typeName(), value); if (returnValue->isNull()) { returnValue = KJS::jsString(value.value<QString>()); } } break; } }
int main( int argc, char **argv ) { QTime time; time.start(); #ifdef _WIN32 # ifdef CONSOLEIO RedirectIOToConsole(); # endif #endif // Handle arguments QString appName = argv[0]; QStringList args; for (int i = 1; i < argc; i++ ) { args << argv[i]; } QString script; KJS::List scriptArgs; bool gui = true; #ifndef QT_ONLY /* #ifdef __GNUC__ #warning "KDE Support enabled" #endif */ bool kde = true; #else /* #ifdef __GNUC__ #warning "KDE Support disabled" #endif */ #endif if (argc > 1) { while (!args.isEmpty()) { QString arg = args.takeFirst(); if (arg.contains('-')) { if ((arg == "--version") || (arg == "-v")) { printf("Qt: %s\n", qVersion()); #ifndef QT_ONLY printf("KDE: %s\n", KDE_VERSION_STRING); #endif return 0; } if ((arg == "--exec") || (arg == "-e")) { gui = false; } else if ((arg == "--interactive") || (arg == "-i")) (*KJSEmbed::conout()) << "Interactive"; #ifndef QT_ONLY else if ((arg == "-n") || (arg == "--no-kde")) { kde = false; } #endif else { printUsage(appName); return 0; } } else { if (!script.isEmpty()) scriptArgs.append(KJS::jsString(arg)); else script = arg; } } } else { printUsage(appName); return 0; } // Setup QApplication QCoreApplication *app; #ifndef QT_ONLY if (kde) { KAboutData aboutData( "kjscmd", 0, ki18n("KJSCmd"), "0.2", ki18n("" "Utility for running KJSEmbed scripts \n" ), KAboutData::License_LGPL, ki18n("(C) 2005-2006 The KJSEmbed Authors") ); KCmdLineOptions options; options.add("e", ki18n("Execute script without gui support")); options.add("exec", ki18n("Execute script without gui support")); options.add("i", ki18n("start interactive kjs interpreter")); options.add("interactive", ki18n("start interactive kjs interpreter")); options.add("n", ki18n("start without KDE KApplication support.")); options.add("no-kde", ki18n("start without KDE KApplication support.")); options.add("!+command", ki18n("Script to execute")); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KCmdLineArgs::init( argc, argv, &aboutData ); app = new KApplication(gui); } else #endif if (gui) { qDebug("no KDE"); app = new QApplication( argc, argv ); dynamic_cast<QApplication*>(app)->connect( app, SIGNAL(lastWindowClosed()), SLOT(quit()) ); } else { qDebug("no GUI"); app = new QCoreApplication(argc, argv); } qDebug(" New %s %dms", app->metaObject()->className(), time.elapsed()); app->setApplicationName( appName ); // Setup Interpreter time.restart(); Engine kernel; qDebug(" New engine %dms", time.elapsed()); time.restart(); KJS::Interpreter *js = kernel.interpreter(); js->setShouldPrintExceptions(true); KJS::ExecState *exec = js->globalExec(); // Publish bindings KJS::JSObject *appObject = kernel.addObject( app, "Application" ); KJS::JSObject *argObject = js->builtinArray()->construct( exec, scriptArgs ); appObject->put( exec, "args", argObject ); Engine::ExitStatus result = Engine::Failure; if (!script.isEmpty()) { result = kernel.runFile(toUString(script)); } else // exec shell { result = kernel.runFile( ":/console.js" ); } if ( result != Engine::Success ) { KJS::Completion jsres = kernel.completion(); (*KJSEmbed::conerr()) << toQString(jsres.value()->toString(exec)) << endl; } return (int)result; }
Kate::JS::ToolView::ToolView(KJS::Object constr, KJS::ExecState *exec, KJSEmbed::JSFactory *factory, KJS::List parameters, const char *name):QVBox(0,name) { parameters.append(factory->createProxy(exec,this)); handler=constr.construct(exec,parameters); }
void PluginKateKJSWrapper::addView(Kate::MainWindow *win) { PluginKateKJSWrapperView * view=getViewObject(win); // this is needed to ensure correct caching the javascript object KJS::Interpreter *js = m_part->interpreter(); KJS::ExecState *exec = js->globalExec(); exec->clearException(); kdDebug()<<"****************************************************************************************"<<endl; kdDebug()<<"PluginKateKJSWrapper::addView"<<endl; kdDebug()<<"****************************************************************************************"<<endl; kdDebug()<<"checking for newWindowHandler"<<endl; if (!m_newWindowHandler.isNull()) { KJS::List param; param.append(view->winObj); KJS::Object newWinFunc=m_newWindowHandler.toObject(exec); if (exec->hadException()) { exec->clearException(); } else { if (newWinFunc.implementsCall()) { newWinFunc.call(exec,js->globalObject(),param); if (exec->hadException()) { kdDebug()<<"Error while calling newWindowHandler"<<endl; exec->clearException(); } } } } if (exec->hadException()) kdDebug()<<"void PluginKateKJSWrapper::addView(Kate::MainWindow *win): exec had an exception - 1"<<endl; kdDebug()<<"checking for toolview constructors"<<endl; if (! (m_toolViewConstructors.isNull() || (m_toolViewConstructors.type()==KJS::NullType))) { KJS::Object constrs=m_toolViewConstructors.toObject(exec); if (!exec->hadException()) { if (QString(constrs.classInfo()->className)=="Array") { kdDebug()<<"Toolview constructor array detected"<<endl; int size=constrs.get(exec,KJS::Identifier("length")).toInteger(exec); if (exec->hadException()) { exec->clearException(); kdDebug()<<"Error while retrieving array length"<<endl; } else { for (int i=0;i<size;i++) { KJS::Object constrO=constrs.get(exec,i).toObject(exec); if (exec->hadException()) { exec->clearException(); } else { KMDI::ToolViewAccessor *w=createToolView(m_part->factory(),js,win,view->winObj,constrO); if (w) { view->toolviews.append(QGuardedPtr<KMDI::ToolViewAccessor>(w)); } exec->clearException(); } } } } else { kdDebug()<<"Single toolview constructor detected"<<endl; if (!constrs.implementsConstruct()) { kdWarning()<<"wrong object type"<<endl; } else { KMDI::ToolViewAccessor *w=createToolView(m_part->factory(),js,win,view->winObj,constrs); if (w) { view->toolviews.append(QGuardedPtr<KMDI::ToolViewAccessor>(w)); } exec->clearException(); } } } } else kdDebug()<<"void PluginKateKJSWrapper::addView(Kate::MainWindow *win): no toolview constructors"<<endl; if (exec->hadException()) kdDebug()<<"void PluginKateKJSWrapper::addView(Kate::MainWindow *win): exec had an exception - 2"<<endl; view->setInstance (new KInstance("kate")); view->setXMLFile(QString("plugins/%1/%2.rc").arg(m_scriptname).arg(m_scriptname)); win->guiFactory()->addClient (view); }
void KSVGLoader::slotResult(KIO::Job *job) { if(job == m_job) { if(m_job->error() == 0) { QString check = static_cast<KIO::TransferJob *>(job)->url().prettyURL(); if(check.contains(".svgz") || check.contains(".svg.gz")) { // decode the gzipped svg and emit it QIODevice *dev = KFilterDev::device(new QBuffer(m_data), "application/x-gzip"); dev->open(IO_ReadOnly); emit gotResult(dev); } else { m_job = 0; emit gotResult(new QBuffer(m_data)); m_data.resize(0); } } } else if(m_postUrlData.job == job) { // Notify that we're done KJS::List callBackArgs; callBackArgs.append(*m_postUrlData.status); m_postUrlData.status->put(m_postUrlData.exec, KJS::Identifier("success"), KJS::Boolean(true)); m_postUrlData.callBackFunction->call(m_postUrlData.exec, *m_postUrlData.callBackFunction, callBackArgs); } else { QMap<KIO::TransferJob *, ImageStreamMap *>::Iterator it; for(it = m_imageJobs.begin(); it != m_imageJobs.end(); ++it) { if(it.key() == job) { ImageStreamMap *streamMap = it.data(); QBuffer buffer(*(streamMap->data)); if(buffer.open(IO_ReadOnly)) { const char *imageFormat = QImageIO::imageFormat(&buffer); if(imageFormat != 0) { QImageIO imageIO(&buffer, imageFormat); // Gamma correction imageIO.setGamma(1/0.45454); if(imageIO.read()) { QImage *image = new QImage(imageIO.image()); image->detach(); (streamMap->imageElement)->setImage(image); } } buffer.close(); } (streamMap->data)->resize(0); m_imageJobs.remove(static_cast<KIO::TransferJob *>(job)); emit imageReady(streamMap->imageElement); break; } } } }
KJS::List SlotProxy::convertArguments(KJS::ExecState *exec, void **_a) { KJS::List args; int offset = metaObject()->indexOfMethod(m_signature.constData()); QMetaMethod method = metaObject()->method(offset); QList<QByteArray> params = method.parameterTypes(); int idx = 1; #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::convertArguments(): obj=" << this << " m_signature=" << m_signature << " offset=" << offset << " params=" << params; #endif foreach (const QByteArray ¶m, params) { #ifdef DEBUG_SLOTPROXY int type = QMetaType::type(param.constData()); qDebug("\tGot a %d - %s - _a[%d] = %p", type, param.data(), idx, _a[idx]); qDebug("\t QMetaType::type()=%d", QMetaType::type(QByteArray("Pinya::") + param.constData())); #endif int tp = QVariant::nameToType(param.constData()); switch (tp) { case QVariant::Int: args.append(KJS::jsNumber(*(int *)_a[idx])); break; case QVariant::UInt: args.append(KJS::jsNumber(*(uint *)_a[idx])); break; case QVariant::LongLong: args.append(KJS::jsNumber(*(qlonglong *)_a[idx])); break; case QVariant::ULongLong: args.append(KJS::jsNumber(*(qulonglong *)_a[idx])); break; case QVariant::Double: args.append(KJS::jsNumber(*(double *)_a[idx])); break; case QVariant::Bool: args.append(KJS::jsBoolean(*(bool *)_a[idx])); break; case QVariant::String: args.append(KJS::jsString((*reinterpret_cast<QString(*)>(_a[idx])))); break; case QVariant::UserType: { KJS::JSObject *returnValue; KJS::JSObject *parent = exec->dynamicInterpreter()->globalObject(); QByteArray typeName = param.constData(); bool isPtr = typeName.contains("*"); if (isPtr) { typeName.replace("*", ""); //krazy:exclude=doublequote_chars } #ifdef DEBUG_SLOTPROXY qDebug() << "\tQVariant::UserType: typeName=" << typeName << " param=" << param.constData() << " isPtr" << isPtr; #endif if (parent->hasProperty(exec, KJS::Identifier(toUString(typeName)))) { QObject *qObj; if (isPtr && ((qObj = *reinterpret_cast<QObject **>(_a[idx])) != 0)) { #ifdef DEBUG_SLOTPROXY qDebug() << "qObj=" << qObj; #endif Pointer<QObject> pov(*reinterpret_cast<QObject*(*)>(_a[idx])); returnValue = StaticConstructor::bind(exec, typeName, pov); if (returnValue) { args.append(returnValue); break; } else { #ifdef DEBUG_SLOTPROXY qDebug("\t\tNo binding retrieved"); #endif returnValue = StaticConstructor::construct(exec, parent, toUString(typeName)); if (returnValue) { if (QObjectBinding *objImp = KJSEmbed::extractBindingImp<QObjectBinding>(exec, returnValue)) { #ifdef DEBUG_SLOTPROXY qDebug() << "\t\t\tFound QObjectBinding"; #endif objImp->setOwnership(KJSEmbed::ObjectBinding::JSOwned); objImp->setObject(qObj); if (qObj->parent() != 0) { objImp->setOwnership(KJSEmbed::ObjectBinding::QObjOwned); } else { objImp->setOwnership(KJSEmbed::ObjectBinding::CPPOwned); } args.append(returnValue); break; } } } } } else { #ifdef DEBUG_SLOTPROXY qDebug("\t\tNo binding registered"); #endif KJS::JSObject *returnValue = 0; const int metaTypeId = QMetaType::type(param.constData()); if (QMetaType::typeFlags(metaTypeId) & QMetaType::PointerToQObject) { QObject *obj = (*reinterpret_cast< QObject*(*)>(_a[idx])); returnValue = KJSEmbed::createQObject(exec, obj, KJSEmbed::ObjectBinding::QObjOwned); } if (returnValue) { args.append(returnValue); break; } } } case QVariant::StringList: case QVariant::List: case QVariant::Map: default: //qDebug("\t\tconverting to variant"); QVariant variant(tp, _a[idx]); args.append(KJSEmbed::convertToValue(exec, variant)); break; } ++idx; }
void JSLazyEventListener::parseCode() const { if (!parsed) { KHTMLPart *part = qobject_cast<KHTMLPart*>(static_cast<Window*>(win.get())->part()); KJSProxy *proxy = 0L; if (part) proxy = part->jScript(); if (proxy) { KJS::ScriptInterpreter *interpreter = static_cast<KJS::ScriptInterpreter *>(proxy->interpreter()); ExecState *exec = interpreter->globalExec(); //KJS::Constructor constr(KJS::Global::current().get("Function").imp()); KJS::FunctionObjectImp *constr = static_cast<KJS::FunctionObjectImp*>(interpreter->builtinFunction()); KJS::List args; if (svg) args.append(jsString("evt")); else args.append(jsString("event")); args.append(jsString(code)); listener = constr->construct(exec, args, Identifier(UString(name)), url, lineNum); // ### is globalExec ok ? compareListenerImp = listener; if (exec->hadException()) { exec->clearException(); // failed to parse, so let's just make this listener a no-op listener = 0; } else if (!listener->inherits(&DeclaredFunctionImp::info)) { listener = 0;// Error creating function } else { DeclaredFunctionImp *declFunc = static_cast<DeclaredFunctionImp*>(listener.get()); if (originalNode) { // Add the event's home element to the scope // (and the document, and the form - see KJS::HTMLElement::eventHandlerScope) ScopeChain scope = declFunc->scope(); JSObject *thisObj = getDOMNode(exec, originalNode)->getObject(); if (thisObj) { static_cast<DOMNode*>(thisObj)->pushEventHandlerScope(exec, scope); declFunc->setScope(scope); } } } } // no more need to keep the unparsed code around code.clear(); if (listener) { static_cast<Window*>(win.get())->jsEventListeners.insert(QPair<void*, bool>(compareListenerImp.get(), true), (KJS::JSEventListener *)(this)); } parsed = true; } }