Function/variable redeclaration bug, different between same context or between contexts



This is a three part problem.
If one re-declares a function one will not get any warning by the jint engine.
The problem gets more complicated when depending on how you execute the code either the first or the second declaration of the function will be executed.

I found this second problem, because I treat the code slightly differently when running from when debugging.

In the normal run case, it will go through a list of files and run each of them, basically doing something like:
// simplified pseudo code for clarity

Below is sample code for the two files, where test1() is declared three times.

// File 1
// first one
function test1()
// This function will not be called since the function is redefined in the next source file

// File 2
// second one
function test1()
// This definition is what will be executed

// third one
function test1()
// This is hidden due to that above definition takes priority
// If the engine should be consistent then this should take priority
// That is how variable definitions work.
Echo("You will not see this!");


When debugging, I need to merge all the files in memory and keep track line numbers and calculate the right offset to which file should be shown during debug (as well as recalculating this offset for any exception).

So it will basically run:
code = file1+file;

However in this scenario it will call the first declaration (in "file1" which is now merged with the second one into one big code string).
One would expect it to always chose the last re-declaration. I'm guessing this behavior is because it will build some tree or something similar where it will pick the first found function declaration
and this tree is re-init between jintEngine.Run states differently than when finding the re-declaration in the same context.

The best would be to get some sort of warning in both scenarios :)

This got pretty long, I hope the explanation was clear enough :)

Best regards
Closed Oct 3, 2014 at 6:43 PM by sebastienros
Jint has been rewritten and this issue should be fixed in the new version. Please check it on https://github.com/sebastienros/jint or on using the nuget package here: https://www.nuget.org/packages/Jint/