Delete properties in ascending order in js::intrinsic_ArrayNativeSort
Categories
(Core :: JavaScript: Standard Library, enhancement, P3)
Tracking
()
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:
js::intrinsic_ArrayNativeSort: https://searchfox.org/mozilla-central/rev/153feabebc2d13bb4c29ef8adf104ec1ebd246ae/js/src/builtin/Array.cpp#2355-2360MoveHoles: https://searchfox.org/mozilla-central/rev/153feabebc2d13bb4c29ef8adf104ec1ebd246ae/js/src/builtin/Sorting.js#266-267
Test case.
- 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, , ,]
- 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.
Updated•6 years ago
|
| Assignee | ||
Comment 1•5 years ago
|
||
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.)
Comment 3•5 years ago
|
||
| bugherder | ||
Updated•5 years ago
|
Updated•5 years ago
|
Description
•