You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Jint 2.11.58v. I'm trying to understand how to use the engine's EnterExecutionContext/LeaveExecutionContext methods. I would like to reset the engine after a certain operation. For example, in the following code, I don't expect to see name printed as foo but it does.
static void Main(string[] args)
{
var engine = new Engine();
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
var ctx = engine.ExecutionContext;
var lexEnv = LexicalEnvironment.NewDeclarativeEnvironment(engine, ctx.LexicalEnvironment);
var varEnv = LexicalEnvironment.NewDeclarativeEnvironment(engine, ctx.VariableEnvironment);
engine.EnterExecutionContext(lexEnv, varEnv, ctx.ThisBinding);
var x = engine.SetValue("name", "foo");
Console.WriteLine("First " + engine.GetValue("name"));
engine.LeaveExecutionContext();
}
else
{
Console.WriteLine("Second " + engine.GetValue("name"));
}
}
}
Is there any other way I can reset the state of the engine between calls?
The text was updated successfully, but these errors were encountered:
ShadowRealm was merged to main and it might contain the functionality requested here, see Jint test case how it isolates a playground from the actual engine.
Currently, in MelonJS I am using a quick "dirty" hack: recreating the engine as new everytime I want to restart it and injecting what I want. It is not the best solution here, but for a PoC is working fine.
I'm using Jint 2.11.58v. I'm trying to understand how to use the engine's EnterExecutionContext/LeaveExecutionContext methods. I would like to reset the engine after a certain operation. For example, in the following code, I don't expect to see
name
printed asfoo
but it does.Is there any other way I can reset the state of the engine between calls?
The text was updated successfully, but these errors were encountered: