示例#1
0
QSEqualsResult QSStringClass::isEqual( const QSObject &a, const QSObject &b ) const
{
    Q_ASSERT( a.isA( this ) );
    if ( b.isString() )
	return (QSEqualsResult) (a.sVal() == b.sVal() || (a.sVal().isEmpty() && b.sVal().isEmpty()));
    else if ( b.isNumber() )
	return ( QSEqualsResult ) ( a.sVal() == b.toString() );
    else if ( !b.isPrimitive() )
	return isEqual( a, b.toPrimitive() );
    else
	return EqualsUndefined;

}
示例#2
0
QSEqualsResult QSNumberClass::isEqual( const QSObject &a, const QSObject &b ) const
{
    Q_ASSERT( a.isA( this ) );
    if ( b.isNumber() ) {
	double n1 = a.dVal();
	double n2 = b.dVal();
	if ( isNaN( n1 ) || isNaN( n2 ) )
	    return EqualsNotEqual;
	else
	    return ( QSEqualsResult ) ( n1 == n2 );
	// ### compare -0 agains +0
    } else if ( b.isString() ) {
	return ( QSEqualsResult ) ( a.dVal() == b.toNumber() );
    } else if ( !b.isPrimitive() ) {
	return isEqual( a, b.toPrimitive() );
    } else {
	return EqualsUndefined;
    }
}
示例#3
0
// eval()
static QSObject qsEval( QSEnv *env )
{
    QSObject x = env->arg( 0 );
    if ( !x.isString() ) {
	return x;
    } else {
	QSEngineImp *eimp = env->engine()->imp();
	QString s = x.toString();
	QSNode *progNode = 0;
	{ // begin mutext locker
            QMutexLocker locker(qsa_lexer_mutex());
            QSLexer::lexer()->setCode( s,
#ifdef QSDEBUGGER
                                       eimp->sourceId()
#else
                                       0
#endif
                                       );
            int yp = qsyyparse();
            progNode = QSProgramNode::last();
            if ( yp || QSLexer::lexer()->lexerState() == QSLexer::Bad ) {
                if (!progNode && progNode->deref())
                    delete progNode;
                return env->throwError( SyntaxError );
            }
	} // end mutext locker

	QSCheckData data( env );
	QSObject scopeTop = env->currentScope();
	postfixAdd( scopeTop.objectType(), &data );
	QSEvalScopeClass *cl = new QSEvalScopeClass( env->objectClass() );
	data.enterEval( cl );

	progNode->check( &data );
	if ( data.hasError() ) {
	    if (!progNode->deref())
		delete progNode;
	    return env->throwError( EvalError,
				    data.errorMessages().first(),
				    data.errorLines().first() );
	}

        QSList empty;
	env->pushScope( cl->construct( empty ) );
	// ### delete tmp scope class

	QSObject res = ((QSProgramNode*)progNode)->execute( env );

	if (!progNode->deref())
	    delete progNode;

	env->popScope();

	if ( env->isReturnValueMode() )
	  return res;
	else if ( env->isNormalMode() ) {
	    if ( res.isValid() )
		return res;
	    else
		return env->createUndefined();
	} else
	    return res;
    }
}