Esempio n. 1
0
/***************************************************************************
 *   setStaticFieldFunctionObject
 ***************************************************************************/
bool CCilVm::setStaticFieldFunctionObject( const RID rid,
        const RID ridMethod )
{
    assert( TypeFromToken( ridMethod ) == MDT_METHODDEF );

    //Create function object and store it to static field
    CVmObject newobject;
    RID ridObj = getFunctionObjectRID();

    newobject.setRID( ridObj );
    newobject.setObjectName( getMetaData().getObjectNameRID( ridObj ) );
    newobject.setPrototypeObject( &getPrototypeObject( ridObj ) );
    newobject.setConstructorProperty( ridMethod );
    newobject.setCallProperty( ridMethod );

    getObjectPool().push_back( newobject );

    CVariable var;
    var.setObjectRef( &getObjectPool().back() );

    METHOD_DEF& method = getMetaData().getMethod( ridMethod );
    int32_t iLength = method.iNumArgments;
    assert( iLength >= 0 );

    CVariable varInt( iLength, OPERAND_FLAG_DONTENUM );
    var.refObject->setProperty( STRING_INTERNAL_LENGTH,
                                varInt );

    //Store the ObjectRef to a static field
    setStaticField( rid, var );

    return true;
}
Esempio n. 2
0
/***************************************************************************
 *      call method
 ***************************************************************************/
void CErrorObject::call( CCilVm* const pVm,
									const int32_t iNumArguments, 
									CVariable* pArguments )
{
	CVariable obj;

	CVmObject* pObj = pVm->createObject( pVm->getErrorObjectRID() );
	obj.setObjectRef( pObj );

	//Set prototype: String prototype object
	obj.refObject->setPrototypeObject( 
		&pVm->getPrototypeObject( pVm->getErrorObjectRID() ) );

	if( iNumArguments > 2 )
	{
		pArguments ++;
		CVariable& var = *pArguments;
		var.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) );
		obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, var ) ;
		
		pArguments ++;
		var = *pArguments;
		var.convertToString( pVm );
		var.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) );
		obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, var );
	} else if( iNumArguments > 1 )
	{
		pArguments ++;
		CVariable& var = *pArguments;
		var.convertToString( pVm );
		var.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) );
		obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, var );

		CVariable varError( ERROR_PROPERTY_NUMBER_DEFAULT,
					  OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) );
		obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, varError );
	}
	else
	{
		CVariable varString( L"",
							OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) );
		CVariable varError( ERROR_PROPERTY_NUMBER_DEFAULT,
						   OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) );
		obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, varString );
		obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, varError );
	}

	CVariable var( L"",
				  OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) );
	obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NAME, var );

	//Push the ObjectRef to a eval stack
	pVm->pushEvalStackVariable( obj );
	return;
}
Esempio n. 3
0
/***************************************************************************
 *      Create a prototype object
 ***************************************************************************/
bool CSystemObject::InitializeVm( CCilVm& vm )
{
    int32_t iIndex = IndexFromBuiltinRid( vm.getSystemObjectRID() );
    RID ridObjectName = vm.getMetaData().getBuiltinObjectTable()[ iIndex ].getObjectName();
    assert( ridObjectName != RID_NOTDEFINED );


    RID rid = vm.createPrototypeObject( vm.getSystemObjectRID(),
                                        ridObjectName,
                                        vm.getObjectRID() );

    assert( rid == vm.getSystemObjectRID() );

    VMOBJECTREF objref = vm.createObject( vm.getObjectRID() );
    CVariable var;
    var.setObjectRef( objref );

    //Set true as an object value..
    CVariable varBool( true );
    objref->setValue( varBool );

    //Create ExitCode property
    CVariable varExitCode( 0 );
    objref->setProperty( NAME_BUILTIN_SYSTEM_PROPERTY_EXITCODE, varExitCode );

    //Create Environment property
    //Add properties of prototype object here
    vm.getPrototypeObject( vm.getSystemObjectRID() ).setProperty( NAME_BUILTIN_SYSTEM_PROPERTY_ENVIRONMENT,
            var );

    //---------------------------------------------------------------------------
    // Bind System functions
    //---------------------------------------------------------------------------
    for( int32_t i = 0; i<sizeof( initParams ) / sizeof( initParams[ 0 ] ); ++i )
    {
        int32_t iParams;
        iParams = (int32_t)RidFromToken( initParams[ i ].ridParam );
        if( isBuiltinRid( initParams[ i ].ridParam ) )
        {
            iParams = RidFromToken( -iParams ) - 1;
        }
        //-----------------------------------------------------------------------
        //Register methods
        //-----------------------------------------------------------------------
        bool b = vm.bindBuiltinMethod(
                     wstring( initParams[ i ].pStrSymbol ),
                     initParams[ i ].pMethod,
                     iParams );
        if( !b )
            return false;
    }

    return true;
}
/***************************************************************************
 *      Load array literal onto the stack
 ***************************************************************************/
