Hi again,
The problem is the ambiguity created by bridging two dissimilar runtimes. JavaScript has no method overloading, so once you find the right method, you can coerce or fill in the arguments as necessary. The CLR is exactly the opposite; you need to examine the arguments to find (or even construct) the right method.
Suppose an instance of the following class is exposed to JavaScript:
Which method should be called by the JavaScript expression
On the other hand, this is only a problem when overloaded or generic methods are involved. If we do maximum narrowing of numeric values by default, we may be able to cover more common scenarios without explicit conversion, but no algorithm will work as expected in every situation.
.NET fields and (normal) properties can't be generic or overloaded, so there's no ambiguity. The type of a field or property is always known, so ClearScript can always make an attempt to convert the argument to the correct type.
Thanks!
This is really a awkward limitation. I don't know any language that does not support such conversion in a standard way.
The problem is the ambiguity created by bridging two dissimilar runtimes. JavaScript has no method overloading, so once you find the right method, you can coerce or fill in the arguments as necessary. The CLR is exactly the opposite; you need to examine the arguments to find (or even construct) the right method.
Suppose an instance of the following class is exposed to JavaScript:
publicclass Thing { publicvoid Foo(byte arg) {} publicvoid Foo(sbyte arg) {} }
thing.Foo(123)
?On the other hand, this is only a problem when overloaded or generic methods are involved. If we do maximum narrowing of numeric values by default, we may be able to cover more common scenarios without explicit conversion, but no algorithm will work as expected in every situation.
I found it also strange that ClearScript do support some implicit conversion
.NET fields and (normal) properties can't be generic or overloaded, so there's no ambiguity. The type of a field or property is always known, so ClearScript can always make an attempt to convert the argument to the correct type.
Thanks!