Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Created Unassigned: DynamicObject: Unable to invoke method with Int argument [89]

0
0
I've been testing some of the ClearScript functionality based on following versions and an ability to invoke DynamicObject methods with various parameters. My testing didn't go far, I immediately started to see issues with Int based arguments for the methods I invoked. Here is a code I used:

```
Module Module1

Sub Main()
Using engine As New V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers, V8ScriptEngineFlags.EnableDebugging, 9222)
With engine
' test dynamic object
.AddHostObject("testDynamicObj", New TestDynamicObject)
.Execute("testDynamicObj.Run(111);")
End With
End Using
End Sub

End Module

Public Class TestDynamicObject
Inherits DynamicObject

Public Overrides Function GetDynamicMemberNames() As IEnumerable(Of String)
Return New List(Of String) From {"Run"}
End Function

Public Overrides Function TryGetMember(binder As GetMemberBinder, ByRef result As Object) As Boolean
Return False
End Function

Public Overrides Function TryInvokeMember(binder As InvokeMemberBinder, args() As Object, ByRef result As Object) As Boolean
result = binder.Name
Return True
End Function
End Class

```
Here is a test results:
* ClearScript 5.3.10 - worked as expected, I've been able to reach TryInvokeMember an execute it.
* ClearScript 5.4/5.4.2.1 - error, unable to reach TryInvokeMember. Error details as following:

