Closed viceice closed 5 years ago
Hello, Michael!
You could give an example of JS code that causes this error.
Simple test case:
_engine.EmbedHostObject("_test", (Action<string>)(c => _engine.Evaluate(c));
_engine.Evaluate("_test('var test;')");
Why are you doing this? You can use a eval
keyword.
What about this:
_engine.EmbedHostObject("_test", (Action<string>)(c => _engine.ExecuteFile($"dist/{c}.js"));
_engine.Evaluate("_test('test')");
I'm trying to implement a simple module system.
Try this variant:
Func<string, string> readFileContent = File.ReadAllText;
_engine.EmbedHostObject("readFileContent", readFileContent);
_engine.Execute(@"function loadModule(moduleName) {
var modulePath = 'dist/' + moduleName + '.js';
var moduleContent = readFileContent(modulePath);
return new Function(moduleContent)();
}");
_engine.CallFunction("loadModule", "test");
That's my workaround 😄
Only here, instead of the eval(…)
expression used the new Function(…)()
, which is more safe.
When there is free time, I will deal with this problem.
Which solution do you prefer, or another solution? I can send a PR.
Which solution do you prefer, or another solution? I can send a PR.
I'll deal with the problem myself, but later.
OK, the new Function
solution is a little bit annoying, because i don't have a filename in the stack traces.
So it is very difficult to find the right source file.
Hello, Michael!
This error is fixed in version 3.0.8.
I'm trying to a simple module loading feature which requires recursive script execution:
net -> js -> net -> js
This is currently not possible, because the scriptdispatcher is blocked by the first
eval
. https://github.com/Taritsyn/JavaScriptEngineSwitcher/blob/753deb75fa62eb82ef1f5ea019a98df708c4eb7d/src/JavaScriptEngineSwitcher.ChakraCore/ScriptDispatcher.cs#L152My current workaround is to use eval, which i don't like. Is there any way to make recursive calls work?