Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8367539

Adding a function to the Array.prototype breaks for each loops

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      nashorn> a = "A,B,C,D".split(",")
      [object Array]
      nashorn> Array.prototype.foo=function(){};
      function(){}
      nashorn> a
      [object Array]
      nashorn> for each(x in a) print (x)
      A
      B
      C
      D
      function(){}

      function() {} is not expected to be in the list of "elements" of the array.

      nashorn> for (i in a) print( i)
      0
      1
      2
      3
      foo

      nashorn> for (i in a.length) print( i)
      nashorn> for (i=0;i<a.length;i++) print( i)
      0
      1
      2
      3

      nashorn> for (i=0;i<a.length;i++) print( a[i])
      A
      B
      C
      D
      nashorn>


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: