diff --git a/lib/_http_common.js b/lib/_http_common.js index 52cabd87fdfcab..b33e38e08dcf3e 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -25,7 +25,7 @@ const binding = process.binding('http_parser'); const methods = binding.methods; const HTTPParser = binding.HTTPParser; -const FreeList = require('internal/freelist').FreeList; +const FreeList = require('internal/freelist'); const ondrain = require('internal/http').ondrain; const incoming = require('_http_incoming'); const IncomingMessage = incoming.IncomingMessage; diff --git a/lib/internal/freelist.js b/lib/internal/freelist.js index ed1084753b1d9a..1096bb2b8e09ba 100644 --- a/lib/internal/freelist.js +++ b/lib/internal/freelist.js @@ -22,4 +22,4 @@ class FreeList { } } -module.exports = {FreeList}; +module.exports = FreeList; diff --git a/lib/internal/fs.js b/lib/internal/fs.js index 97a4c16aed19b5..e7a7299b344355 100644 --- a/lib/internal/fs.js +++ b/lib/internal/fs.js @@ -4,16 +4,17 @@ const Buffer = require('buffer').Buffer; const Writable = require('stream').Writable; const fs = require('fs'); const util = require('util'); -const constants = process.binding('constants').fs; - -const O_APPEND = constants.O_APPEND | 0; -const O_CREAT = constants.O_CREAT | 0; -const O_EXCL = constants.O_EXCL | 0; -const O_RDONLY = constants.O_RDONLY | 0; -const O_RDWR = constants.O_RDWR | 0; -const O_SYNC = constants.O_SYNC | 0; -const O_TRUNC = constants.O_TRUNC | 0; -const O_WRONLY = constants.O_WRONLY | 0; + +const { + O_APPEND, + O_CREAT, + O_EXCL, + O_RDONLY, + O_RDWR, + O_SYNC, + O_TRUNC, + O_WRONLY +} = process.binding('constants').fs; function assertEncoding(encoding) { if (encoding && !Buffer.isEncoding(encoding)) { diff --git a/lib/internal/module.js b/lib/internal/module.js index a2f990ee643073..49bd9b84eee9a1 100644 --- a/lib/internal/module.js +++ b/lib/internal/module.js @@ -1,14 +1,5 @@ 'use strict'; -exports = module.exports = { - makeRequireFunction, - stripBOM, - stripShebang, - addBuiltinLibsToObject -}; - -exports.requireDepth = 0; - // Invoke with makeRequireFunction(module) where |module| is the Module object // to use as the context for the require() function. function makeRequireFunction(mod) { @@ -85,7 +76,7 @@ function stripShebang(content) { return content; } -exports.builtinLibs = [ +const builtinLibs = [ 'assert', 'buffer', 'child_process', 'cluster', 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'net', 'os', 'path', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'tls', 'tty', @@ -94,7 +85,7 @@ exports.builtinLibs = [ function addBuiltinLibsToObject(object) { // Make built-in modules available directly (loaded lazily). - exports.builtinLibs.forEach((name) => { + builtinLibs.forEach((name) => { // Goals of this mechanism are: // - Lazy loading of built-in modules // - Having all built-in modules available as non-enumerable properties @@ -130,3 +121,12 @@ function addBuiltinLibsToObject(object) { }); }); } + +module.exports = exports = { + addBuiltinLibsToObject, + builtinLibs, + makeRequireFunction, + requireDepth: 0, + stripBOM, + stripShebang +}; diff --git a/lib/internal/process.js b/lib/internal/process.js index 236c0f7da3d496..921b693df3299f 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -9,16 +9,6 @@ function lazyConstants() { return _lazyConstants; } -exports.setup_cpuUsage = setup_cpuUsage; -exports.setup_hrtime = setup_hrtime; -exports.setupMemoryUsage = setupMemoryUsage; -exports.setupConfig = setupConfig; -exports.setupKillAndExit = setupKillAndExit; -exports.setupSignalHandlers = setupSignalHandlers; -exports.setupChannel = setupChannel; -exports.setupRawDebug = setupRawDebug; - - const assert = process.assert = function(x, msg) { if (!x) throw new Error(msg || 'assertion error'); }; @@ -267,3 +257,14 @@ function setupRawDebug() { rawDebug(format.apply(null, arguments)); }; } + +module.exports = { + setup_cpuUsage, + setup_hrtime, + setupMemoryUsage, + setupConfig, + setupKillAndExit, + setupSignalHandlers, + setupChannel, + setupRawDebug +}; diff --git a/lib/internal/streams/BufferList.js b/lib/internal/streams/BufferList.js index 76da94bc83d977..b9bdfa7d0ea0ea 100644 --- a/lib/internal/streams/BufferList.js +++ b/lib/internal/streams/BufferList.js @@ -2,71 +2,71 @@ const Buffer = require('buffer').Buffer; -module.exports = BufferList; +module.exports = class BufferList { + constructor() { + this.head = null; + this.tail = null; + this.length = 0; + } -function BufferList() { - this.head = null; - this.tail = null; - this.length = 0; -} + push(v) { + const entry = { data: v, next: null }; + if (this.length > 0) + this.tail.next = entry; + else + this.head = entry; + this.tail = entry; + ++this.length; + } -BufferList.prototype.push = function(v) { - const entry = { data: v, next: null }; - if (this.length > 0) - this.tail.next = entry; - else + unshift(v) { + const entry = { data: v, next: this.head }; + if (this.length === 0) + this.tail = entry; this.head = entry; - this.tail = entry; - ++this.length; -}; + ++this.length; + } -BufferList.prototype.unshift = function(v) { - const entry = { data: v, next: this.head }; - if (this.length === 0) - this.tail = entry; - this.head = entry; - ++this.length; -}; + shift() { + if (this.length === 0) + return; + const ret = this.head.data; + if (this.length === 1) + this.head = this.tail = null; + else + this.head = this.head.next; + --this.length; + return ret; + } -BufferList.prototype.shift = function() { - if (this.length === 0) - return; - const ret = this.head.data; - if (this.length === 1) + clear() { this.head = this.tail = null; - else - this.head = this.head.next; - --this.length; - return ret; -}; - -BufferList.prototype.clear = function() { - this.head = this.tail = null; - this.length = 0; -}; + this.length = 0; + } -BufferList.prototype.join = function(s) { - if (this.length === 0) - return ''; - var p = this.head; - var ret = '' + p.data; - while (p = p.next) - ret += s + p.data; - return ret; -}; + join(s) { + if (this.length === 0) + return ''; + var p = this.head; + var ret = '' + p.data; + while (p = p.next) + ret += s + p.data; + return ret; + } -BufferList.prototype.concat = function(n) { - if (this.length === 0) - return Buffer.alloc(0); - if (this.length === 1) - return this.head.data; - const ret = Buffer.allocUnsafe(n >>> 0); - var p = this.head; - var i = 0; - while (p) { - p.data.copy(ret, i); - i += p.data.length; - p = p.next; + concat(n) { + if (this.length === 0) + return Buffer.alloc(0); + if (this.length === 1) + return this.head.data; + const ret = Buffer.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + while (p) { + p.data.copy(ret, i); + i += p.data.length; + p = p.next; + } + return ret; } - return ret; }; diff --git a/test/parallel/test-freelist.js b/test/parallel/test-freelist.js index 8ec7134dad0eb5..d1f7d888c03868 100644 --- a/test/parallel/test-freelist.js +++ b/test/parallel/test-freelist.js @@ -4,12 +4,11 @@ require('../common'); const assert = require('assert'); -const freelist = require('internal/freelist'); +const FreeList = require('internal/freelist'); -assert.strictEqual(typeof freelist, 'object'); -assert.strictEqual(typeof freelist.FreeList, 'function'); +assert.strictEqual(typeof FreeList, 'function'); -const flist1 = new freelist.FreeList('flist1', 3, String); +const flist1 = new FreeList('flist1', 3, String); // Allocating when empty, should not change the list size const result = flist1.alloc('test'); diff --git a/test/parallel/test-internal-modules-expose.js b/test/parallel/test-internal-modules-expose.js index ab48e36881268c..a3fd6f63ffe399 100644 --- a/test/parallel/test-internal-modules-expose.js +++ b/test/parallel/test-internal-modules-expose.js @@ -7,5 +7,5 @@ const config = process.binding('config'); console.log(config, process.argv); -assert.strictEqual(typeof require('internal/freelist').FreeList, 'function'); +assert.strictEqual(typeof require('internal/freelist'), 'function'); assert.strictEqual(config.exposeInternals, true);