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

Call from scoped function to function in with expression has wrong receiver

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • 9
    • None
    • core-libs
    • None

      A call from a nested function that requires a scope object to a function in a with-expression results in the latter function to be called with the global object rather than the with-expression as receiver.

      The following script prints "error: [object global]" in Nashorn. It should not print anything.

      var obj = {f: function() { return this; }};

      with (obj) {
          // a function designed to require a scope
          var s = function() { var m = 1; x = function() { return m; }; return f(); }
          if (s() !== obj) {
            print("error: " + s());
          }
      }

            hannesw Hannes Wallnoefer
            hannesw Hannes Wallnoefer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: