void VJSGlobalClass::do_dateToIso(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString s;
	VJSValue jsval(ioParms.GetContextRef());
	if (ioParms.CountParams() > 0)
	{
		VTime dd;
		jsval = ioParms.GetParamValue(1);
		jsval.GetTime(dd);
		dd.GetJSONString(s);
	}
	ioParms.ReturnString(s);
}
void VJSGlobalClass::do_testMe( VJSParms_callStaticFunction& inParms, VJSGlobalObject*)
{
	VJSObject globalObject( inParms.GetContext().GetGlobalObject());
	
	VString functionName;
	inParms.GetStringParam( 1, functionName);
	
	std::vector<VJSValue> values;
	size_t count = inParms.CountParams();
	for( size_t i = 2 ; i <= count ; ++i)
		values.push_back( inParms.GetParamValue( i));

	VJSValue result( inParms.GetContextRef());
	bool ok = globalObject.CallMemberFunction( functionName, &values, &result, inParms.GetExceptionRefPointer());
	inParms.ReturnValue( result);
}
void VJSStorageClass::_setItem (VJSParms_callStaticFunction &ioParms, VJSStorageObject *inStorageObject)
{
	xbox_assert(inStorageObject != NULL);

	XBOX::VString	name;

	if (ioParms.CountParams() && ioParms.IsStringParam(1) && ioParms.GetStringParam(1, name)) {

		XBOX::VJSValue	value(ioParms.GetContext());
		
		if (ioParms.CountParams() < 2)
		
			value.SetUndefined();

		else

			value = ioParms.GetParamValue(2);

		inStorageObject->SetKeyValue(name, value);

	}	
}
Example #4
0
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);
}