You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I try to use Array.prototype.indexOf with interop collection such as List<T> it returns -1 for any argument until I call something like Object.keys to create properties (actually I'm using SetPrototypeOf with my custom collection, but I think it's not important).
It seems the issue occurs because ObjectInstanceOperations.GetSmallestIndex returns the length of the collection if there are no cached properties for indices.
[Fact]
public void ArrayPrototypeIndexOfWithInteropList()
{
var engine = new Jint.Engine();
engine.SetValue("list", new List<string> { "A", "B", "C" });
// ok: interop methods IndexOf and LastIndexOf of List<T> are used
Assert.Equal(1, engine.Evaluate("list.indexOf('B')"));
Assert.Equal(1, engine.Evaluate("list.lastIndexOf('B')"));
// error: returns -1 because list does not have properties 0, 1 or 2
Assert.Equal(-1, engine.Evaluate("Array.prototype.indexOf.call(list, 'B')"));
// ok: this method does not use GetSmallestIndex
Assert.Equal(1, engine.Evaluate("Array.prototype.lastIndexOf.call(list, 'B')"));
// call any method that creates properties
engine.Execute("Object.keys(list);");
// now this works as expected
Assert.Equal(1, engine.Evaluate("Array.prototype.indexOf.call(list, 'B')"));
}
The text was updated successfully, but these errors were encountered:
If I try to use
Array.prototype.indexOf
with interop collection such asList<T>
it returns-1
for any argument until I call something likeObject.keys
to create properties (actually I'm usingSetPrototypeOf
with my custom collection, but I think it's not important).It seems the issue occurs because
ObjectInstanceOperations.GetSmallestIndex
returns the length of the collection if there are no cached properties for indices.The text was updated successfully, but these errors were encountered: