Beispiel #1
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;
}