void VJSStream::_GetLong64(VJSParms_callStaticFunction& ioParms, VStream* inStream)
{
	sLONG8 l8;
	VError err = inStream->GetLong8(l8);
	if (err == VE_OK)
		ioParms.ReturnNumber(l8);
}
void VJSStream::_GetReal(VJSParms_callStaticFunction& ioParms, VStream* inStream)
{
	Real r;
	VError err = inStream->GetReal(r);
	if (err == VE_OK)
		ioParms.ReturnNumber(r);
}
void VJSStream::_GetByte(VJSParms_callStaticFunction& ioParms, VStream* inStream)
{
	uBYTE c;
	VError err = inStream->GetByte(c);
	if (err == VE_OK)
		ioParms.ReturnNumber(c);
}
void VJSStream::_GetWord(VJSParms_callStaticFunction& ioParms, VStream* inStream)
{
	sWORD w;
	VError err = inStream->GetWord(w);
	if (err == VE_OK)
		ioParms.ReturnNumber(w);
}
void VJSTextStream::_GetPos (VJSParms_callStaticFunction &ioParms, VJSTextStreamState *inStreamState)
{
	if (inStreamState != NULL)

		ioParms.ReturnNumber(inStreamState->fPosition);
		
	else

		XBOX::vThrowError(XBOX::VE_JVSC_INVALID_STATE, L"TextStream.getPos()");
}
void VJSSession::_promoteWith(VJSParms_callStaticFunction& ioParms, CUAGSession* inSession)
{
	sLONG promotionToken = 0;

	CUAGGroup* group = RetainParamGroup(inSession->GetDirectory(), ioParms, 1);
	if (group != nil)
	{
		promotionToken = inSession->PromoteIntoGroup(group);
	}

	QuickReleaseRefCountable(group);
	ioParms.ReturnNumber(promotionToken);
}
Exemple #7
0
void VJSSession::_promoteWith(VJSParms_callStaticFunction& ioParms, CUAGSession* inSession)
{
	sLONG promotionToken = 0;

	CUAGGroup* group = RetainParamGroup(inSession->GetDirectory(), ioParms, 1);
	if (group != nil)
	{
		CUAGThreadPrivilege* privileges = static_cast<CUAGThreadPrivilege*>(ioParms.GetContext().GetGlobalObjectPrivateInstance()->GetSpecific('uagX'));
		promotionToken = inSession->PromoteIntoGroup(group, privileges);
	}

	QuickReleaseRefCountable(group);
	ioParms.ReturnNumber(promotionToken);
}
void VJSStream::_GetSize(VJSParms_callStaticFunction& ioParms, VStream* inStream)
{
	ioParms.ReturnNumber(inStream->GetSize());
}
void VJSTimer::_SetTimer (VJSParms_callStaticFunction &ioParms, VJSWorker *inWorker, bool inIsInterval) 
{
	xbox_assert(inWorker != NULL);

	if (!ioParms.CountParams())
		
		return;

	XBOX::VJSContext	context(ioParms.GetContext());
	XBOX::VJSObject		functionObject(context);

	ioParms.GetParamObject(1, functionObject);
	if (!functionObject.IsFunction())

		return;

	functionObject.Protect();

	Real	duration;

	duration = 0.0;
	if (ioParms.CountParams() >= 2) {

		if (ioParms.IsNumberParam(2)) {
			
			if (!ioParms.GetRealParam(2, &duration))
			
				duration = 0.0;

		} else {

			// According to specification, if timeout is an object, call its toString() method if any. 
			// Then apply ToNumber() on the string to obtain duration.
			
			XBOX::VJSObject	timeOutObject(context);

			if (ioParms.GetParamObject(2, timeOutObject)) {

				timeOutObject.SetContext(context);
				if (timeOutObject.HasProperty("toString")) {

					XBOX::VJSObject	toStringObject = timeOutObject.GetPropertyAsObject("toString");

					if (toStringObject.IsFunction()) {

						std::vector<XBOX::VJSValue>	values;
						XBOX::VJSValue				string(context);

						toStringObject.SetContext(context);
						timeOutObject.CallFunction(toStringObject, &values, &string, NULL);

						if (string.IsString()) {

							// If Number() is called as a function (and not as a constructor), it acts as ToNumber().
							// See section 15.7.1 of ECMA-262 specification.

							XBOX::VJSObject	toNumberObject = context.GetGlobalObject().GetPropertyAsObject("Number");

							if (toNumberObject.IsFunction()) {

								XBOX::VJSValue	number(context);

								values.clear();
								values.push_back(string);
								toNumberObject.SetContext(context);
								context.GetGlobalObject().CallFunction(toNumberObject, &values, &number, NULL);

								if (number.IsNumber() && !number.GetReal(&duration))

									duration = 0.0;

							}

						}

					}

				}

			}
		
		}

		// (value != value) is true if value is a NaN.

		if (duration < 0.0 || duration > XBOX::kMAX_Real || duration != duration)
		
			duration = 0.0;

	}	
	
	std::vector<XBOX::VJSValue> *arguments;

	arguments = new std::vector<XBOX::VJSValue>;
	for (sLONG i = 3; i <= ioParms.CountParams(); i++) 

		arguments->push_back(ioParms.GetParamValue(i));

	sLONG		period, id;
	VJSTimer	*timer;

	period = (sLONG) duration;
	if (inIsInterval) {

		if (period < VJSTimer::kMinimumInterval)

			period = VJSTimer::kMinimumInterval;

	} else {

		if (period < VJSTimer::kMinimumTimeout)

			period = VJSTimer::kMinimumTimeout;

	}		 
	timer = new VJSTimer(functionObject, inIsInterval ? period : VJSTimer::kTimeOut);
	if ((id = inWorker->GetTimerContext()->InsertTimer(timer)) < 0) {

		// Too many timers (should never happen). Silently ignore. 
		// Returned ID (-1) isn't valid and a clear on it, will do nothing.

		timer->Release();
		delete arguments;
	
	} else {

		XBOX::VTime	triggerTime;
	
		triggerTime.FromSystemTime();
		triggerTime.AddMilliseconds(period);

		inWorker->QueueEvent(VJSTimerEvent::Create(timer, triggerTime, arguments));

	}

	ioParms.ReturnNumber(id);
}
void VJSLanguageSyntaxTesterDefinitionResults::_GetResultCount( VJSParms_callStaticFunction &ioParams, IJSLanguageSyntaxTesterDefinitionResults *inResults )
{
	if (inResults) {
		ioParams.ReturnNumber( inResults->GetResultCount() );
	}
}