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

Script evaluation should not return last function declaration

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8
    • core-libs
    • None
    • b70
    • generic
    • generic

        If Nashorn evaluates a script that only contains function declarations it returns the last declared function as return value. This is against ECMAScript 5.1 section 14 which says that evaluation of a function declaration should not return a value.

        http://es5.github.io/#x14

        We probably introduced this behaviour because Rhino has the same bug, and people have been using this to obtain a reference to a function evaluated in a script.

        One possible way to fix this while still allowing functions to be returned from script evaluation is to only return anonymous function statements (a Nashorn extension).

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

                Created:
                Updated:
                Resolved: