paulbartrum / jurassic

A .NET library to parse and execute JavaScript code.
MIT License
868 stars 121 forks source link

Bug in Evaluate: Loop and variable handling #218

Closed Hansann closed 2 years ago

Hansann commented 2 years ago

Hi,

I have tried to use the Evaluate method and found some bugs.

Please take look at the examples below.

EXAMPLE JS code 1:

var str = "Buzz";
for (var i = 0; i < str.length; i++)
{
  str[i];
}

For each iteration in the loop it should output a character. But this code will only print z. It should print Buzz.

EXAMPLE JS code 2:

var str = "Buzz";
var b = "";

for (var i = 0; i < str.length; i++)
{
  b +=str[i];
}

This code will print Buzz. It should not print anything, because variable b is only getting appending.

paulbartrum commented 2 years ago

Try opening the console in your browser (F12 > Console in Chrome) and pasting your examples in there. When I try that the first example does give "z" and the second example does give "Buzz". So the behavior in Jurassic is correct, as far as I can tell.

Evaluate() just returns the last executed expression. If you want to print to the console see here.

Hansann commented 2 years ago

Hi there! Yes i agree - you are right about that. I guess i was looking for console behaviour. Thank you!