Esempio n. 1
0
VJSTimer::VJSTimer (XBOX::VJSObject &inFunctionObject, sLONG inInterval)
{
	xbox_assert(inFunctionObject.GetObjectRef() != NULL);
	xbox_assert(inInterval >= 0 || inInterval == VJSTimer::kTimeOut);

	fTimerContext = NULL;
	fID = -1;
	fInterval = inInterval;
	fFunctionObject = inFunctionObject.GetObjectRef();	
}
Esempio n. 2
0
void VJSMessagePort::SetObject (VJSWorker *inWorker, XBOX::VJSObject &inObject)
{
    xbox_assert(inWorker != NULL && (inWorker == fOutsideWorker || inWorker == fInsideWorker));
    xbox_assert((inWorker == fOutsideWorker && !fOutsideClosingFlag) || (inWorker == fInsideWorker && !fInsideClosingFlag));
    xbox_assert(inObject.GetObjectRef() != NULL);

    if (inWorker == fOutsideWorker)

        fOutsideObject = inObject.GetObjectRef();

    else

        fInsideObject = inObject.GetObjectRef();
}
XBOX::VJSValue VJSStructuredClone::_ConstructObject (XBOX::VJSContext inContext, const XBOX::VString &inConstructorName, XBOX::VJSValue inArgument)
{
	XBOX::VJSObject				object = inContext.GetGlobalObject().GetPropertyAsObject(inConstructorName);
	std::vector<XBOX::VJSValue>	arguments;
	XBOX::VJSValue				value(inContext);

	arguments.push_back(inArgument);
	if (object.CallAsConstructor(&arguments, &object, NULL)) 

		value.SetValueRef((JS4D::ObjectRef) object.GetObjectRef());

	else

		value.SetUndefined();

	return value;
}
void VJSNetServerSyncClass::_accept (XBOX::VJSParms_callStaticFunction &ioParms, VJSNetServerObject *inServer)
{
	xbox_assert(inServer != NULL);

	sLONG	timeOut;

	if (ioParms.CountParams() >= 1) {

		if (!ioParms.IsNumberParam(1) || !ioParms.GetLongParam(1, &timeOut)) {

			XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1");
			return;

		}

		if (timeOut < 0) {

			XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1");
			return;

		}

	} else

		timeOut = 0;

	XBOX::XTCPSock	*socket;

	// If socket returned is NULL, accept() has timed out or an error has occured.
	// An exception is thrown by GetNewConnectedSocket() if erroneous.

	if ((socket = inServer->fSockListener->GetNewConnectedSocket(timeOut)) == NULL) 

		ioParms.ReturnNullValue();

	else {

		XBOX::VTCPEndPoint	*endPoint		= NULL;
		VJSNetSocketObject	*socketObject	= NULL;
	
		if ((endPoint = new XBOX::VTCPEndPoint(socket)) == NULL 
		|| (socketObject = new VJSNetSocketObject(true, VJSNetSocketObject::eTYPE_TCP4, false)) == NULL) {

			if (endPoint != NULL)

				endPoint->Release();

			if (socketObject != NULL)

				socketObject->Release();

			socket->Close();
			delete socket;

			XBOX::vThrowError(XBOX::VE_MEMORY_FULL);
		
		} else {

			socketObject->fEndPoint = endPoint;
			socketObject->fEndPoint->SetNoDelay(false);

			XBOX::VJSObject	newSocketSync = VJSNetSocketSyncClass::CreateInstance(ioParms.GetContext(), socketObject);
			XBOX::VString	address;

			socketObject->fObjectRef = newSocketSync.GetObjectRef();
			socketObject->fWorker = VJSWorker::RetainWorker(ioParms.GetContext());

			socketObject->fEndPoint->GetIP(address);
			newSocketSync.SetProperty("remoteAddress", address);
			newSocketSync.SetProperty("remotePort", (sLONG) socketObject->fEndPoint->GetPort() & 0xffff);

			ioParms.ReturnValue(newSocketSync);

		}

	}
}