Bug 163085 - Handle non-function, non-undefined comparator in Array.prototype.sort
Summary: Handle non-function, non-undefined comparator in Array.prototype.sort
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Keith Miller
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-06 14:19 PDT by Keith Miller
Modified: 2016-10-12 12:43 PDT (History)
4 users (show)

See Also:


Attachments
Patch (3.51 KB, patch)
2016-10-06 14:33 PDT, Keith Miller
no flags Details | Formatted Diff | Diff
Patch for landing (4.29 KB, patch)
2016-10-06 14:53 PDT, Keith Miller
no flags Details | Formatted Diff | Diff
Patch for landing (4.92 KB, patch)
2016-10-12 12:08 PDT, Keith Miller
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Keith Miller 2016-10-06 14:19:44 PDT
This is broken right now, we should fix it.
Comment 1 Keith Miller 2016-10-06 14:33:12 PDT
Created attachment 290866 [details]
Patch
Comment 2 Yusuke Suzuki 2016-10-06 14:38:12 PDT
Comment on attachment 290866 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=290866&action=review

> Source/JavaScriptCore/builtins/ArrayPrototype.js:650
>      else

How about just checking here like `else if (comparator !== @undefined)`?
Comment 3 Keith Miller 2016-10-06 14:41:58 PDT
Comment on attachment 290866 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=290866&action=review

>> Source/JavaScriptCore/builtins/ArrayPrototype.js:650
>>      else
> 
> How about just checking here like `else if (comparator !== @undefined)`?

We need to avoid doing the check if the length of the array is < 2 since that's observably different behavior from other browsers. Although, we could move that check into the main body instead of the helpers. I'll make that change.
Comment 4 Keith Miller 2016-10-06 14:53:21 PDT
Created attachment 290868 [details]
Patch for landing
Comment 5 Keith Miller 2016-10-12 12:08:48 PDT
Created attachment 291380 [details]
Patch for landing
Comment 6 WebKit Commit Bot 2016-10-12 12:43:29 PDT
Comment on attachment 291380 [details]
Patch for landing

Clearing flags on attachment: 291380

Committed r207235: <http://trac.webkit.org/changeset/207235>
Comment 7 WebKit Commit Bot 2016-10-12 12:43:32 PDT
All reviewed patches have been landed.  Closing bug.