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

Nashorn: defineProperty setters/getters on prototype object ignored with numeric property names

    XMLWordPrintable

Details

    • b11
    • x86_64
    • generic

    Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      When using Object.defineProperty to define numeric Properties on a prototype-object setting or reading the value on a derived object ignores these setters and getters.
      Using non-numeric properties works, strings containing numeric values don't work.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute script via jjs command line tool:
      // ---
      if(typeof console == 'object') var print = console.log;
      var z = {};
      var s = null, g = null;
      Object.defineProperty(z,'0',{get:function(){g = 1; return 1;},set:function(v){s = v;}});
      var x = Object.create(z);
      x['0'] = 6; x['0'];
      print("getter (1): "+g);
      print("setter (6): "+s);
      // ---

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      getter (1): 1
      setter (6): 6

      nodejs and rhino command line tools produce correct result
      ACTUAL -
      getter (1): null
      setter (6): null

      getters and setters seem to be ignored with nashorn

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.script.ScriptEngineManager;
      import javax.script.ScriptException;

      public class BugNashornGetter {
      public static void main(String[] args) throws ScriptException {
      Object x = new ScriptEngineManager().getEngineByName("js").eval(
      "var s = null; var z = {};\n" +
      "Object.defineProperty(z,'0',{get:function(){return 5;},set:function(v){s = v;}});\n" +
      "var x = Object.create(z);\n" +
      "x['0']=3; "+
      "s");
      System.out.println(x); //Should print 3, but prints null with java 8
      }
      }

      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              hannesw Hannes Wallnoefer
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: