How to reset the state of the engine between calls? #1214
Replies: 3 comments
-
|
#789 tries to solve this by allowing you to enter temporary context which is tried to be cleaned after usage. |
Beta Was this translation helpful? Give feedback.
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
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. engine.SetValue("__reset_current_execution__", new Action(() => {
EngineManager.ResetEngine();
engine.SetupFor(BuiltInJsModule.LibrariesAndPolyfills, currentApp, container);
engine.SetupFor(BuiltInJsModule.Engine, currentApp, container);
engine.SetupFor(BuiltInJsModule.Application, currentApp, container);
engine.SetupFor(BuiltInJsModule.Environment, currentApp, container);
engine.SetupFor(BuiltInJsModule.InputOutput, currentApp, container);
engine.SetupFor(BuiltInJsModule.UnsafeScripting, currentApp, container);
engine.SetupFor(BuiltInJsModule.DataManagement, currentApp, container);
engine.SetupFor(BuiltInJsModule.HttpOperations, currentApp, container);
engine.SetupFor(BuiltInJsModule.Tools, currentApp, container);
engine.SetupFor(BuiltInJsModule.Debug, currentApp, container);
engine.SetupFor(BuiltInJsModule.Database, currentApp, container);
}));public static void ResetEngine()
{
JintStatic.CurrentJintEngine = new();
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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
nameprinted asfoobut it does.Is there any other way I can reset the state of the engine between calls?
Beta Was this translation helpful? Give feedback.
All reactions