Announcement

Collapse
No announcement yet.

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

Collapse
X
  • 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?

    #2
    Hello. Welcome to Bridge!

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

    Comment


      #3
      Sure, here you go:

      http://deck.net/b3eba9499435e2a3e0a29ac4c1c4dace

      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.

      Comment


        #4
        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.

        https://deck.net/22d6ce63d0ec81fdbf264ee493c0589b

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

        Comment


          #5
          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.

          https://deck.net/97dac73c06e56929c279e52ade816fd3

          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.

          Comment


            #6
            > 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 bridge.net console, I don't see 'undefined' in the output, whereas if I use the js console directly, like the way the deck.net 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: https://github.com/bridgedotnet/Brid...nal-javascript

            Comment


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

              Comment

              Working...
              X