void QuickInterpreter::setTopLevelObjects(QObjectList *l) { QSEngine::init(); if(toplevel) for (int i=0; i<toplevel->size(); ++i) { QObject *o = toplevel->at(i); disconnect(o, SIGNAL(destroyed(QObject*)), this, SLOT(topLevelDestroyed(QObject*))); } delete toplevel; toplevel = new QObjectList; kids.clear(); if (!l) { toplevel->clear(); return; } QSObject global(env()->globalObject()); for (int i=0; i<toplevel->size(); ++i) { QObject *o = toplevel->at(i); if (hasTopLevelParent(o)) { continue; } kids.append(o->objectName()); connect(o, SIGNAL(destroyed(QObject *)), this, SLOT(topLevelDestroyed(QObject *))); global.put(o->objectName(), wrap(o)); staticGlobals << o->objectName(); toplevel->append(o); } delete l; }
void QuickInterpreter::setTopLevelObjects( QObjectList *l ) { QSEngine::init(); if( toplevel ) for( QObject *o = toplevel->first(); o; o = toplevel->next() ) disconnect( o, SIGNAL( destroyed( QObject* ) ), this, SLOT( topLevelDestroyed( QObject* ) ) ); delete toplevel; toplevel = new QObjectList; kids.clear(); if ( !l ) { toplevel->clear(); return; } QSObject global( env()->globalObject() ); QObject *o = l->first(); while ( o ) { if ( hasTopLevelParent( o ) ) { o = l->next(); continue; } kids.append( QString::fromLatin1(o->name()) ); connect( o, SIGNAL( destroyed( QObject * ) ), this, SLOT( topLevelDestroyed( QObject * ) ) ); global.put( QString::fromLatin1(o->name()), wrap( o ) ); staticGlobals << QString::fromLatin1(o->name()); toplevel->append( o ); o = l->next(); } delete l; }
void QuickInterpreter::addTopLevelObject(QObject *o) { QSEngine::init(); if (!toplevel) toplevel = new QObjectList; if (toplevel->indexOf(o) != -1) return; Q_ASSERT(!hasTopLevelParent(o)); for(int i=0; i<toplevel->size(); ++i) { QObject *cur = toplevel->at(i); if(cur == o) { return; } else if (cur && o && cur->objectName() == o->objectName()) { return; } } toplevel->append(o); kids.clear(); if (!toplevel) return; for (int i=0; i<toplevel->size(); ++i) { QObject *obj = toplevel->at(i); kids.append(obj->objectName()); } connect(o, SIGNAL(destroyed(QObject *)), this, SLOT(topLevelDestroyed(QObject *))); QSObject global = env()->globalObject(); const_cast<QSClass *>(global.objectType())->deleteMember(o->objectName()); QString context_name = o->objectName(); if (context_name.isEmpty()) { context_name = "unnamed"; } else { staticGlobals << context_name; } env()->globalObject().put(context_name, wrap(o)); }
QVariant QuickInterpreter::execute(QObject *obj, const QString &c, const QString &name) { QString code = c + QString::fromLatin1("\n"); int sourceId = debugger ? debugger->freeSourceId() : -1; if(!name.isNull() && sourceId >= 0) sourceIdNames[sourceId] = name; QSObject t, oldThis; if (obj) { if (!name.isNull() && sourceId >= 0) addSourceId(sourceId, obj); if (!hasTopLevelParent(obj)) addTopLevelObject(obj); t = wrap(obj); oldThis = env()->thisValue(); env()->setThisValue(t); } QSEngine::evaluate(t, code); // restore this value if (obj) env()->setThisValue(oldThis); if (hadError()) if(errorType() == QSErrParseError) emit parseError(); else emit runtimeError(); // Make sure we dereference the engines return value to avoid pooling QVariant a = convertToArgument(returnValue()); setReturnValue(QSObject()); return a; }
void QuickInterpreter::addTopLevelObject( QObject *o ) { QSEngine::init(); if ( !toplevel ) toplevel = new QObjectList; if ( toplevel->findRef( o ) != -1 ) return; if ( hasTopLevelParent( o ) ) return; for( QObject *cur = toplevel->first(); cur; cur = toplevel->next() ) { if( cur == o ) { return; } else if ( cur && o && QString::fromLatin1( cur->name() ) == QString::fromLatin1( o->name() ) ) { return; } } toplevel->append( o ); kids.clear(); if ( !toplevel ) return; QObject *obj = toplevel->first(); while ( obj ) { kids.append( QString::fromLatin1(obj->name()) ); obj = toplevel->next(); } connect( o, SIGNAL( destroyed( QObject * ) ), this, SLOT( topLevelDestroyed( QObject * ) ) ); QSObject global = env()->globalObject(); const_cast<QSClass *>(global.objectType())->deleteMember(o->name()); env()->globalObject().put( QString::fromLatin1(o->name()), wrap( o ) ); staticGlobals << QString::fromLatin1(o->name()); }