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

Honor Number type hint in toPrimitive on Numbers

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b133
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Since JDK-8143896 not all instances of java.lang.Number are treated as primitive numbers anymore in Nashorn. This affects java longs/Long and all classes implementing java.lang.Number that do not directly represent wrappers of Java primitives.

        However, these Number objects should still convert to JS numbers when passed to the ECMAScript ToPrimitive with Number hint. This would allow to compare these objects numerically in <, <=, >=, and > operators.

        Currently, the code below prints "false" because Longs are converted to strings:

        l1 = new java.lang.Long(2), l2 = new java.lang.Long(10);
        print(l1 < l2);

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: