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 alloc() { 16 return this.list.length > 0 ? 17 this.list.pop() : 18 ReflectApply(this.ctor, this, arguments); 19 } 20 21 free(obj) { 22 if (this.list.length < this.max) { 23 this.list.push(obj); 24 return true; 25 } 26 return false; 27 } 28} 29 30module.exports = FreeList; 31