```
Microsoft.ClearScript.ScriptEngineException was unhandled
_HResult=-2146233079
_message=Error: An expression of type 'System.Int32' cannot be used to initialize an array of type 'System.Object'
HResult=-2146233079
IsTransient=false
Message=Error: An expression of type 'System.Int32' cannot be used to initialize an array of type 'System.Object'
Source=ClearScriptV8-64
EngineName=2
ErrorDetails=Error: An expression of type 'System.Int32' cannot be used to initialize an array of type 'System.Object'
at Script Document:1:16 -> testDynamicObj.Run(111);
IsFatal=false
StackTrace:
at V8Exception.ThrowScriptEngineException(V8Exception* )
at Microsoft.ClearScript.V8.V8ContextProxyImpl.Execute(String gcDocumentName, String gcCode, Boolean evaluate, Boolean discard)
at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass1b.<Execute>b__19()
at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func`1 func)
at Microsoft.ClearScript.V8.V8ScriptEngine.BaseScriptInvoke[T](Func`1 func)
at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass25`1.<ScriptInvoke>b__24()
at Microsoft.ClearScript.V8.?A0x361e23e8.InvokeAction(Void* pvActionRef)
at Microsoft.ClearScript.V8.V8ContextProxyImpl.InvokeWithLock(Action gcAction)
at Microsoft.ClearScript.V8.V8ScriptEngine.ScriptInvoke[T](Func`1 func)
at Microsoft.ClearScript.V8.V8ScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard)
at Microsoft.ClearScript.ScriptEngine.Execute(String documentName, Boolean discard, String code)
at Microsoft.ClearScript.ScriptEngine.Execute(String documentName, String code)
at Microsoft.ClearScript.ScriptEngine.Execute(String code)
at ClearScript_5._3._9Test.EngineWrapper.RunScriptsExperimental(ScriptToRun scriptToRun, Int32 operationTimeout) in C:\Users\mshakirov\Documents\Visual Studio 2012\Projects\ClearScript-5.3.9Test\ClearScript-5.3.9Test\Module1.vb:line 113
at ClearScript_5._3._9Test.Module1.Main() in C:\Users\mshakirov\Documents\Visual Studio 2012\Projects\ClearScript-5.3.9Test\ClearScript-5.3.9Test\Module1.vb:line 16
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.InvalidOperationException
_HResult=-2146233079
_message=An expression of type 'System.Int32' cannot be used to initialize an array of type 'System.Object'
HResult=-2146233079
IsTransient=false
Message=An expression of type 'System.Int32' cannot be used to initialize an array of type 'System.Object'
Source=System.Core
StackTrace:
at System.Linq.Expressions.Expression.NewArrayInit(Type type, IEnumerable`1 initializers)
at Microsoft.ClearScript.Util.DynamicHelpers.DynamicInvokeMemberBinder.FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
at System.Dynamic.DynamicObject.MetaDynamic.BuildCallMethodWithResult(String methodName, DynamicMetaObjectBinder binder, Expression[] args, DynamicMetaObject fallbackResult, Fallback fallbackInvoke)
at System.Dynamic.DynamicObject.MetaDynamic.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
at Microsoft.ClearScript.Util.DynamicHelpers.InvokeMember(DynamicMetaObject target, IHostInvokeContext context, String name, BindingFlags invokeFlags, Object[] args)
at Microsoft.ClearScript.Util.DynamicHelpers.<>c__DisplayClass7.<TryInvokeMember>b__6()
at Microsoft.ClearScript.Util.DynamicHelpers.TryDynamicOperation[T](Func`1 operation, T& result)
at Microsoft.ClearScript.Util.DynamicHelpers.TryInvokeMember(DynamicMetaObject target, IHostInvokeContext context, String name, BindingFlags invokeFlags, Object[] args, Object& result)
at Microsoft.ClearScript.HostItem.InvokeHostMember(String name, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, CultureInfo culture, Boolean& isCacheable)
at Microsoft.ClearScript.HostItem.InvokeMember(String name, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, CultureInfo culture, Boolean bypassTunneling, Boolean& isCacheable)
at Microsoft.ClearScript.HostItem.InvokeMember(String name, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, CultureInfo culture, Boolean bypassTunneling)
at Microsoft.ClearScript.HostMethod.TryInvoke(IHostInvokeContext context, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, Object& result)
at Microsoft.ClearScript.Util.InvokeHelpers.TryInvokeObject(IHostInvokeContext context, Object target, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, Boolean tryDynamic, Object& result)
at Microsoft.ClearScript.HostItem.InvokeHostMember(String name, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, CultureInfo culture, Boolean& isCacheable)
at Microsoft.ClearScript.HostItem.InvokeMember(String name, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, CultureInfo culture, Boolean bypassTunneling, Boolean& isCacheable)
at Microsoft.ClearScript.HostItem.<>c__DisplayClass4b.<InvokeReflectMember>b__4a()
at Microsoft.ClearScript.ScriptEngine.HostInvoke[T](Func`1 func)
at Microsoft.ClearScript.HostItem.HostInvoke[T](Func`1 func)
at Microsoft.ClearScript.HostItem.InvokeReflectMember(String name, BindingFlags invokeFlags, Object[] wrappedArgs, CultureInfo culture, String[] namedParams, Boolean& isCacheable)
at Microsoft.ClearScript.HostItem.InvokeReflectMember(String name, BindingFlags invokeFlags, Object[] wrappedArgs, CultureInfo culture, String[] namedParams)
at Microsoft.ClearScript.HostItem.System.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeFlags, Binder binder, Object invokeTarget, Object[] wrappedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.ClearScript.HostItem.Microsoft.ClearScript.Util.IDynamic.Invoke(Object[] args, Boolean asConstructor)
at Microsoft.ClearScript.V8.V8ProxyHelpers.InvokeHostObject(Object obj, Object[] args, Boolean asConstructor)
at Microsoft.ClearScript.V8.V8ProxyHelpers.InvokeHostObject(Void* pObject, Object[] args, Boolean asConstructor)
at HostObjectHelpers.Invoke(V8Value* , Void* pvObject, vector<V8Value\,std::allocator<V8Value> >* args, Boolean asConstructor)
InnerException:
```
Just out of curiosity I've tested this with string argument, or non of it at all and it worked just as expected. I didn't test with any other argument type from that point and decided to share this with ClearScript team. Could someone elaborate on this and either point out at problem in the test code or confirm that there is a deeper issue at the ClearScript/V8 levels?

Thanks in advance,
Max


Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images