-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix race condition in sharing of function state (#1465)
- Loading branch information
Showing
6 changed files
with
102 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Esprima; | ||
|
||
namespace Jint.Tests.CommonScripts; | ||
|
||
[Parallelizable(ParallelScope.Fixtures)] | ||
public class ConcurrencyTest | ||
{ | ||
[Test] | ||
[TestCase(true)] | ||
[TestCase(false)] | ||
public void ConcurrentEnginesCanUseSameAst(bool prepared) | ||
{ | ||
var scriptContents = SunSpiderTests.GetEmbeddedFile("babel-standalone.js"); | ||
var script = prepared | ||
? Engine.PrepareScript(scriptContents) | ||
: new JavaScriptParser().ParseScript(scriptContents); | ||
|
||
Parallel.ForEach(Enumerable.Range(0, 3), x => | ||
{ | ||
new Engine() | ||
.SetValue("assert", new Action<bool, string>((condition, message)=> { })) | ||
.Evaluate(script); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,72 @@ | ||
using System.Reflection; | ||
using Jint.Runtime; | ||
|
||
namespace Jint.Tests.CommonScripts | ||
namespace Jint.Tests.CommonScripts; | ||
|
||
[Parallelizable(ParallelScope.All)] | ||
public class SunSpiderTests | ||
{ | ||
public class SunSpiderTests | ||
private static void RunTest(string source) | ||
{ | ||
private static void RunTest(string source) | ||
{ | ||
var engine = new Engine() | ||
.SetValue("log", new Action<object>(Console.WriteLine)) | ||
.SetValue("assert", new Action<bool, string>((condition, message) => Assert.True(condition, message))); | ||
var engine = new Engine() | ||
.SetValue("log", new Action<object>(Console.WriteLine)) | ||
.SetValue("assert", new Action<bool, string>((condition, message) => Assert.True(condition, message))); | ||
|
||
try | ||
{ | ||
engine.Execute(source); | ||
} | ||
catch (JavaScriptException je) | ||
{ | ||
throw new Exception(je.ToString()); | ||
} | ||
try | ||
{ | ||
engine.Execute(source); | ||
} | ||
catch (JavaScriptException je) | ||
{ | ||
throw new Exception(je.ToString()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Parallelizable(ParallelScope.All)] | ||
[TestCase("3d-cube.js")] | ||
[TestCase("3d-morph.js")] | ||
[TestCase("3d-raytrace.js")] | ||
[TestCase("access-binary-trees.js")] | ||
[TestCase("access-fannkuch.js")] | ||
[TestCase("access-nbody.js")] | ||
[TestCase("access-nsieve.js")] | ||
[TestCase("bitops-3bit-bits-in-byte.js")] | ||
[TestCase("bitops-bits-in-byte.js")] | ||
[TestCase("bitops-bitwise-and.js")] | ||
[TestCase("bitops-nsieve-bits.js")] | ||
[Test] | ||
[TestCase("3d-cube.js")] | ||
[TestCase("3d-morph.js")] | ||
[TestCase("3d-raytrace.js")] | ||
[TestCase("access-binary-trees.js")] | ||
[TestCase("access-fannkuch.js")] | ||
[TestCase("access-nbody.js")] | ||
[TestCase("access-nsieve.js")] | ||
[TestCase("bitops-3bit-bits-in-byte.js")] | ||
[TestCase("bitops-bits-in-byte.js")] | ||
[TestCase("bitops-bitwise-and.js")] | ||
[TestCase("bitops-nsieve-bits.js")] | ||
#if !DEBUG // should only be ran in release mode when inlining happens | ||
[TestCase("controlflow-recursive.js")] | ||
[TestCase("controlflow-recursive.js")] | ||
#endif | ||
[TestCase("crypto-aes.js")] | ||
[TestCase("crypto-md5.js")] | ||
[TestCase("crypto-sha1.js")] | ||
[TestCase("date-format-tofte.js")] | ||
[TestCase("date-format-xparb.js")] | ||
[TestCase("math-cordic.js")] | ||
[TestCase("math-partial-sums.js")] | ||
[TestCase("math-spectral-norm.js")] | ||
[TestCase("regexp-dna.js")] | ||
[TestCase("string-base64.js")] | ||
[TestCase("string-fasta.js")] | ||
[TestCase("string-tagcloud.js")] | ||
[TestCase("string-unpack-code.js")] | ||
[TestCase("string-validate-input.js")] | ||
[TestCase("babel-standalone.js")] | ||
public void Sunspider(string url) | ||
{ | ||
var content = GetEmbeddedFile(url); | ||
RunTest(content); | ||
} | ||
[TestCase("crypto-aes.js")] | ||
[TestCase("crypto-md5.js")] | ||
[TestCase("crypto-sha1.js")] | ||
[TestCase("date-format-tofte.js")] | ||
[TestCase("date-format-xparb.js")] | ||
[TestCase("math-cordic.js")] | ||
[TestCase("math-partial-sums.js")] | ||
[TestCase("math-spectral-norm.js")] | ||
[TestCase("regexp-dna.js")] | ||
[TestCase("string-base64.js")] | ||
[TestCase("string-fasta.js")] | ||
[TestCase("string-tagcloud.js")] | ||
[TestCase("string-unpack-code.js")] | ||
[TestCase("string-validate-input.js")] | ||
[TestCase("babel-standalone.js")] | ||
public void Sunspider(string url) | ||
{ | ||
var content = GetEmbeddedFile(url); | ||
RunTest(content); | ||
} | ||
|
||
private string GetEmbeddedFile(string filename) | ||
{ | ||
const string prefix = "Jint.Tests.CommonScripts.Scripts."; | ||
internal static string GetEmbeddedFile(string filename) | ||
{ | ||
const string Prefix = "Jint.Tests.CommonScripts.Scripts."; | ||
|
||
var assembly = typeof(SunSpiderTests).GetTypeInfo().Assembly; | ||
var scriptPath = prefix + filename; | ||
var assembly = typeof(SunSpiderTests).GetTypeInfo().Assembly; | ||
var scriptPath = Prefix + filename; | ||
|
||
using var stream = assembly.GetManifestResourceStream(scriptPath); | ||
using var sr = new StreamReader(stream); | ||
return sr.ReadToEnd(); | ||
} | ||
using var stream = assembly.GetManifestResourceStream(scriptPath); | ||
using var sr = new StreamReader(stream); | ||
return sr.ReadToEnd(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters