Permalink
Browse files

Implement TypeReference.HasInstance (#422)

This patch introduces support for instanceof operator on engine symbols
 which are created from a TypeReference.  Instances constructed from a
 TypeReference should be an instance of that CLR type.

 Tests included in InteropTests. Fixes sebastienros/jint#421.
  • Loading branch information...
tylerjwatson authored and sebastienros committed Oct 1, 2017
1 parent 4223c30 commit f04109e400cba99fab4352d024b8ba46c8e164dd
Showing with 23 additions and 1 deletion.
  1. +10 −0 Jint.Tests/Runtime/InteropTests.cs
  2. +13 −1 Jint/Runtime/Interop/TypeReference.cs
@@ -861,6 +861,16 @@ public void ShouldUseSystemIO()
");
}
[Fact]
public void ShouldBeInstanceOfTypeReferenceType()
{
_engine.SetValue("A", typeof(A));
RunTest(@"
var a = new A();
assert(a instanceof A);
");
}
[Fact]
public void ShouldImportNamespace()
{
@@ -63,7 +63,7 @@ public ObjectInstance Construct(JsValue[] arguments)
{
for (var i = 0; i < arguments.Length; i++)
{
var parameterType = method.GetParameters()[i].ParameterType;
var parameterType = method.GetParameters()[i].ParameterType;
if (parameterType == typeof(JsValue))
{
@@ -96,6 +96,18 @@ public ObjectInstance Construct(JsValue[] arguments)
}
public override bool HasInstance(JsValue v)
{
ObjectWrapper wrapper = v.As<ObjectWrapper>();
if (wrapper == null)
{
return base.HasInstance(v);
}
return wrapper.Target.GetType() == this.Type;
}
public override bool DefineOwnProperty(string propertyName, PropertyDescriptor desc, bool throwOnError)
{
if (throwOnError)

0 comments on commit f04109e

Please sign in to comment.