doc,test: fix inspect's sorted compare function
In V8 7.0, the array sorting algorithm was changed to Timsort, which is stable. A compare function returning only `true` or `false` (converted to 0 and 1) cannot work properly. PR-URL: https://github.com/nodejs/node/pull/22992 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
This commit is contained in:
parent
36bdd19a6b
commit
e758d4ab0a
@ -556,7 +556,7 @@ const o1 = {
|
|||||||
};
|
};
|
||||||
console.log(inspect(o1, { sorted: true }));
|
console.log(inspect(o1, { sorted: true }));
|
||||||
// { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set { 1, 2, 3 } }
|
// { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set { 1, 2, 3 } }
|
||||||
console.log(inspect(o1, { sorted: (a, b) => a < b }));
|
console.log(inspect(o1, { sorted: (a, b) => b.localeCompare(a) }));
|
||||||
// { c: Set { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' }
|
// { c: Set { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' }
|
||||||
|
|
||||||
const o2 = {
|
const o2 = {
|
||||||
|
@ -1688,7 +1688,7 @@ assert.strictEqual(
|
|||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
inspect(
|
inspect(
|
||||||
{ a200: 4, a100: 1, a102: 3, a101: 2 },
|
{ a200: 4, a100: 1, a102: 3, a101: 2 },
|
||||||
{ sorted(a, b) { return a < b; } }
|
{ sorted(a, b) { return b.localeCompare(a); } }
|
||||||
),
|
),
|
||||||
'{ a200: 4, a102: 3, a101: 2, a100: 1 }'
|
'{ a200: 4, a102: 3, a101: 2, a100: 1 }'
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user