Initialize the engine (context)

Jan 3, 2012 at 3:02 PM
Edited Jan 3, 2012 at 3:05 PM

Hi,

If I write :

 

try
{
	object res;
	res = engine.Run("return 12");
	Console.WriteLine(res.ToString());
	res = engine.Run("double dummy = 8; return dummy;");   //not valid !
	Console.WriteLine(res.ToString());
}
catch (Exception ex)
{
	Console.WriteLine(ex.Message);
}

 

I obtain on the console :

12

12

If I write :

 

try
{
	object res;
	//res = engine.Run("return 12");
	//Console.WriteLine(res.ToString());

	res = engine.Run("double dummy = 8; return dummy;");   //not valid !
	Console.WriteLine(res.ToString());

}
catch (Exception ex)
{
	Console.WriteLine(ex.Message);
}

 

I obtain an exception, because res = null

Why the first run() call has an effect on the second run() call ?

Is there a method to initialize the engine for each call of run() ?

Thanks for your job.

PurL

Jan 12, 2012 at 10:13 AM

The Result of any script is still in memory of jint visitor, so you obtain the first run result in case the second run go null (but maybe it is correct so)

Anyway, this situation is quite important to me too (tnx Purl^).

I did some tests and it seems that jint fails in compiling the script..

If you enter in debug you'll notice that the Program object has 0 statements to execute, but the script still goes on in execution..

I tried different script and i found out lots of keywords (double, goto..) which i think should return a syntax error during compilation, but they do not.

The real problem (to me) is that the script, instead of being stopped in compilation, is executed till the invalid line.. so a lot of commands can be launched and then the script just exits without any error or alert (compromising the next step of my app)

Jan 20, 2012 at 12:33 PM

jint is an interpreter, not a compiler... it will be executed until it finds an error.

 

I faced similar problems that the first post, here is my solution: jeti.codeplex.com

Jan 24, 2012 at 7:26 AM

Hi jorgeleo,

Thanks for your reply and compliments for your project, very nice :)

Anyway.. its not what i need..

The problem here is focused on a syntax check (in my opinion) and is related to the "compile" method of jint..

For example:

If i execute this script:

---

var b = 10;
b++;
aaaaaa a = 10;

---

Jint complier throws an exception.. and the script is not executed at all!

At the same way, if my script contains particular keywords like (double, goto, private...) it should threw the same exception: "An unexpected error occurred while parsing the script" (and you can verify the correct behaviour by using a common browser engine).

The problem is that many keywords have been included in the parser, you find them in ES3.g file.. but there is no interpretation for these words during execution (and is correct because they are not javascript keywords), so i expect them to be catched in a syntax check.