mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
ff2ed3ec85
Remove the hasItems() method from freelist module as it is unused internally. PR-URL: https://github.com/nodejs/node/pull/30744 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Weijia Wang <starkwang@126.com>
31 lines
951 B
JavaScript
31 lines
951 B
JavaScript
'use strict';
|
|
|
|
// Flags: --expose-internals
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const FreeList = require('internal/freelist');
|
|
|
|
assert.strictEqual(typeof FreeList, 'function');
|
|
|
|
const flist1 = new FreeList('flist1', 3, Object);
|
|
|
|
// Allocating when empty, should not change the list size
|
|
const result = flist1.alloc();
|
|
assert.strictEqual(typeof result, 'object');
|
|
assert.strictEqual(flist1.list.length, 0);
|
|
|
|
// Exhaust the free list
|
|
assert(flist1.free({ id: 'test1' }));
|
|
assert(flist1.free({ id: 'test2' }));
|
|
assert(flist1.free({ id: 'test3' }));
|
|
|
|
// Now it should not return 'true', as max length is exceeded
|
|
assert.strictEqual(flist1.free({ id: 'test4' }), false);
|
|
assert.strictEqual(flist1.free({ id: 'test5' }), false);
|
|
|
|
// At this point 'alloc' should just return the stored values
|
|
assert.strictEqual(flist1.alloc().id, 'test3');
|
|
assert.strictEqual(flist1.alloc().id, 'test2');
|
|
assert.strictEqual(flist1.alloc().id, 'test1');
|