Closed Bug 1583528 Opened 6 years ago Closed 5 years ago

Delete properties in ascending order in js::intrinsic_ArrayNativeSort

Categories

(Core :: JavaScript: Standard Library, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla72
Tracking Status
firefox71 --- wontfix
firefox72 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file)

https://github.com/tc39/ecma262/pull/1585#issuecomment-532994188 shows that V8 and SpiderMonkey behave almost the same except when deleting properties. SpiderMonkey is currently deleting extra properties in descending order whereas V8 deletes them in ascending order. To match the proposed spec changes and to match our self-hosting code, we should remove properties in ascending order.

Relevant code lines:


Test case.

  1. Native sort used:
js> new Proxy(new Proxy([, , 0], {}), {deleteProperty(t, pk){ print(`delete ${pk}`); return delete t[pk]; }}).sort()
delete 2
delete 1
[0, , ,]
  1. Self-hosted sort used:
js> new Proxy(new Proxy([, , 0], {}), {deleteProperty(t, pk){ print(`delete ${pk}`); return delete t[pk]; }}).sort((a, b) => a < b ? -1 : a > b ? 1 : 0)
delete 1
delete 2
[0, , ,]

Expected: Properties are deleted in the same (= ascending) order.
Actual: Native sort deletes properties in descending order.

Priority: -- → P3

This ensures our native Array.prototype.sort implementation matches the proposed
semantics in https://github.com/tc39/ecma262/pull/1585. (Our self-hosted
implementation was already deleting the properties in ascending order.)

Pushed by ncsoregi@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/6d6e89a6a2bf Delete properties in ascending order in ArrayNativeSort. r=arai
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla72
Assignee: nobody → andrebargull
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: