예제 #1
0
QSObject QSObject::getQualified(const QString &name) const
{
  QSObject obj = *this;
  QString s = name;

  // break up dotted notation ns like P1.P2.P3
  while (!s.isEmpty()) {
    int pos = s.find('.');
    if (pos < 0)
      pos = s.length();
    // don't overwrite any existing objects, reuse them
    QString cname = s.left(pos);
    QSObject tmpobj = obj.get(cname);

    // Search the class hieriarchy for member if undefined
    if (!tmpobj.isDefined()) {
      QSClass *base = obj.objectType()->base();
      while (base && !tmpobj.isDefined()) {
        tmpobj = base->get(&obj, cname);
        base = base->base();
      }
      if (!tmpobj.isDefined())
        return env()->createUndefined();
    }
    obj = tmpobj;
    s = s.mid(pos + 1);
  }
  return obj;
}
예제 #2
0
bool Debugger::setVar(const QString &ident, const QSObject &value)
{
  if (!eng || ident == QString::fromLatin1("this"))
    return false;
  int dot = ident.find('.');
  QString sub = dot > 0 ? ident.mid(0, dot) : ident;
  QSObject base;
  // resolve base
  if (sub == QString::fromLatin1("||Global||")) {
    base = env()->globalObject();
  } else if (sub == QString::fromLatin1("||Activation||")) {
    base = env()->currentScope();
  } else if (sub == QString::fromLatin1("this")) {
    base = env()->thisValue();
  } else {
    // return false;
    ScopeChain::const_iterator it = env()->scope().begin();
    for (it = env()->scope().begin(); it != env()->scope().end(); ++it) {
      if ((*it).hasProperty(sub)) {
        base = *it;
        break;
      }
    }
    if (it == env()->scope().end())
      return false;
#if 0 // ###
    const QSList *chain = Context::current()->pScopeChain();
    QSListIterator scope = chain->begin();
    while (scope != chain->end()) {
      if (scope->hasProperty(sub)) {
        base = *scope;
        break;
      }
      scope++;
    }
    if (scope == chain->end())
      return false;
#endif
  }
  // look up each part of a.b.c.
  while (dot > 0) {
    int olddot = dot;
    dot = ident.find('.', olddot + 1);
    if (dot < 0) {
      sub = ident.mid(olddot + 1);
      break;
    }
    sub = ident.mid(olddot + 1, dot - olddot - 1);
    if (!base.hasProperty(sub))
      return false;
    base = base.get(sub);
  }

  base.put(sub, value);

  return true;
}
예제 #3
0
QSObject QSRegExpClass::test( QSEnv *env )
{
    QSObject obj = env->thisValue();
    QRegExp *re = regExp( &obj );
    QString s = env->arg( 0 ).toString();
    uint length = s.length();
    int i = obj.get( QString::fromLatin1("lastIndex") ).toInt32();
    QSObject tmp = obj.get( QString::fromLatin1("global") );
    if ( !tmp.toBoolean() )
	i = 0;
    if ( i < 0 || i >(int) length ) {
	obj.put( QString::fromLatin1("lastIndex"), 0 );
	return env->createBoolean( FALSE );
    }
    i = re->search( s, i );
    obj.env()->regexpClass()->lastCaptures = re->capturedTexts();
    return env->createBoolean( i >= 0 );
}
예제 #4
0
파일: qsaeditor.cpp 프로젝트: aschet/qsaqt5
QSObject QSAEditor::queryQSObject( QSObject &ctx, const QString &property ) const
{
    QString s = property;

    QSObject ctxValue = ctx.get( s );
    if ( ctxValue.isA( env()->typeClass() ) ) {
	return ctxValue;
    }

    if ( s.indexOf( '[' ) != -1 )
	return QSArray( env() );
    else if ( s == QString::fromLatin1("false") || s == QString::fromLatin1("true") )
	return env()->createBoolean( false );
    else if ( s[0] == '\'' || s[0] == '\"' )
	return env()->createString( QString::fromLatin1("") );
    return ctxValue;
}
예제 #5
0
static bool hasMember(QSEnv *env, const QString &function, QSMember::Type type)
{
    QSObject o = env->globalObject();
    QSMember member;
    QStringList names = function.split(QString::fromLatin1("."));
    int nameCount = names.count();
    for (QStringList::ConstIterator it = names.begin(); it != names.end(); ++it, --nameCount) {
	if (nameCount==1) {
	    if (o.objectType() == env->typeClass())
		return QSTypeClass::classValue(&o)->member(0, *it, &member)
		    && member.type() == type;
	    else if (o.objectType()->member(&o, *it, &member))
		return o.objectType()->member(0, *it, &member) && member.type() == type;
	} else {
	    o = o.get(*it);
	    if (!o.isValid())
		return false;
	}
    }
    return false;
}
예제 #6
0
QString Debugger::varInfo(const QString &ident) const
{
  if (!eng)
    return QString();

  int dot = ident.find('.');
  if (dot < 0)
    dot = ident.length();
  QString sub = ident.mid(0, dot);
  QSObject obj;
  // resolve base
  if (sub == QString::fromLatin1("||Global||")) {
    obj = env()->globalObject();
  } else if (sub == QString::fromLatin1("||Activation||")) {
    obj = env()->currentScope();
  } else if (sub == QString::fromLatin1("this")) {
    obj = env()->thisValue();
  } else {
    obj = env()->resolveValue(ident);
    if (!obj.isValid())
      return QString();
  }
  // look up each part of a.b.c.
  while (dot < (int)ident.length()) {
    int olddot = dot;
    dot = ident.find('.', olddot + 1);
    if (dot < 0)
      dot = ident.length();
    sub = ident.mid(olddot + 1, dot - olddot - 1);
    obj = obj.get(sub);
    if (!obj.isDefined())
      break;
  }

  return sub + QString::fromLatin1("=") + obj.debugString();
}