No announcement yet.

[CLOSED] [#156] [16.0] Bound-Checked array access?

  • Filter
  • Time
  • Show
Clear All
new posts

    [CLOSED] [#156] [16.0] Bound-Checked array access?

    When writing code to the .NET framework I can safely assume that any out-of-bounds array access will be caught be the runtime and an exception will be thrown.
    This seem to not be the case with Bridge.NET since arrays are mapped to JS arrays which return 'undefined' for out of bounds access.
    Is there a way to make Bridge.NET compile all of my array accesses to bounch-checked ones?

    Hello. Welcome to Bridge!

    Could you share a Deck.NET link demonstrating a simplified sample?


      Sure, here you go:

      if you look in the chrome console you will see this prints "undefined" (not sure why this doesn't show up in the Bridge.NET console.
      What I expect to happen is that this code will throw an exception, since the array access is out of bounds.
      I realize some people would not want this as the default behaviour due to performance degredation so a compilation config for this would be nice.


        Thanks for the sample. I consider this a defect since Bridge does not reproduce the expected result from C#.

        I have created Issue #2466 (duplicate of #156) to track this defect. We will try to fix right away.

        not sure why this doesn't show up in the Bridge.NET console
        Because you are writing directly to the browser developer tools console, not the Bridge Console. Calling Console.WriteLine() will write to the Bridge Console.

        Hope this helps.
        Last edited by geoffrey.mcgill; 2017-03-17 @ 06:52 AM.


          By the way, if you're interested in writing inline JavaScript, I find the inline //@ comment syntax cleaner than using the Script class helpers. Both have their place.

          public class Program
              public static void Main()
                  var arr = new int[5] { 0,1,2,3,4 };
                  var x = arr[6];
                  // Script.Call("console.log", x);
                  //@ console.log(x);
          Hope this helps.


            > duplicate of #156

            It's strange how this bug keeps popping up again and again since 2015...

            > not sure why this doesn't show up in the Bridge.NET console

            What I meant was the when I use the console, I don't see 'undefined' in the output, whereas if I use the js console directly, like the way the was originally, I do see it in the js console

            > //@ console.log(x);

            This is good to know! I didn't see this documented anywhere in this page:


              Fix for issue #156 merged into master branch and will be included in the next Bridge.NET release.