You are not logged in.
Hello
I'm trying to use TSMEngineManager as an engine to run a JavaScript in Delphi application.
It works fine but I want to put it inside a closed DLL module and run it with a JavaScript as an method argument. But I have encountered a problem. When I create an instance of TSMEngineManager inside a DLL method and free it, then my application crashes after about 5 seconds after the FreeLibrary().
I have reduced my test application to the absolute minimum and it still crashes everytime. Now it doesn't do anything beside creating and freeing the TSMEngineManager. When I remove the creation of TSMEngineManager, it doesn't crash.
Am I doing something wrong?
Delphi version used: XE 10.1 Berlin
Tested on the newest mORMot from here https://github.com/synopse/mORMot (master).
DLL files needed to run the project: libnspr4.dll and mozjs-24.dll (I have both from 2017 - are they the most recent ones?).
Maybe I use wrong version of mozjs-24.dll? I know it's pretty old SM implementation but I'm not sure how to use SM45 or SM52 and where to find new DLLs for it.
Here's the example. It has 2 DPR files only:
---------------------------------------------------------------
DLL file
---------------------------------------------------------------
library JavaScriptRunnerLib;
uses
SynSM,
SynCommons;
{$R *.res}
procedure RunMethodTest(); stdcall;
var
SMEngineManager: TSMEngineManager;
begin
SMEngineManager := TSMEngineManager.Create;
// SMEngineManager.ReleaseCurrentThreadEngine; // < it doesn't help at all
SMEngineManager.Free;
end;
exports
RunMethodTest;
begin
end.
---------------------------------------------------------------
Host application
---------------------------------------------------------------
program JavaScriptRunnerExample;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Winapi.Windows,
System.SysUtils;
type
TRunMethodTestProc = procedure (); stdcall;
const
ScriptRunnerLibFileName = 'JavaScriptRunnerLib.dll';
function LoadScriptRunnerLibrary: THandle;
begin
result := LoadLibrary(ScriptRunnerLibFileName);
// result := SafeLoadLibrary(ScriptRunnerLibFileName, SEM_FAILCRITICALERRORS); // < it doesn't help
if result = 0 then
raise exception.CreateFmt('Error loading library %s', [ScriptRunnerLibFileName]);
end;
procedure Test2;
var
LibHandle: THandle;
RunMethodTestProc: TRunMethodTestProc;
begin
LibHandle := LoadScriptRunnerLibrary;
try
RunMethodTestProc := GetProcAddress(LibHandle, 'RunMethodTest');
RunMethodTestProc();
finally
FreeLibrary(LibHandle); // < after this command the application will crash within about 5 seconds
// If I don't use the FreeLibrary() it won't crash but I need to it
end;
end;
begin
ReportMemoryLeaksOnShutdown := true;
try
writeln('start');
Test2;
writeln('sleep');
sleep(5000);
writeln('after sleep - press enter');
//probably it will crash before this line
Readln;
writeln('ok');
except
on E: exception do
begin
writeln(E.ClassName, ': ', E.Message);
readln;
end;
end;
end.
Thank you for any help.
Offline
Wokring SyNode version is currently in feature/synodeCleanup brunch. It's for SpiderMonkey52. Links to compiled DLLs is in the SyNode/README.md.
But after Mozilla rewrote most of the part of SpiderMonkey using C++ we lost Deplhi compatibility - please, see this discussion https://synopse.info/forum/viewtopic.php?id=5442.
We use a FPC 3.2.0 (x64) for both Windows and Linux.
In case you do not need a NodeJS build-in modules and JavaScript Debugger the good choice is a Chakra Core wrapper. Chakra API is MUCH simple compared to SM and exported as C.
Or pure Delphi besen ECMAScript (no JIT optimization)
Offline
Any plans to regain Delphi compatibility? Is there any reason I shouldn't feel comfortable building my application around an older version that is compatible with Delphi?
Offline
A solution for how to import a variable exported by DLL - see this discussion in Delphi should be found to return a Delphi compatibility.
We uses an older version that is compatible with Delphi in production before, so yes, it can be used. But it lack some new features we add to latest version, mostly a nodeJS compatibility (at last hashes in crypto)
Offline
Precompiled binary can be downloaded here:
- Win x32: https://unitybase.info/media/files/synm … 32dlls.zip
- Win x64: https://unitybase.info/media/files/synm … 64dlls.zip
- Linux x64: https://unitybase.info/media/files/libsynmozjs52.zip
It seems, links are broken
Offline
Unable to connect.
Firefox can’t establish a connection to the server at unitybase.info.
I checked also from tor browser, just in case (with IP address from France).
Last edited by George (2021-07-25 08:05:25)
Offline
I am from France, and I can access the link with no problem.
I can't ping unitybase.info (I guess this is on purpose) but it is resolved as 91.214.182.35
You may have a DNS issue.
Offline
Ping unitybase.info reports same ip 91.214.182.35
I believe this is some sort of cross country restrictions.
But i have no idea how it affects tor browser as well.
I tested from 4 separate ISPs and 3 different devices from different networks (and from mobile phone as well).
Offline
If this is cros country restriction, I think this is is not from my side. unitybase.info is hosted on our private cloud and we do not add any restriction there.
Please, try a google drive - https://drive.google.com/drive/folders/ … sp=sharing
Last edited by mpv (2021-07-25 19:02:09)
Offline
Thank you mpv!
Offline
mORMot 2 looks so pretty, and seems, SM engine will be included as well.
In mORMot 1.18, in order to get working SyNode, we must use separate branch.
How it will be implemented in mORMot2 - will the SyNode code appear on the master branch?
Offline