Closed BlazingTwist closed 1 year ago
The behavior you observed is expected with the CheerpJ 2.x architecture, which is currently being deprecated in favor of the new CheerpJ 3. CheerpJ 3 will behave correctly for this test case.
A first release candidate CheerpJ 3.0 will be made available in mid-october, but you can already try out current builds. Please join our Discord for more information: https://discord.gg/X9ruPkchM5
Currently it seems that class initialization is only run once. As a result Java code such as this causes "unexpected" behaviour:
Executing the Main class like this:
Results in this output:
Whereas the expected output would be:
The same behaviour occurs for
Obviously "fixing" that example is trivial, but for more complicated programs this preservation of static fields causes a lot of unexpected side effects.
Ideally there would be some way to restart the JVM / or re-run all static initializers, such that subsequent
cheerpjRunMain
calls start from a fresh slate.For completeness sake, I have attached the full source code / jar / jar.js source.zip
Just to clarify, this does provide the expected output: