Bug 186993 - Inconsistent output compared with other JS engines
Summary: Inconsistent output compared with other JS engines
Status: RESOLVED DUPLICATE of bug 184267
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-25 00:09 PDT by sunlili
Modified: 2020-05-07 15:40 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sunlili 2018-06-25 00:09:23 PDT
Hello,
The following code behaves incorrectly (inconsistent with the standard and other engines).

arr0 = [ 1, 2, 3 ];                                                                                                                 
 arr1 = [ 4, 5, 6 ];  
handler1 = { 
    get: function (oTarget, sKey) {
       print('arg ' + '1' + ':get ' + sKey.toString()); 
       if (sKey.toString() == 'Symbol(Symbol.isConcatSpreadable)') { 
          arr0[1] = { undefined: 'a', 1: 'b', 2: 'c' };  
       }   
       if (sKey.toString() == 'length') { 
          arr1['length'] = 100; return 10; 
       }   
       if (Number(sKey.toString()) != NaN) { ; } 
       return Reflect.get(oTarget, sKey);
   },  
   has: function (oTarget, sKey) { 
      print('arg ' + '1' + ':has ' + sKey.toString()); 
      if (Number(sKey.toString()) != NaN) {
           arr1[1] = true; return Symbol.split;
      }   
      return Reflect.has(oTarget, sKey); } 
   };  
var proxy1 = new Proxy(arr1, handler1); 
arr2 = Array.prototype.concat.call(arr0, proxy1); 
print(arr2);

The output is :
arg 1:get Symbol(Symbol.isConcatSpreadable)
arg 1:get Symbol(Symbol.toPrimitive)
arg 1:get toString
arg 1:get join
arg 1:get length
arg 1:get 0
arg 1:get 1
arg 1:get 2
arg 1:get 3
arg 1:get 4
arg 1:get 5
arg 1:get 6
arg 1:get 7
arg 1:get 8
arg 1:get 9
1,[object Object],3,4,5,6,,,,,,,

However, it should be:
arg 1:get Symbol(Symbol.isConcatSpreadable)
arg 1:get length
arg 1:has 0
arg 1:get 0
arg 1:has 1
arg 1:get 1
arg 1:has 2
arg 1:get 2
arg 1:has 3
arg 1:get 3
arg 1:has 4
arg 1:get 4
arg 1:has 5
arg 1:get 5
arg 1:has 6
arg 1:get 6
arg 1:has 7
arg 1:get 7
arg 1:has 8
arg 1:get 8
arg 1:has 9
arg 1:get 9
1,2,3,4,true,6,,,,,,,
Comment 1 Alexey Shvayka 2020-05-07 15:20:06 PDT
(In reply to sunlili from comment #0)
> However, it should be:
> arg 1:get Symbol(Symbol.isConcatSpreadable)
> arg 1:get length

Thank you for detailed reports.
As of r232261, JSC outputs as expected.

*** This bug has been marked as a duplicate of bug 184267 ***