-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
8, 11, 12.0.1, 14
-
x86_64
-
generic
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
#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