I debug javascript running on V8 engine with Visual Studio Code. Whenever I execute a script, the debugger loads a copy of that script. Is this normal?

Below is my code:
using Microsoft.ClearScript;
using Microsoft.ClearScript.V8;
using System;
namespace ClearScriptDemo
{
class Person
{
public string GetName()
{
return "John Doe";
}
}
class Program
{
static void Main(string[] args)
{
using (var engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging, 9222))
{
// expose a host type
engine.AddHostType("Console", typeof(Console));
// expose a host object
engine.AccessContext = typeof(Program);
engine.AddHostObject("person", new Person());
DocumentInfo documentInfo = new DocumentInfo("My Script");
Console.WriteLine("Press any key to run script, ESC to exit.");
while (Console.ReadKey().Key != ConsoleKey.Escape)
{
engine.Execute(documentInfo,
"Console.WriteLine('{0} is an interesting number.', Math.PI);\r\n" +
"Console.WriteLine(person.GetName());");
}
}
}
}
}
Hi @tu-lehong,
This behavior is by design. It's meant to ensure that each script is accessible in the debugger even if the host provided the same name for all of them.
You can avoid this behavior by specifying a URI instead of a name:
C#
Uri uri = new Uri("My Script", UriKind.RelativeOrAbsolute);
DocumentInfo documentInfo = new DocumentInfo(uri);
Keep in mind however that a script with a given URI clobbers any previous script with the same URI, making the latter inaccessible in the debugger.
Good luck!
Thank you!