Calling a function from another function in webgl plugin

In my .jslib file I have multiple functions which returns string. Instead of writing the lines that convert the value to string over and over again, I tried to put that code in another function, and call it from other functions whenever needed, but I am getting an error “ConvertToStr is not defined”. I couldn’t figure out how to do it in this context. Or is it not possible at all and every function needs to be standalone and they cannot “see” each other? I tried a couple of ways but failed to use ConvertToStr method from other methods.

var BrowserHelperPlugin =
{

	ConvertToStr : function (thing)
	{
		var bufferSize = lengthBytesUTF8(thing) + 1;
		var buffer = _malloc(bufferSize);
		stringToUTF8(thing, buffer, bufferSize);
		return buffer;
	},

	GetDocumentReferrer : function ()
	{
		var result;
		result = document.referrer;

		return ConvertToStr(result);

		//var bufferSize = lengthBytesUTF8(result) + 1;
		//var buffer = _malloc(bufferSize);
		//stringToUTF8(result, buffer, bufferSize);
		//return buffer;
	},


	GetDocumentLocationHost : function ()
	{
		var result;
		result = document.location.host;

		return ConvertToStrl(result);
		
		//var bufferSize = lengthBytesUTF8(result) + 1;
		//var buffer = _malloc(bufferSize);
		//stringToUTF8(result, buffer, bufferSize);
		//return buffer;
	},


};

mergeInto(LibraryManager.library, BrowserHelperPlugin);

Did you find a solution for this? I’m currently trying to do the same, but so far no success :frowning:
Tried with:

  • this.methodName
  • libname.methodName
  • methodName

So far nothing works.

I could not find a solution to this or even figure out if it is even possible.
But, here is a possible workaround. I did not test if this works.
Instead of calling different methods from the application to get referrer, host etc. When calling the method from your game, you can try passing what you want to get as a parameter, set the ‘result’ accordingly, and then convert it to string. This way you don’t have to re-write the same ConvertToStrl code again. (@kvabakoma)

	var BrowserHelperPlugin =
	{
    

		GetSomething : function (param)
		{
			var result;

			if(param == "locationhost") { result = document.location.host; }
			else if(param == "referrer") { result = document.referrer; }

			var bufferSize = lengthBytesUTF8(result) + 1;
			var buffer = _malloc(bufferSize);
			stringToUTF8(result, buffer, bufferSize);

			return buffer;

		},

	};
     
	mergeInto(LibraryManager.library, BrowserHelperPlugin);