-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib,test: add freelist deprecation and test
As per the dicussion in #569, this patch issues a deprecation warning when freelist module is required. A test file for freelist is also added. PR-URL: #2176 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Brendan Ashworth <[email protected]>
- Loading branch information
1 parent
a764ac4
commit fef87fe
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
'use strict'; | ||
|
||
const util = require('internal/util'); | ||
|
||
module.exports = require('internal/freelist'); | ||
util.printDeprecationMessage('freelist module is deprecated.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
// Flags: --expose-internals | ||
|
||
const assert = require('assert'); | ||
const freelist = require('freelist'); | ||
const internalFreelist = require('internal/freelist'); | ||
|
||
assert.equal(typeof freelist, 'object'); | ||
assert.equal(typeof freelist.FreeList, 'function'); | ||
assert.strictEqual(freelist, internalFreelist); | ||
|
||
const flist1 = new freelist.FreeList('flist1', 3, String); | ||
|
||
// Allocating when empty, should not change the list size | ||
var result = flist1.alloc('test'); | ||
assert.strictEqual(typeof result, 'string'); | ||
assert.strictEqual(result, 'test'); | ||
assert.strictEqual(flist1.list.length, 0); | ||
|
||
// Exhaust the free list | ||
assert(flist1.free('test1')); | ||
assert(flist1.free('test2')); | ||
assert(flist1.free('test3')); | ||
|
||
// Now it should not return 'true', as max length is exceeded | ||
assert.strictEqual(flist1.free('test4'), false); | ||
assert.strictEqual(flist1.free('test5'), false); | ||
|
||
// At this point 'alloc' should just return the stored values | ||
assert.strictEqual(flist1.alloc(), 'test1'); | ||
assert.strictEqual(flist1.alloc(), 'test2'); | ||
assert.strictEqual(flist1.alloc(), 'test3'); |