Skip to content

Commit

Permalink
Revert "Add thread-safety to AcornParser methods (#71)"
Browse files Browse the repository at this point in the history
This reverts commit 445d929.
  • Loading branch information
tony-jang committed Mar 12, 2024
1 parent 445d929 commit 02dedd1
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions Qsi.MongoDB/Acorn/AcornParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ internal static class AcornParser
{
private static readonly JavascriptContext _javascriptContext;
private static readonly JsonSerializerSettings _serializerSettings;
private static readonly object _lockObj = new();

static AcornParser()
{
Expand Down Expand Up @@ -104,27 +103,18 @@ private static IEnumerable<INode> FlattenNode(INode rootNode)

public static string Execute(string code)
{
lock (_lockObj)
{
return _javascriptContext.Evaluate(code);
}
return _javascriptContext.Evaluate(code);
}

internal static string ParseStrict(string code)
{
lock (_lockObj)
{
_javascriptContext.SetVariable("code", code);
return _javascriptContext.Evaluate("JSON.stringify(acorn.parse(code, {{locations: true}}))");
}
_javascriptContext.SetVariable("code", code);
return _javascriptContext.Evaluate($"JSON.stringify(acorn.parse(code, {{locations: true}}))");
}

internal static string ParseLoose(string code)
{
lock (_lockObj)
{
_javascriptContext.SetVariable("code", code);
return _javascriptContext.Evaluate("JSON.stringify(acorn.loose.LooseParser.parse(code, {{locations: true}}))");
}
_javascriptContext.SetVariable("code", code);
return _javascriptContext.Evaluate($"JSON.stringify(acorn.loose.LooseParser.parse(code, {{locations: true}}))");
}
}
}

0 comments on commit 02dedd1

Please sign in to comment.