void CSystemObject::LoadarrayLiteral( CCilVm* const pVm,
										   const int32_t iNumArguments, 
										   CVariable* pArguments )
{
	assert( pVm != NULL );
	//Array parameter can be null
	assert( iNumArguments >= 1 );

	//Skip this pointer
	pArguments++;

	//Create object object
	CVmObject* pObj = pVm->createObject( pVm->getArrayObjectRID() );
	CVariable var;
	var.setObjectRef( pObj );

	wchar_t strBuffer[ 22 ];		//22=max value width of longlong

	int32_t i = 0;
	for( ; i < iNumArguments - 1; ++i )
	{
		//Argument: 1) value of the property
		swprintf( strBuffer, 22, L"%d", i );
		var.refObject->setProperty( strBuffer, *pArguments );
		pArguments++;
	}

	//Set prototype: Array prototype object
	var.refObject->setPrototypeObject( 
		&pVm->getPrototypeObject( pVm->getArrayObjectRID() ) );

	//Update 'length' property
	CVariable varInt( 0 );
	var.refObject->setProperty( STRING_INTERNAL_LENGTH, varInt );
	//-2 means, 'prototype' & 'length'
	CVariable varLength( (int32_t)var.refObject->getPropertyMap().size() - 2,
						OPERAND_FLAG( OPERAND_FLAG_DONTDELETE | OPERAND_FLAG_DONTENUM ) ); 
	var.refObject->setProperty( STRING_INTERNAL_LENGTH, varLength );

	//Push the ObjectRef to a eval stack
	pVm->pushEvalStackVariable( var );

	return;
}
/***************************************************************************
 *      Load object literal onto the stack
 ***************************************************************************/
void CSystemObject::LoadobjectLiteral( CCilVm* const pVm,
										   const int32_t iNumArguments, 
										   CVariable* pArguments )
{
	assert( pVm != NULL );
	assert( iNumArguments >= 2 );
	assert( iNumArguments % 2 == 1 );

	//Skip this pointer
	pArguments++;
	int32_t i = iNumArguments;
	i--;
	CMetaData& Metadata = pVm->getMetaData();

	//Create object object
	CVmObject newobject;
	RID ridObject = pVm->getObjectRID();
	newobject.setRID( ridObject );
	newobject.setObjectName( pVm->getMetaData().getObjectNameRID( ridObject ) );
	newobject.setPrototypeObject( &pVm->getPrototypeObject( ridObject ) );

	pVm->getObjectPool().push_back( newobject );

	CVariable var;
	var.setObjectRef( &pVm->getObjectPool().back() );

	for( ; i > 0; i -= 2 )
	{
		//Argument: 1) value of the property
		//			2) string RID of the property

		RID ridString = pArguments->iValue;
		assert( TypeFromToken( ridString ) == MDT_STRING );
		pArguments++;

		wstring& str = Metadata.getStringConstant( ridString );
		var.refObject->setProperty( str, *pArguments );
		pArguments++;
	}

	//Push the ObjectRef to a eval stack
	pVm->pushEvalStackVariable( var );
	return;
}