Skip to content

Commit

Permalink
ensure wrapped .NET dictionaries are not array-like
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Jun 1, 2021
1 parent 214063c commit 2894370
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Jint.Tests/Runtime/InteropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2556,5 +2556,12 @@ public void ObjectWrapperOverridingEquality()
Assert.Equal(1, _engine.Evaluate("arr.indexOf(b)").AsNumber());
Assert.True(_engine.Evaluate("arr.includes(b)").AsBoolean());
}

[Fact]
public void ObjectWrapperWrappingDictionaryShouldNotBeArrayLike()
{
var wrapper = new ObjectWrapper(_engine, new Dictionary<string, object>());
Assert.False(wrapper.IsArrayLike);
}
}
}
6 changes: 5 additions & 1 deletion Jint.Tests/Runtime/PromiseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,11 @@ public void PromiseRaceMixturePromisesNoPromises_ResolvesCorrectly4()
public void PromiseRegression_SingleElementArrayWithClrDictionaryInPromiseAll()
{
var engine = new Engine();
var dictionary = new Dictionary<string, object>() { { "Value 1", 1 }, { "Value 2", "a string" } };
var dictionary = new Dictionary<string, object>
{
{ "Value 1", 1 },
{ "Value 2", "a string" }
};
engine.SetValue("clrDictionary", dictionary);

var resultAsObject = engine
Expand Down
6 changes: 6 additions & 0 deletions Jint/Runtime/Interop/TypeDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public static TypeDescriptor Get(Type type)

private static bool DetermineIfObjectIsArrayLikeClrCollection(Type type)
{
if (typeof(IDictionary).IsAssignableFrom(type))
{
// dictionaries are considered normal-object-like
return false;
}

if (typeof(ICollection).IsAssignableFrom(type))
{
return true;
Expand Down

0 comments on commit 2894370

Please sign in to comment.