1'use strict'; 2 3// Flags: --expose-internals 4 5require('../common'); 6const assert = require('assert'); 7const FreeList = require('internal/freelist'); 8 9assert.strictEqual(typeof FreeList, 'function'); 10 11const flist1 = new FreeList('flist1', 3, Object); 12 13// Allocating when empty, should not change the list size 14const result = flist1.alloc(); 15assert.strictEqual(typeof result, 'object'); 16assert.strictEqual(flist1.list.length, 0); 17 18// Exhaust the free list 19assert(flist1.free({ id: 'test1' })); 20assert(flist1.free({ id: 'test2' })); 21assert(flist1.free({ id: 'test3' })); 22 23// Now it should not return 'true', as max length is exceeded 24assert.strictEqual(flist1.free({ id: 'test4' }), false); 25assert.strictEqual(flist1.free({ id: 'test5' }), false); 26 27// At this point 'alloc' should just return the stored values 28assert.strictEqual(flist1.alloc().id, 'test3'); 29assert.strictEqual(flist1.alloc().id, 'test2'); 30assert.strictEqual(flist1.alloc().id, 'test1'); 31