From 00904429489615168b644c4b34ccc54ddd322b24 Mon Sep 17 00:00:00 2001 From: Marko Lahma Date: Fri, 5 Apr 2024 19:12:50 +0300 Subject: [PATCH] Upgrade to Jint 3.0.2 Remove obsolete STJ integration helpers --- src/OrchardCore.Build/Dependencies.props | 2 +- .../JavaScriptEngine.cs | 37 +----------- .../JsonValueConverter.cs | 56 ------------------- src/docs/resources/libraries/README.md | 2 +- 4 files changed, 4 insertions(+), 93 deletions(-) delete mode 100644 src/OrchardCore/OrchardCore.Scripting.JavaScript/JsonValueConverter.cs diff --git a/src/OrchardCore.Build/Dependencies.props b/src/OrchardCore.Build/Dependencies.props index e3b7dd14b40..027601a202b 100644 --- a/src/OrchardCore.Build/Dependencies.props +++ b/src/OrchardCore.Build/Dependencies.props @@ -26,7 +26,7 @@ - + diff --git a/src/OrchardCore/OrchardCore.Scripting.JavaScript/JavaScriptEngine.cs b/src/OrchardCore/OrchardCore.Scripting.JavaScript/JavaScriptEngine.cs index 8dd3421c99f..5e40ce59e01 100644 --- a/src/OrchardCore/OrchardCore.Scripting.JavaScript/JavaScriptEngine.cs +++ b/src/OrchardCore/OrchardCore.Scripting.JavaScript/JavaScriptEngine.cs @@ -23,40 +23,7 @@ public JavaScriptEngine(IMemoryCache memoryCache) public IScriptingScope CreateScope(IEnumerable methods, IServiceProvider serviceProvider, IFileProvider fileProvider, string basePath) { - var engine = new Engine(options => - { - // Make JsonArray behave like JS array. - options.SetWrapObjectHandler(static (e, target, type) => - { - if (target is JsonArray) - { - var wrapped = new ObjectWrapper(e, target) - { - Prototype = e.Intrinsics.Array.PrototypeObject - }; - return wrapped; - } - - return new ObjectWrapper(e, target); - }); - - options.AddObjectConverter(); - - // We cannot access this[string] with anything else than JsonObject, otherwise itw will throw. - options.SetTypeResolver(new TypeResolver - { - MemberFilter = static info => - { - if (info.ReflectedType != typeof(JsonObject) && info.Name == "Item" && info is PropertyInfo p) - { - var parameters = p.GetIndexParameters(); - return parameters.Length != 1 || parameters[0].ParameterType != typeof(string); - } - - return true; - } - }); - }); + var engine = new Engine(); foreach (var method in methods) { @@ -78,7 +45,7 @@ static void ThrowInvalidScopeTypeException() ThrowInvalidScopeTypeException(); } - var parsedAst = _memoryCache.GetOrCreate(script, static entry => Engine.PrepareScript((string)entry.Key)); + var parsedAst = _memoryCache.GetOrCreate(script, static entry => Engine.PrepareScript((string) entry.Key)); var result = jsScope.Engine.Evaluate(parsedAst).ToObject(); diff --git a/src/OrchardCore/OrchardCore.Scripting.JavaScript/JsonValueConverter.cs b/src/OrchardCore/OrchardCore.Scripting.JavaScript/JsonValueConverter.cs deleted file mode 100644 index 5a59b572633..00000000000 --- a/src/OrchardCore/OrchardCore.Scripting.JavaScript/JsonValueConverter.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Text.Json; -using System.Text.Json.Nodes; -using Jint; -using Jint.Native; -using Jint.Runtime.Interop; - -namespace OrchardCore.Scripting.JavaScript; -public class JsonValueConverter : IObjectConverter -{ - public bool TryConvert(Engine engine, object value, out JsValue result) - { - if (value is JsonValue jsonValue) - { - var valueKind = jsonValue.GetValueKind(); - switch (valueKind) - { - case JsonValueKind.Object: - case JsonValueKind.Array: - result = JsValue.FromObject(engine, jsonValue); - break; - case JsonValueKind.String: - result = jsonValue.ToString(); - break; - case JsonValueKind.Number: - if (jsonValue.TryGetValue(out var doubleValue)) - { - result = JsNumber.Create(doubleValue); - } - else - { - result = JsValue.Undefined; - } - break; - case JsonValueKind.True: - result = JsBoolean.True; - break; - case JsonValueKind.False: - result = JsBoolean.False; - break; - case JsonValueKind.Undefined: - result = JsValue.Undefined; - break; - case JsonValueKind.Null: - result = JsValue.Null; - break; - default: - result = JsValue.Undefined; - break; - } - return true; - } - result = JsValue.Undefined; - return false; - - } -} diff --git a/src/docs/resources/libraries/README.md b/src/docs/resources/libraries/README.md index beb62c407a8..8d18e064cb4 100644 --- a/src/docs/resources/libraries/README.md +++ b/src/docs/resources/libraries/README.md @@ -20,7 +20,7 @@ The below table lists the different .NET libraries used in Orchard Core: | [HtmlSanitizer](https://github.com/mganss/HtmlSanitizer) | Cleans HTML to avoid XSS attacks. | 8.1.860-beta | [MIT](https://github.com/mganss/HtmlSanitizer/blob/master/LICENSE.md) | | [Image Sharp](https://github.com/SixLabors/ImageSharp.Web) | Middleware for ASP.NET-Core for image manipulation. | 3.1.1 |[Apache-2.0](https://github.com/SixLabors/ImageSharp.Web/blob/master/LICENSE) | | [Irony.Core](https://github.com/daxnet/irony) | A modified version of the Irony project with .NET Core support | 1.0.7 | [MIT](https://github.com/daxnet/irony/blob/master/LICENSE) | -| [Jint](https://github.com/sebastienros/jint) | Javascript Interpreter for .NET. | 3.0.1 | [MIT](https://github.com/sebastienros/jint/blob/dev/LICENSE) | +| [Jint](https://github.com/sebastienros/jint) | Javascript Interpreter for .NET. | 3.0.2 | [MIT](https://github.com/sebastienros/jint/blob/dev/LICENSE) | | [libphonenumber-csharp](https://github.com/twcclegg/libphonenumber-csharp) | .NET library for parsing, formatting, and validating international phone numbers | 8.13.33 | [Apache-2.0](https://github.com/twcclegg/libphonenumber-csharp/blob/main/LICENSE) | | [Lorem.NET for netstandard](https://github.com/trichards57/Lorem.Universal.NET) | A .NET library for all things random! | 4.0.80 | [MIT](https://github.com/trichards57/Lorem.Universal.NET/blob/master/license.md) | | [Lucene.Net](https://github.com/apache/lucenenet) | .NET full-text search engine. | 4.8.0-beta00016 | [Apache-2.0](https://github.com/apache/lucenenet/blob/master/LICENSE.txt) |