void VJSNetServerSyncClass::Construct (XBOX::VJSParms_callAsConstructor &ioParms)
{
	VJSNetServerObject	*serverObject;
	
	if ((serverObject = new VJSNetServerObject(true)) != NULL) {

		XBOX::VJSObject	createdObject(ioParms.GetContext());

		createdObject = VJSNetServerSyncClass::CreateInstance(ioParms.GetContext(), serverObject);

		ioParms.ReturnConstructedObject(createdObject);

	} else

		XBOX::vThrowError(XBOX::VE_MEMORY_FULL);
}
Ejemplo n.º 2
0
void VJSSharedWorkerClass::_Construct (XBOX::VJSParms_callAsConstructor &ioParms)
{
    if (!ioParms.CountParams()
            || !ioParms.IsStringParam(1)
            || (ioParms.CountParams() >= 2 && !ioParms.IsStringParam(2))) {

        XBOX::vThrowError(XBOX::VE_INVALID_PARAMETER);
        ioParms.ReturnUndefined();
        return;

    }

    XBOX::VString		url, name;
    bool				reUseContext;
    VJSWorker			*outsideWorker;
    VJSWebWorkerObject	*workerProxy;
    XBOX::VJSContext	context(ioParms.GetContext());
    XBOX::VJSObject		constructedObject(context);

    ioParms.GetStringParam(1, url);
    if (ioParms.CountParams() == 2)

        ioParms.GetStringParam(2, name);

    outsideWorker = VJSWorker::RetainWorker(context);

    if (ioParms.CountParams() < 3 || !ioParms.IsBooleanParam(3) || !ioParms.GetBoolParam(3, &reUseContext))

        reUseContext = false;

    if ((workerProxy = VJSWebWorkerObject::_CreateWorker(context, outsideWorker, reUseContext, url, false, name)) != NULL) {

        constructedObject = VJSDedicatedWorkerClass::CreateInstance(context, workerProxy);
        workerProxy->fOnErrorPort->SetObject(outsideWorker, constructedObject);

        XBOX::VJSObject	messagePortObject(context);

        messagePortObject = VJSMessagePortClass::CreateInstance(context, workerProxy->fOnMessagePort);
        workerProxy->fOnMessagePort->SetObject(outsideWorker, messagePortObject);

        constructedObject.SetProperty("port", messagePortObject);

    } else

        constructedObject.SetNull();

    ioParms.ReturnConstructedObject(constructedObject);

    XBOX::ReleaseRefCountable<VJSWorker>(&outsideWorker);
}
void VJSXMLHttpRequest::_Construct(XBOX::VJSParms_callAsConstructor& ioParms)
{
    XMLHttpRequest* xhr=new XMLHttpRequest();
	
    if(!xhr)
    {
        XBOX::vThrowError(VE_XHRQ_IMPL_FAIL_ERROR);
        return;
    }
	
	
    XBOX::VJSObject pData(ioParms.GetContext());
	bool resData;
    resData=ioParms.GetParamObject(1, pData);
	
	if(resData)
	{
		XBOX::VJSValue hostValue=pData.GetProperty("host", NULL);
		XBOX::VString hostString;
		bool hostRes=hostValue.GetString(hostString, NULL);
		
		if(hostRes) //we have a proxy
		{
			XBOX::VJSValue portValue=pData.GetProperty("port", NULL);
			sLONG portLong=0;
			bool portRes=portValue.GetLong(&portLong, NULL);
			
			portLong=(portRes && portLong>0) ? portLong : 80;
			
			//todo : user and passwd
			
			XBOX::VError res=xhr->SetProxy(hostString, portLong);
			
			if(res!=XBOX::VE_OK)
				XBOX::vThrowError(res);
		}
	}
	
    ioParms.ReturnConstructedObject(VJSXMLHttpRequest::CreateInstance(ioParms.GetContextRef(), xhr));
	
}