Exemple #1
0
bool QSEngineImp::call( QSObject *scope, const QString &func,
                        const QSList &args )
{
    init();
    QSObject t;
    if ( !scope || !scope->isValid() ) {
        t = env()->globalObject();
        scope = &t;
    }

    QSObject v = scope->getQualified(func);
    Q_ASSERT(v.isValid());

    if ( !v.isDefined() ) {
        if (func != QString::fromLatin1("main")) {
            errType = ReferenceError;
            errMsgs.append( QString::fromLatin1("Unknown function: ") + func );
            errLines.append( 0 );
        }
        return false;
    }

    if ( !v.isFunction() ) {
        errType = TypeError;
        errMsgs.append( func + QString::fromLatin1(" is not a function. Call failed.") );
        errLines.append( 0 );
        return false;
    }
    QSObject res = v.invoke( QSMember(), args );

    if ( env()->isExceptionMode() ) {
        QSObject err = env()->exception();
        errType = 99; /* TODO */
        errLines.append(QSErrorClass::errorLine(&err));
        errMsgs.append(QSErrorClass::errorName(&err) + QString::fromLatin1(". ") + QSErrorClass::errorMessage(&err));
#ifdef QSDEBUGGER
        if (dbg)
            dbg->setSourceId(QSErrorClass::errorSourceId(&err));
#endif
        env()->clearException();
        return false;
    } else {
        errType = 0;
        errLines.clear();
        errMsgs.clear();

        // return value
        retVal = res;
        return true;
    }
}
Exemple #2
0
QSObject QSFuncRefClass::invoke( QSObject * objPtr,
				   const QSMember & ) const
{
    Q_ASSERT( objPtr->isA( this ) );
    QSReferenceData * data = (QSReferenceData*) objPtr->shVal();
    QSObject base = data->base;
    QSMember bmem = data->member;

    env()->pushScopeBlock();
    ScopeChain::const_iterator it = data->context.begin();
    while( it!=data->context.end() ) {
	env()->pushScope( *it );
	it++;
    }

    QSObject retVal = base.invoke( bmem, *(env()->arguments()) );

    env()->popScopeBlock();
    return retVal;
}