Skip to content

Commit

Permalink
Include inherited static members in interop member search (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Aug 28, 2022
1 parent 7f80dc8 commit 9e378e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Jint.Tests/Runtime/InteropTests.MemberAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ public void CustomDictionaryPropertyAccessTests()
Assert.Equal(10, engine.Evaluate("dc.c"));
}

[Fact]
public void CanAccessBaseClassStaticFields()
{
var engine = new Engine(options =>
{
options.AllowClr();
});

engine.SetValue("B", TypeReference.CreateTypeReference(engine, typeof(InheritingFromClassWithStatics)));
Assert.Equal(42, engine.Evaluate("B.a").AsNumber());
Assert.Equal(24, engine.Evaluate("B.a = 24; B.a").AsNumber());
}

private class BaseClassWithStatics
{
public static int a = 42;
}

private class InheritingFromClassWithStatics : BaseClassWithStatics
{
}

private static class EchoService
{
public static string Echo(string message) => message;
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Interop/TypeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static ReflectionAccessor ResolveMemberAccessor(Engine engine, Type type
return ConstantValueAccessor.NullAccessor;
}

const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Static;
const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;
return typeResolver.TryFindMemberAccessor(engine, type, name, bindingFlags, indexerToTry: null, out var accessor)
? accessor
: ConstantValueAccessor.NullAccessor;
Expand Down

0 comments on commit 9e378e8

Please sign in to comment.