jint: [BUG] Implicit Conversion from CLR Interface to JSValue Behaviour Changed

Version used

The issue occurs on 3.0.0-beta-2051 and newer versions.

Describe the bug

For the below example. Interface properties no longer support accessing underlying implementation. For example, IList to List. Whilst this may be appropriate for user-defined interfaces, it breaks existing behaviour for framework-managed assemblies.

I can no longer use JavaScript iterative methods on an interface that implements IEnumerable.

Jint.Runtime.JavaScriptException: Property 'forEach' of object is not a function
 ---> Error: Property 'forEach' of object is not a function
   at test (test) <anonymous>:1:23
   at <anonymous>:1:1
   --- End of inner exception stack trace ---
   at Jint.Runtime.ExceptionHelper.ThrowJavaScriptException(Engine engine, JsValue value, Completion& result)
   at Jint.Native.Function.ScriptFunctionInstance.Call(JsValue thisArgument, JsValue[] arguments)
   at Jint.Engine.Call(FunctionInstance functionInstance, JsValue thisObject, JsValue[] arguments, JintExpression expression)
   at Jint.Engine.<>c__DisplayClass119_0.<Call>g__Callback|0()
   at Jint.Engine.ExecuteWithConstraints[T](Boolean strict, Func`1 callback)
   at Jint.Engine.Call(JsValue callable, JsValue thisObject, JsValue[] arguments)
   at Jint.Engine.Call(JsValue callable, JsValue[] arguments)
   at Jint.Engine.Call(String callableName, JsValue[] arguments)

To Reproduce

using Jint;
using Jint.Native;

var engine = new Engine();
engine.Evaluate("function test(listTest) { listTest.list.forEach(x => 1); }");
var foo = JsValue.FromObject(engine, new ListTest());
var arguments = new[] {foo};
engine.Call("test", arguments);

public class ListTest
{
    public IList<int> List { get; set; } = new List<int>();
}

Expected behaviour

The code runs to completion without error.

Additional context

Using version 3.0.0-beta-2050 and below works without issue. (Tested to 2049)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

I’ll fix the SetValue method and everybody passing an interface and expecting to be able to call methods outside of the interface will cry 😂. PR coming up, probably tomorrow though

I’ll have a look