Script evaluation should not return last function declaration

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 9
    • Affects Version/s: 8
    • Component/s: 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).

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

                Created:
                Updated:
                Resolved: