kevingadd/JSIL — Issue #40: Error while redefining Array.Get
Author: matra774
Created: 2011-12-01 22:26:19+00:00
State: open

When running in browser (tested with IE9 and FF8), the following code breaks at run time

var x = new int[,] { { 1, 2 }, { 2, 2 } };
Console.WriteLine(x[2, 2].ToString());

Array.Get is implemented in JSIL.MultidimensionalArray which redefines the Get method to:

this.Get = function (y, x) {
return items[(y * width) + x];
};

This has two problems:
* FF complains with "this.Get is read-only"
* IE9 allows to re-define this method, but after JSIL.Initialize() is called, the method get overwritten with a stub that reports "The external method 'Get' of type 'System.Array' has not been implemented". I guess that this is because it is defined as [JSExternal] in Proxies.csproj). If I do not call Jsil.Initialize(), then it works OK in IE9 (but other things are broken).

Probably the best option would be to use different method name 'JsilGet' or something similar.

Any pointers on how to implement the fix. I was unable to find out how to change JSILC to emit differnet method name (the only reference that I have found is in AstmethodBodyBuilder.TransformCall which checks "cecilMethod.Name == "Get"", but breakpoint that was set on this line never fired).

Any help is appreciated.

Matra