Esempio n. 1
0
bool CArrayObject::CilPredicater( const CVariable& elem1,
									const CVariable& elem2 )
{
	assert( g_ridPredicater != RID_NULL );
	assert( g_pVm != NULL );
	
	//Invoke predicater
	CVariable vars[ 3 ];
	vars[ 1 ] = elem1;
	vars[ 2 ] = elem2;
	
	CVariable* pResult = g_pVm->invokeMethod( g_ridPredicater,
												3,
												vars );
	bool bReturn = (pResult->toInt() < 0);
	delete( pResult );
	
	return bReturn;
}
Esempio n. 2
0
/***************************************************************************
 *      anyAccessor
 ***************************************************************************/
CVariable* CArrayObject::anyAccessor(CCilVm* const pVm,
										CVmObject* const pObject, 
										const wstring* const pName,
										CVariable* const pVar,
										const bool bSet )
{
	assert( pObject != NULL );
	if( bSet )
	{
		//Getter implementation
		return NULL;
	}
	else
	{
		pObject->setProperty( *pName, *pVar );

		//Setter implementation
		int32_t iLength = 0;

		//Check existing length
		CVariable* pCurrentLengthVar = pObject->lookupProperty( STRING_PROPERTY_INTERNAL_LENGTH );

		if( pCurrentLengthVar != NULL  )
		{
			iLength = pCurrentLengthVar->toInt();
		}

		int32_t iGivenIndex = _wtoi( pName->data() ) + 1;
		
		if( iGivenIndex > iLength )
		{
			CVariable var( iGivenIndex, OPERAND_FLAG( OPERAND_FLAG_DONTDELETE | OPERAND_FLAG_DONTENUM ) ); 
			pObject->setProperty( STRING_PROPERTY_INTERNAL_LENGTH, var );
		}
		return NULL;
	}
}
Esempio n. 3
0
/***************************************************************************
 *      lengthAccessor
 *      array object helper
 ***************************************************************************/
CVariable* CArrayObject::lengthAccessor(CCilVm* const pVm,
										CVmObject* const pObject,
										const wstring* const pName,
										CVariable* const pVar,
										const bool bSet )
{
	assert( pObject != NULL );
	if( bSet )
	{
		//Getter implementation
		return pObject->lookupProperty( STRING_PROPERTY_INTERNAL_LENGTH );
	}
	else
	{
		//Setter implementation
		int32_t iLength = 0;

		//Check existing length
		CVariable* pCurrentLengthVar = pObject->lookupProperty( STRING_PROPERTY_INTERNAL_LENGTH );

		if( pCurrentLengthVar != NULL  )
		{
			iLength = pCurrentLengthVar->toInt();
		}

		int32_t iGivenIndex = pVar->toInt();

		//Just expanding the array, nothing to do
		CVariable var( iGivenIndex,
					  OPERAND_FLAG( OPERAND_FLAG_DONTDELETE | OPERAND_FLAG_DONTENUM ) );
		pObject->setProperty( STRING_PROPERTY_INTERNAL_LENGTH, var );

		if( iGivenIndex < iLength )
		{
			//Reducing an array size, need to eliminate some entries
			int32_t iNumToEliminate = iLength - iGivenIndex;

			hash_map< wstring, CVariable >::iterator itStart =
										pObject->getPropertyMap().begin();
			hash_map< wstring, CVariable >::iterator itEnd =
										pObject->getPropertyMap().end();
			while( itStart != itEnd && iNumToEliminate )
			{
				if( itStart->second.iOperandFlag && OPERAND_FLAG_DONTENUM )
				{
					itStart++;
					continue;
				}
				if( CheckArrayIndex( itStart->first ) )
				{
					const wstring& String = itStart->first;
					itStart ++;
					if( _wtoi( String.data() ) >= iGivenIndex )
					{
						pObject->removeProperty( String );
						iNumToEliminate--;
					}
				}
				else
					itStart++;
			}
		}
		return NULL;
	}
}