コード例 #1
0
void VJSGlobalClass::do_ProgressIndicator(VJSParms_callStaticFunction& ioParms, VJSGlobalObject *inContext)
{
	VString sessiontile;
	VString windowtile, userinfo;
	bool caninterrupt = false;
	Real maxvalue = -1;
	VError err = VE_OK;
	
	if (ioParms.IsNumberParam(1))
		ioParms.GetRealParam(1, &maxvalue);
	else
		err = vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1");

	if (err == VE_OK )
	{
		if (ioParms.IsStringParam(2))
			ioParms.GetStringParam(2, sessiontile);
		else
			err = vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "2");
	}

	caninterrupt = ioParms.GetBoolParam( 3, L"Can Interrupt", "Cannot Interrupt");

		
	//VProgressIndicator* progress = inContext->GetRuntimeDelegate()->CreateProgressIndicator( windowtile);

	if (err == VE_OK)
	{
		VProgressIndicator* progress = new VProgressIndicator();
		if (progress != NULL)
		{
			if (ioParms.CountParams() >= 4)
			{
				if (ioParms.IsStringParam(4))
				{
					ioParms.GetStringParam(4, windowtile);
					progress->SetTitle(windowtile);
				}
				else
					vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "4");
			}
			if (ioParms.CountParams() >= 5)
			{
				if (ioParms.IsStringParam(5))
				{
					ioParms.GetStringParam(5, userinfo);
					progress->SetUserInfo(userinfo);
				}
				else
					vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "5");
			}
			progress->BeginSession((sLONG8)maxvalue, sessiontile, caninterrupt);
		}
		ioParms.ReturnValue(VJSProgressIndicator::CreateInstance(ioParms.GetContextRef(), progress));
		
		ReleaseRefCountable( &progress);
	}
	else
		ioParms.ReturnNullValue();	
}	
コード例 #2
0
void VJSStream::do_BinaryStream(VJSParms_callStaticFunction& ioParms)
{
	VFile* file = ioParms.RetainFileParam( 1);
	bool forwrite = ioParms.GetBoolParam( 2, L"Write", L"Read");
	if (file != NULL)
	{
		VError err = VE_OK;
		if (forwrite)
		{
			if (!file->Exists())
				err = file->Create();
		}
		VFileStream* stream = new VFileStream(file);
		if (err == VE_OK)
		{
			if (forwrite)
				err = stream->OpenWriting();
			else
				err = stream->OpenReading();
		}
		
		if (err == VE_OK)
		{
			ioParms.ReturnValue(VJSStream::CreateInstance(ioParms.GetContextRef(), stream));
		}
		else
		{
			delete stream;
		}
	}
	else
		vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1");
	ReleaseRefCountable( &file);
}
コード例 #3
0
void VJSLanguageSyntaxTesterDefinitionResults::_GetResult( VJSParms_callStaticFunction &ioParams, IJSLanguageSyntaxTesterDefinitionResults *inResults )
{
	if (inResults) {
		sLONG index;
		if (ioParams.GetLongParam( 1, &index ))
		{
			IDefinition definition = inResults->GetResult( index );
			VJSObject	result(ioParams.GetContextRef());
			VJSValue	jsval(ioParams.GetContextRef());

			result.MakeEmpty();

			jsval.SetString( definition.GetName() );
			result.SetProperty(L"name", jsval, JS4D::PropertyAttributeNone);

			jsval.SetString( definition.GetFilePath() );
			result.SetProperty(L"file", jsval, JS4D::PropertyAttributeNone);

			jsval.SetNumber( definition.GetLineNumber() + 1 );
			result.SetProperty(L"line", jsval, JS4D::PropertyAttributeNone);

			ioParams.ReturnValue(result);
		}
	}
}
コード例 #4
0
ファイル: JsUAG.cpp プロジェクト: StephaneH/core-Components
void VJSDirectory::_filterGroups(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory)
{
	VString s;
	bool isquery = false;
	ioParms.GetStringParam(1, s);
	isquery = ioParms.GetBoolParam(2, "query", "not query");
	CUAGGroupVector groups;
	VError err = inDirectory->FilterGroups(s, isquery, groups);

	ioParms.ReturnValue(buildArrFromGroups(ioParms, groups, nil));
}
コード例 #5
0
void VJSGlobalClass::do_GetProgressIndicator(VJSParms_callStaticFunction& ioParms, VJSGlobalObject *inContext)
{
	if (ioParms.IsStringParam(1))
	{
		VString userinfo;
		ioParms.GetStringParam(1, userinfo);
		VProgressIndicator* progress = VProgressManager::RetainProgressIndicator(userinfo);
		if (progress != nil)
			ioParms.ReturnValue(VJSProgressIndicator::CreateInstance(ioParms.GetContextRef(), progress));
		QuickReleaseRefCountable(progress);
	}
}
コード例 #6
0
void VJSGlobalClass::do_Require(VJSParms_callStaticFunction& ioParms, VJSGlobalObject *inGlobalObject)
{
	xbox_assert(inGlobalObject != NULL);

	XBOX::VString	className;

	if (ioParms.CountParams() != 1 || !ioParms.IsStringParam(1) || !ioParms.GetStringParam(1, className))

		vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");

	else

		ioParms.ReturnValue(inGlobalObject->Require(ioParms.GetContext(), className));
}
コード例 #7
0
ファイル: JsUAG.cpp プロジェクト: StephaneH/core-Components
void VJSDirectory::_addGroup(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory)
{
	VError err;
	VString groupname, fullname;
	ioParms.GetStringParam(1, groupname);
	ioParms.GetStringParam(2, fullname);
	CUAGGroup* group = inDirectory->AddOneGroup(groupname, fullname, err);
	if (group == nil)
		ioParms.ReturnNullValue();
	else
	{
		ioParms.ReturnValue(VJSGroup::CreateInstance(ioParms.GetContext(), group));
		group->Release();
	}
}
コード例 #8
0
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);
}
コード例 #9
0
ファイル: JsUAG.cpp プロジェクト: StephaneH/core-Components
void VJSDirectory::_addUser(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory)
{
	VError err;
	VString username, password, fullname;
	ioParms.GetStringParam(1, username);
	ioParms.GetStringParam(2, password);
	ioParms.GetStringParam(3, fullname);
	CUAGUser* user = inDirectory->AddOneUser(username, password, fullname, err);
	if (user == nil)
		ioParms.ReturnNullValue();
	else
	{
		ioParms.ReturnValue(VJSUser::CreateInstance(ioParms.GetContext(), user));
		user->Release();
	}
	
}
コード例 #10
0
void VJSStorageClass::_getItem (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());

		inStorageObject->GetKeyValue(name, &value);

		ioParms.ReturnValue(value);

	} else

		ioParms.ReturnNullValue();
}
コード例 #11
0
void VJSStorageClass::_key (VJSParms_callStaticFunction &ioParms, IJSStorageObject *inStorageObject)
{
	xbox_assert(inStorageObject != NULL);

	sLONG	index;

	if (ioParms.CountParams() && ioParms.IsNumberParam(1) && ioParms.GetLongParam(1, &index)) {

		XBOX::VJSValue	value(ioParms.GetContext());

		inStorageObject->GetKeyValue(index, &value);

		ioParms.ReturnValue(value);

	} else

		ioParms.ReturnNullValue();
}
コード例 #12
0
ファイル: JsUAG.cpp プロジェクト: StephaneH/core-Components
void VJSDirectory::_getUser(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory)
{
	StErrorContextInstaller errs(false, true);
	VString s;
	ioParms.GetStringParam(1, s);
	CUAGUser* user = inDirectory->RetainUser(s);
	if (user == nil)
	{
		VUUID id;
		id.FromString(s);
		user = inDirectory->RetainUser(id);
	}
	if (user == nil)
		ioParms.ReturnNullValue();
	else
	{
		ioParms.ReturnValue(VJSUser::CreateInstance(ioParms.GetContext(), user));
		user->Release();
	}
}
コード例 #13
0
ファイル: JsUAG.cpp プロジェクト: StephaneH/core-Components
void VJSDirectory::_getGroup(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory)
{
	StErrorContextInstaller errs(false, true);
	VString s;
	ioParms.GetStringParam(1, s);
	CUAGGroup* group = inDirectory->RetainGroup(s);
	if (group == nil)
	{
		VUUID id;
		id.FromString(s);
		group = inDirectory->RetainGroup(id);
	}
	if (group == nil)
		ioParms.ReturnNullValue();
	else
	{
		ioParms.ReturnValue(VJSGroup::CreateInstance(ioParms.GetContext(), group));
		group->Release();
	}
}
コード例 #14
0
void VJSGlobalClass::do_SyncEvent(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString s;
	bool okresult = false;
	if (ioParms.IsStringParam(1))
	{	ioParms.GetStringParam(1, s);
		if (!s.IsEmpty())
		{
			jsSyncEvent* sync = jsSyncEvent::RetainSyncEvent(s);
			if (sync != nil)
			{
				okresult = true;
				ioParms.ReturnValue(VJSSyncEvent::CreateInstance(ioParms.GetContextRef(), sync));
				sync->Release();
			}
		}
	}
	else
		vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
	if (!okresult)
		ioParms.ReturnNullValue();
}
コード例 #15
0
void VJSGlobalClass::do_GetURLPath(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString s;
	if (ioParms.IsStringParam(1))
	{
		if (ioParms.GetStringParam(1, s))
		{
			VFullURL url(s);
			VJSArray result(ioParms.GetContextRef());
			const VString* next = url.NextPart();
			while (next != NULL)
			{
				VJSValue elem(ioParms.GetContextRef());
				elem.SetString(*next);
				result.PushValue(elem);
				next = url.NextPart();
			}
			ioParms.ReturnValue(result);
		}
	}
	else
		vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
}
コード例 #16
0
void VJSGlobalClass::do_AtomicSection(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString s;
	bool okresult = false;
	if (ioParms.IsStringParam(1))
	{
		ioParms.GetStringParam(1, s);
		if (!s.IsEmpty())
		{
			jsAtomicSection* atomsec = jsAtomicSection::RetainAtomicSection(s);
			if (atomsec != nil)
			{
				okresult = true;
				ioParms.ReturnValue(VJSAtomicSection::CreateInstance(ioParms.GetContextRef(), atomsec));
				atomsec->Release();
			}
		}
	}
	else
		vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
	if (!okresult)
		ioParms.ReturnNullValue();
}
コード例 #17
0
void VJSGlobalClass::do_GetURLQuery(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString s;
	if (ioParms.IsStringParam(1) && ioParms.GetStringParam(1, s))
	{
		VFullURL url(s);
		VJSObject result(ioParms.GetContextRef());
		result.MakeEmpty();
		const VValueBag& values = url.GetValues();
		VIndex nbvalues = values.GetAttributesCount();
		for (VIndex i = 1; i <= nbvalues; i++)
		{
			VString attName;
			const VValueSingle* cv = values.GetNthAttribute(i, &attName);
			if (cv != nil)
			{
				result.SetProperty(attName, cv);
			}
		}
		ioParms.ReturnValue(result);
	}
	else
		vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
}
コード例 #18
0
void VJSStream::_GetBinary (VJSParms_callStaticFunction &ioParms, XBOX::VStream* inStream, bool inIsBuffer)
{
	xbox_assert(inStream != NULL);

	sLONG	size;
	void	*buffer;

	if (!ioParms.GetLongParam(1, &size) || size < 0) {

		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1");
		ioParms.ReturnNullValue();

	} else if (!size) {

		if (inIsBuffer)

			ioParms.ReturnValue(VJSBufferClass::NewInstance(ioParms.GetContext(), 0, NULL));

		else 

			ioParms.ReturnValue(VJSBlob::NewInstance(ioParms.GetContext(), 0, NULL, ""));
			
	} else if ((buffer = ::malloc(size)) == NULL) {
	
		vThrowError(XBOX::VE_MEMORY_FULL);
		ioParms.ReturnNullValue();
	
	} else {

		XBOX::VError	error;
		VSize			bytesRead;

		// Prevent error throwing for XBOX::VE_STREAM_EOF, this will allow to read less than requested.

		{
			StErrorContextInstaller	context(false, true);

			error = inStream->GetData(buffer, size, &bytesRead);
		}

/*
		// Do ::realloc()?

		if (bytesRead < size)

			buffer = ::realloc(buffer, bytesRead);
*/
				
		if (error != XBOX::VE_OK && error != XBOX::VE_STREAM_EOF) {

			XBOX::vThrowError(error);
			ioParms.ReturnNullValue();
			::free(buffer);

		} else {
			
			if (inIsBuffer) 

				ioParms.ReturnValue(VJSBufferClass::NewInstance(ioParms.GetContext(), bytesRead, buffer));

			else

				ioParms.ReturnValue(VJSBlob::NewInstance(ioParms.GetContext(), bytesRead, buffer, ""));

			// Check if instance creation has succeed, if not free memory.

			if (ioParms.GetReturnValue().IsNull())

				::free(buffer);
			
		}	

	}
}
コード例 #19
0
void VJSRequireClass::_evaluate (VJSParms_callStaticFunction &ioParms, void *)
{
	XBOX::VJSContext	context(ioParms.GetContext());
	XBOX::VString		fullPath;
	XBOX::VJSObject		exportsObject(context), moduleObject(context);

	if (!ioParms.GetStringParam(1, fullPath)) {
		
		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
		return;

	}

	if (!ioParms.GetParamObject(2, exportsObject)) {

		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_OBJECT, "2");
		return;

	}

	if (!ioParms.GetParamObject(3, moduleObject)) {

		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_OBJECT, "3");
		return;

	}

	XBOX::VError	error;
	XBOX::VURL		url;
	XBOX::VString	script;
		
	if ((error = VJSModuleState::LoadScript(fullPath, &url, &script)) != XBOX::VE_OK) {

		if (error == XBOX::VE_JVSC_SCRIPT_NOT_FOUND) {

			// Should not happen as require() does already check for existence.

			XBOX::vThrowError(XBOX::VE_JVSC_SCRIPT_NOT_FOUND, fullPath);

		} else

			XBOX::vThrowError(error);
			
	} else {

		XBOX::VFilePath	path(fullPath, FPS_POSIX);
		XBOX::VFile		*file;
			
		if ((file = new XBOX::VFile(path)) == NULL) {

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

			context.GetGlobalObjectPrivateInstance()->RegisterIncludedFile(file);

			XBOX::VString				functionScript;
			XBOX::VJSValue				functionResult(context);
			XBOX::JS4D::ExceptionRef	exception;			

			// Make a function of the module script, then call it.
			
			functionScript.AppendString("(function (exports, module) {");
			functionScript.AppendString(script);
			functionScript.AppendString("})");

			if (!context.EvaluateScript(functionScript, &url, &functionResult, &exception)) {
						
				ioParms.SetException(exception);	// Syntax error.

			} else {

				xbox_assert(functionResult.IsFunction());

				XBOX::VJSObject				functionObject(context);
				std::vector<XBOX::VJSValue>	arguments;
				XBOX::VJSValue				result(context);

				functionObject.SetObjectRef((XBOX::JS4D::ObjectRef) functionResult.GetValueRef());
	
				arguments.push_back(exportsObject);
				arguments.push_back(moduleObject);

				if (!context.GetGlobalObject().CallFunction(functionObject, &arguments, &result, &exception, &path)) 

					ioParms.SetException(exception);

				else 

					ioParms.ReturnValue(result);

			}

			XBOX::ReleaseRefCountable<XBOX::VFile>(&file);

		}

	}	
}
コード例 #20
0
void VJSTextStream::do_TextStream (VJSParms_callStaticFunction &ioParms)
{
	ioParms.ReturnValue(VJSTextStream::_Construct(ioParms));
}