1'use strict'; 2 3const { 4 ReflectApply, 5} = primordials; 6 7class FreeList { 8 constructor(name, max, ctor) { 9 this.name = name; 10 this.ctor = ctor; 11 this.max = max; 12 this.list = []; 13 } 14 15 hasItems() { 16 return this.list.length > 0; 17 } 18 19 alloc() { 20 return this.list.length > 0 ? 21 this.list.pop() : 22 ReflectApply(this.ctor, this, arguments); 23 } 24 25 free(obj) { 26 if (this.list.length < this.max) { 27 this.list.push(obj); 28 return true; 29 } 30 return false; 31 } 32} 33 34module.exports = FreeList; 35