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

A defect of Array.prototype.lastIndexOf method

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 8, 11, 12.0.1, 14
    • Fix Version/s: None
    • Component/s: core-libs

      Description

      A DESCRIPTION OF THE PROBLEM :
      #Testcase:
      var foo = function () {
      var targetObj = ['hello', 'world'];
      var obj = {
      0: targetObj,
      1: 1234,
      2: targetObj,
      4294967294: targetObj,
      4294967295: targetObj,
      length: 4294967299
      };
      return Array.prototype.lastIndexOf.call(obj, targetObj);
      };
      var result = foo();
      print(result);

      #Command:
      ./nashorn/jdk-12.0.1/bin/jjs --language=es6 testcase.js

      #Result:
      Warning: The jjs tool is planned to be removed from a future JDK release
      2


      #Description:
      When using the above testcase, jjs outputs 2 which is the wrong result. This is caused by a defect of ES5.1. If the length of an object is more than 2^32, the result will be wrong because the ToUint32 method will let len%2^32 which makes the lastIndexOf method search the target object from index 2 in this testcase.
      So we suggest that it’s better to update the Array.prototype.lastIndexOf method according to ES2015.
      Reference 1: http://www.ecma-international.org/ecma-262/5.1/index.html#sec-15.4.4.15
      Reference 2: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-array.prototype.lastindexof


        Attachments

          Activity

            People

            • Assignee:
              hannesw Hannes Wallnoefer
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: