Remove ExpandoObject support from JintJavaScriptEvaluator (#5913)
Removed the `ConverterHelper` and `ExpandoObjectConverter` classes, along with their integration in `JintJavaScriptEvaluator`. Updated unit tests to skip unsupported functionality and added references to related issues for context.
This commit is contained in:
parent
8917bd9d0c
commit
8a417ca765
|
|
@ -1,59 +0,0 @@
|
|||
using System.Collections;
|
||||
using Elsa.Extensions;
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Jint.Native.Object;
|
||||
using Jint.Runtime.Descriptors;
|
||||
|
||||
namespace Elsa.JavaScript.Helpers;
|
||||
|
||||
internal static class ConverterHelper
|
||||
{
|
||||
public static ObjectInstance ConvertToJsObject(Engine engine, IDictionary<string, object?> expando)
|
||||
{
|
||||
var jsObject = engine.Intrinsics.Object.Construct([]);
|
||||
|
||||
foreach (var kvp in expando)
|
||||
{
|
||||
var value = kvp.Value;
|
||||
var jsValue = ConvertToJsValue(engine, value);
|
||||
var propertyDescriptor = new PropertyDescriptor(jsValue, true, true, true);
|
||||
jsObject.DefineOwnProperty(kvp.Key, propertyDescriptor);
|
||||
}
|
||||
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
private static JsValue ConvertToJsValue(Engine engine, object? value)
|
||||
{
|
||||
if (value == null)
|
||||
return JsValue.Null;
|
||||
|
||||
if (value is IDictionary<string, object?> dict)
|
||||
return ConvertToJsObject(engine, dict);
|
||||
|
||||
var valueType = value.GetType();
|
||||
if (valueType.IsCollectionType())
|
||||
{
|
||||
var list = (ICollection)value;
|
||||
var jsArray = engine.Intrinsics.Array.Construct(list.Count);
|
||||
var index = 0;
|
||||
|
||||
foreach (var item in list)
|
||||
jsArray.Set(index++, ConvertToJsValue(engine, item), true);
|
||||
|
||||
return jsArray;
|
||||
}
|
||||
|
||||
if (value is string str)
|
||||
return JsValue.FromObject(engine, str);
|
||||
|
||||
if (value is int or double or float or decimal)
|
||||
return JsValue.FromObject(engine, Convert.ToDouble(value));
|
||||
|
||||
if (value is bool b)
|
||||
return JsValue.FromObject(engine, b);
|
||||
|
||||
return JsValue.FromObject(engine, value);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
using System.Dynamic;
|
||||
using Elsa.JavaScript.Helpers;
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Jint.Runtime.Interop;
|
||||
|
||||
namespace Elsa.JavaScript.ObjectConverters;
|
||||
|
||||
internal class ExpandoObjectConverter : IObjectConverter
|
||||
{
|
||||
public bool TryConvert(Engine engine, object value, out JsValue result)
|
||||
{
|
||||
if (value is ExpandoObject expandoObject)
|
||||
{
|
||||
result = ConverterHelper.ConvertToJsObject(engine, expandoObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
result = JsValue.Null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ public class JintJavaScriptEvaluator(IConfiguration configuration, INotification
|
|||
|
||||
private void ConfigureObjectConverters(Jint.Options options)
|
||||
{
|
||||
options.Interop.ObjectConverters.AddRange([new ByteArrayConverter(), new ExpandoObjectConverter()]);
|
||||
options.Interop.ObjectConverters.AddRange([new ByteArrayConverter()]);
|
||||
}
|
||||
|
||||
private void ConfigureArgumentGetters(Engine engine, ExpressionEvaluatorOptions options)
|
||||
|
|
|
|||
|
|
@ -80,9 +80,11 @@ public class Tests
|
|||
Assert.Equal(43, magicNumber);
|
||||
}
|
||||
|
||||
[Theory(DisplayName = "Can sort array and list properties as mutable arrays")]
|
||||
[Theory(DisplayName = "Can sort array and list properties as mutable arrays", Skip = "Not supported yet. See https://github.com/elsa-workflows/elsa-core/issues/5912")]
|
||||
[MemberData(nameof(ArraySortEnumerableData))]
|
||||
// See also: https://github.com/sebastienros/jint/issues/1942
|
||||
// See also:
|
||||
// - https://github.com/sebastienros/jint/issues/1942
|
||||
// - https://github.com/elsa-workflows/elsa-core/issues/5912
|
||||
public async Task Test5(IEnumerable<double> collection)
|
||||
{
|
||||
dynamic dynamicObject = new ExpandoObject();
|
||||
|
|
|
|||
Loading…
Reference in a new issue