diff --git a/lib/_linklist.js b/lib/_linklist.js index 02186cfedcb9f6..08ecbea828b666 100644 --- a/lib/_linklist.js +++ b/lib/_linklist.js @@ -1,57 +1,6 @@ 'use strict'; -function init(list) { - list._idleNext = list; - list._idlePrev = list; -} -exports.init = init; +const msg = require('internal/util').printDeprecationMessage; - -// show the most idle item -function peek(list) { - if (list._idlePrev == list) return null; - return list._idlePrev; -} -exports.peek = peek; - - -// remove the most idle item from the list -function shift(list) { - var first = list._idlePrev; - remove(first); - return first; -} -exports.shift = shift; - - -// remove a item from its list -function remove(item) { - if (item._idleNext) { - item._idleNext._idlePrev = item._idlePrev; - } - - if (item._idlePrev) { - item._idlePrev._idleNext = item._idleNext; - } - - item._idleNext = null; - item._idlePrev = null; -} -exports.remove = remove; - - -// remove a item from its list and place at the end. -function append(list, item) { - remove(item); - item._idleNext = list._idleNext; - list._idleNext._idlePrev = item; - item._idlePrev = list; - list._idleNext = item; -} -exports.append = append; - - -function isEmpty(list) { - return list._idleNext === list; -} -exports.isEmpty = isEmpty; +module.exports = require('internal/linkedlist'); +msg('_linklist module is deprecated. Please use a userland alternative.'); diff --git a/lib/internal/linkedlist.js b/lib/internal/linkedlist.js new file mode 100644 index 00000000000000..02186cfedcb9f6 --- /dev/null +++ b/lib/internal/linkedlist.js @@ -0,0 +1,57 @@ +'use strict'; + +function init(list) { + list._idleNext = list; + list._idlePrev = list; +} +exports.init = init; + + +// show the most idle item +function peek(list) { + if (list._idlePrev == list) return null; + return list._idlePrev; +} +exports.peek = peek; + + +// remove the most idle item from the list +function shift(list) { + var first = list._idlePrev; + remove(first); + return first; +} +exports.shift = shift; + + +// remove a item from its list +function remove(item) { + if (item._idleNext) { + item._idleNext._idlePrev = item._idlePrev; + } + + if (item._idlePrev) { + item._idlePrev._idleNext = item._idleNext; + } + + item._idleNext = null; + item._idlePrev = null; +} +exports.remove = remove; + + +// remove a item from its list and place at the end. +function append(list, item) { + remove(item); + item._idleNext = list._idleNext; + list._idleNext._idlePrev = item; + item._idlePrev = list; + list._idleNext = item; +} +exports.append = append; + + +function isEmpty(list) { + return list._idleNext === list; +} +exports.isEmpty = isEmpty; diff --git a/lib/timers.js b/lib/timers.js index 5a0a8ab271e549..0dc9ed80b7e577 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -1,7 +1,7 @@ 'use strict'; const Timer = process.binding('timer_wrap').Timer; -const L = require('_linklist'); +const L = require('internal/linkedlist'); const assert = require('assert').ok; const util = require('util'); const debug = util.debuglog('timer'); diff --git a/node.gyp b/node.gyp index 386074be796d8a..b35c8a508a7589 100644 --- a/node.gyp +++ b/node.gyp @@ -17,7 +17,6 @@ 'src/node.js', 'lib/_debug_agent.js', 'lib/_debugger.js', - 'lib/_linklist.js', 'lib/assert.js', 'lib/buffer.js', 'lib/child_process.js', @@ -39,6 +38,7 @@ 'lib/_http_outgoing.js', 'lib/_http_server.js', 'lib/https.js', + 'lib/_linklist.js', 'lib/module.js', 'lib/net.js', 'lib/os.js', @@ -70,9 +70,10 @@ 'lib/zlib.js', 'lib/internal/child_process.js', 'lib/internal/freelist.js', + 'lib/internal/linkedlist.js', 'lib/internal/module.js', - 'lib/internal/socket_list.js', 'lib/internal/repl.js', + 'lib/internal/socket_list.js', 'lib/internal/util.js', 'lib/internal/streams/lazy_transform.js', ], diff --git a/test/parallel/test-timers-linked-list.js b/test/parallel/test-timers-linked-list.js index 00b2129d126c4a..0c76af970a1fb7 100644 --- a/test/parallel/test-timers-linked-list.js +++ b/test/parallel/test-timers-linked-list.js @@ -1,8 +1,13 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var L = require('_linklist'); +// Flags: --expose-internals + +const common = require('../common'); +const assert = require('assert'); +const L = require('_linklist'); +const internalL = require('internal/linkedlist'); + +assert.strictEqual(L, internalL); var list = { name: 'list' }; var A = { name: 'A' };