Replies: 7 comments 3 replies
-
On mobile, but some earlier discussions for starters: Maybe #721 So there's already some detection logic for array likes. ObjectWrapper sniffs some things. The prototype can be a bit tricky if the object is not owned by Jint. I think I went through the thinking process at some point but probably have forgotten. In-place mutating methods would probably require writing (and maintaining!) duplicate set of functions and anything out-of-sync or different behavior would again cause bug reports or hard to debug scenarios. Despite the former worries, I'm not entirely opposing these new features. Maybe need to do it in small bites and having careful consideration with JS semantics vs .NET. |
Beta Was this translation helpful? Give feedback.
-
Some further points:
|
Beta Was this translation helpful? Give feedback.
-
Thinking about dotnet types:
var ilistint = typeof(IList<int>);
var ilistinterfaces = ilistint.GetInterfaces(); // IEnumerator, IEnumerator<int>, ICollection<int>, no IList<int>
var ilistmethods = ilistint.GetMethods(); // IndexOf, Insert, RemoveAt, get_Item, set_Item, no GetEnumerator, no get_Count
var ilist_GetEnumerator = ilistint.GetMethod("GetEnumerator"); // null
public interface IListAndDictionary : IList<string>, IReadOnlyDictionary<int, string> {}
var iboth = typeof(IListAndDictionary);
var ibothinterfaces = iboth.GetInterfaces(); // 6
var ibothmethods = iboth.GetMethods(); // 0
var iboth_GetEnumerator = iboth.GetMethod("GetEnumerator"); // null
|
Beta Was this translation helpful? Give feedback.
-
Some known problems:
[Fact]
public void CanUseIndexOnGenericList()
{
var list = new List<int>() { 3, 4 };
_engine.SetValue("list", list);
_engine.Evaluate("list[1] = 42;");
Assert.Equal(42, _engine.Evaluate("list[1]"));
Assert.Equal(3, list[0]);
Assert.Equal(42, list[1]);
}
|
Beta Was this translation helpful? Give feedback.
-
Problems may occur:
var dict = new Dictionary<int, string>() {
{ 3, "" },
{ 24, "abc" },
}; compared to var dict = { length: 2, 3: "", 24: "abc" }; |
Beta Was this translation helpful? Give feedback.
-
The usage of |
Beta Was this translation helpful? Give feedback.
-
What to do for CLR array-like objects:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
T[]
,IList
,IList<T>
and any class withint Length {get;}
andT this[int]
ObjectWrapper
result = ConvertArray(engine, a);
inbool DefaultObjectConverter.TryConvert()
, wrap array inObjectWrapper
TypeReference
andTypeDescriptor
and set it toObjectWrapper._prototype
. This may break API compatibility.I'll try my best to pass existing tests and add new tests to cover the new features. Any problem? @lahma
Beta Was this translation helpful? Give feedback.
All reactions