<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>199663</bug_id>
          
          <creation_ts>2019-07-10 02:27:57 -0700</creation_ts>
          <short_desc>A defect of Array.prototype.lastIndexOf method</short_desc>
          <delta_ts>2020-04-18 19:59:24 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Local Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>163417</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>yaohouyou</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ashvayka</cc>
    
    <cc>fpizlo</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1551630</commentid>
    <comment_count>0</comment_count>
    <who name="">yaohouyou</who>
    <bug_when>2019-07-10 02:27:57 -0700</bug_when>
    <thetext>Version: &lt;d940b47&gt;
OS: &lt;ubuntu 16.04&gt;

#Testcase:
var foo = function () {
	var targetObj = [&apos;hello&apos;, &apos;world&apos;];
	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:
./webkit/WebKitBuild/Release/bin/jsc testcase.js

#Output:
2

#Expected output:
4294967295


#Description:
When using the above testcase, JSC 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&apos;s better to update the Array.prototype.lastIndexOf method according to ES2015.
The ECMAScript standard references are as follow:
http://www.ecma-international.org/ecma-262/5.1/index.html#sec-15.4.4.15
http://www.ecma-international.org/ecma-262/6.0/index.html#sec-array.prototype.lastindexof

Other more, the output of other engines is 4294967295, such as v8, spiderMonkey, chakra.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1551673</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-07-10 09:05:21 -0700</bug_when>
    <thetext>&lt;rdar://problem/52894578&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1643144</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Shvayka">ashvayka</who>
    <bug_when>2020-04-18 19:59:24 -0700</bug_when>
    <thetext>Thank you for detailed report.
Apart from Array.prototype.lastIndexOf, other Array methods (mostly ones that are implemented in C++) are affected.
I am merging all bug reports to fix all (observable) cases with a single patch.

*** This bug has been marked as a duplicate of bug 163417 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>