Skip to content

lib,src: split up big builtin scripts #2714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

module.exports = Duplex;

const util = require('util');
const Readable = require('_stream_readable');
const Writable = require('_stream_writable');
const inherits = require('internal/inherits');

util.inherits(Duplex, Readable);
inherits(Duplex, Readable);

var keys = Object.keys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/_stream_passthrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
module.exports = PassThrough;

const Transform = require('_stream_transform');
const util = require('util');
util.inherits(PassThrough, Transform);
const inherits = require('internal/inherits');
inherits(PassThrough, Transform);

function PassThrough(options) {
if (!(this instanceof PassThrough))
Expand Down
17 changes: 11 additions & 6 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
module.exports = Readable;
Readable.ReadableState = ReadableState;

const EE = require('events').EventEmitter;
const Stream = require('stream');
const Buffer = require('buffer').Buffer;
const util = require('util');
const debug = util.debuglog('stream');
const EE = require('events').EventEmitter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EventEmitter at the end could be removed along with this change I guess.

const Stream = require('internal/stream');
const debug = require('internal/debuglog')('stream');
const inherits = require('internal/inherits');

var Duplex; // Break recursive dependency with _stream_duplex.js.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it should be unnecessary, since _stream_duplex's export is hoisted.

var StringDecoder;

util.inherits(Readable, Stream);
inherits(Readable, Stream);

function ReadableState(options, stream) {
options = options || {};
Expand All @@ -19,7 +21,10 @@ function ReadableState(options, stream) {
// make all the buffer merging and length checks go away
this.objectMode = !!options.objectMode;

if (stream instanceof Stream.Duplex)
if (Duplex === undefined)
Duplex = require('_stream_duplex');

if (stream instanceof Duplex)
this.objectMode = this.objectMode || !!options.readableObjectMode;

// the point at which it stops calling _read() to fill the buffer
Expand Down
4 changes: 2 additions & 2 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
module.exports = Transform;

const Duplex = require('_stream_duplex');
const util = require('util');
util.inherits(Transform, Duplex);
const inherits = require('internal/inherits');
inherits(Transform, Duplex);


function TransformState(stream) {
Expand Down
6 changes: 3 additions & 3 deletions lib/_stream_wrap.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

const assert = require('assert');
const util = require('util');
const Socket = require('net').Socket;
const JSStream = process.binding('js_stream').JSStream;
const uv = process.binding('uv');
const debug = util.debuglog('stream_wrap');
const debug = require('internal/debuglog')('stream_wrap');
const inherits = require('internal/inherits');

function StreamWrap(stream) {
const handle = new JSStream();
Expand Down Expand Up @@ -57,7 +57,7 @@ function StreamWrap(stream) {
handle: handle
});
}
util.inherits(StreamWrap, Socket);
inherits(StreamWrap, Socket);
module.exports = StreamWrap;

// require('_stream_wrap').StreamWrap
Expand Down
24 changes: 17 additions & 7 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
module.exports = Writable;
Writable.WritableState = WritableState;

const util = require('util');
const internalUtil = require('internal/util');
const Stream = require('stream');
const Buffer = require('buffer').Buffer;
const Stream = require('internal/stream');
const inherits = require('internal/inherits');
const internalUtil = require('internal/util');

inherits(Writable, Stream);

util.inherits(Writable, Stream);
var Duplex; // Break recursive dependency with _stream_duplex.js.

function nop() {}

Expand All @@ -30,7 +32,10 @@ function WritableState(options, stream) {
// contains buffers or objects.
this.objectMode = !!options.objectMode;

if (stream instanceof Stream.Duplex)
if (Duplex === undefined)
Duplex = require('_stream_duplex');

if (stream instanceof Duplex)
this.objectMode = this.objectMode || !!options.writableObjectMode;

// the point at which write() starts returning false
Expand Down Expand Up @@ -130,8 +135,13 @@ Object.defineProperty(WritableState.prototype, 'buffer', {
function Writable(options) {
// Writable ctor is applied to Duplexes, though they're not
// instanceof Writable, they're instanceof Readable.
if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
return new Writable(options);
if (!(this instanceof Writable)) {
if (Duplex === undefined)
Duplex = require('_stream_duplex');

if (!(this instanceof Duplex))
return new Writable(options);
}

this._writableState = new WritableState(options, this);

Expand Down
20 changes: 14 additions & 6 deletions lib/console.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const util = require('util');
const format = require('internal/format');


function Console(stdout, stderr) {
if (!(this instanceof Console)) {
Expand Down Expand Up @@ -33,23 +34,30 @@ function Console(stdout, stderr) {
}

Console.prototype.log = function() {
this._stdout.write(util.format.apply(this, arguments) + '\n');
this._stdout.write(format.apply(this, arguments) + '\n');
};


Console.prototype.info = Console.prototype.log;


Console.prototype.warn = function() {
this._stderr.write(util.format.apply(this, arguments) + '\n');
this._stderr.write(format.apply(this, arguments) + '\n');
};


Console.prototype.error = Console.prototype.warn;


var extend;
var inspect;

Console.prototype.dir = function(object, options) {
this._stdout.write(util.inspect(object, util._extend({
if (extend === undefined) {
extend = require('internal/extend');
inspect = require('util').inspect;
}
this._stdout.write(inspect(object, extend({
customInspect: false
}, options)) + '\n');
};
Expand All @@ -75,7 +83,7 @@ Console.prototype.trace = function trace() {
// exposed.
var err = new Error();
err.name = 'Trace';
err.message = util.format.apply(this, arguments);
err.message = format.apply(this, arguments);
Error.captureStackTrace(err, trace);
this.error(err.stack);
};
Expand All @@ -84,7 +92,7 @@ Console.prototype.trace = function trace() {
Console.prototype.assert = function(expression) {
if (!expression) {
var arr = Array.prototype.slice.call(arguments, 1);
require('assert').ok(false, util.format.apply(this, arr));
require('assert').ok(false, format.apply(this, arr));
}
};

Expand Down
10 changes: 5 additions & 5 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

const assert = require('assert');
const Buffer = require('buffer').Buffer;
const util = require('util');
const events = require('events');
const constants = require('constants');

const errnoException = require('internal/errno_exception');
const exceptionWithHostPort = require('internal/exception_with_host_port');
const inherits = require('internal/inherits');

const UDP = process.binding('udp_wrap').UDP;
const SendWrap = process.binding('udp_wrap').SendWrap;

Expand All @@ -17,9 +20,6 @@ const BIND_STATE_BOUND = 2;
var cluster = null;
var dns = null;

const errnoException = util._errnoException;
const exceptionWithHostPort = util._exceptionWithHostPort;

function lookup(address, family, callback) {
if (!dns)
dns = require('dns');
Expand Down Expand Up @@ -101,7 +101,7 @@ function Socket(type, listener) {
if (typeof listener === 'function')
this.on('message', listener);
}
util.inherits(Socket, events.EventEmitter);
inherits(Socket, events.EventEmitter);
exports.Socket = Socket;


Expand Down
23 changes: 12 additions & 11 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'use strict';

const SlowBuffer = require('buffer').SlowBuffer;
const util = require('util');
const pathModule = require('path');

const binding = process.binding('fs');
Expand Down Expand Up @@ -34,7 +33,9 @@ const O_WRONLY = constants.O_WRONLY || 0;
const isWindows = process.platform === 'win32';

const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
const errnoException = util._errnoException;
const errnoException = require('internal/errno_exception');
const extend = require('internal/extend');
const inherits = require('internal/inherits');

function throwOptionsError(options) {
throw new TypeError('Expected options to be either an object or a string, ' +
Expand Down Expand Up @@ -1048,7 +1049,7 @@ function toUnixTimestamp(time) {
if (typeof time === 'number') {
return time;
}
if (util.isDate(time)) {
if (Object.prototype.toString.call(time) === '[object Date]') {
// convert to 123.456 UNIX timestamp
return time.getTime() / 1000;
}
Expand Down Expand Up @@ -1185,7 +1186,7 @@ fs.appendFile = function(path, data, options, callback_) {
}

if (!options.flag)
options = util._extend({ flag: 'a' }, options);
options = extend({ flag: 'a' }, options);
fs.writeFile(path, data, options, callback);
};

Expand All @@ -1198,7 +1199,7 @@ fs.appendFileSync = function(path, data, options) {
throwOptionsError(options);
}
if (!options.flag)
options = util._extend({ flag: 'a' }, options);
options = extend({ flag: 'a' }, options);

fs.writeFileSync(path, data, options);
};
Expand All @@ -1219,7 +1220,7 @@ function FSWatcher() {
}
};
}
util.inherits(FSWatcher, EventEmitter);
inherits(FSWatcher, EventEmitter);

FSWatcher.prototype.start = function(filename, persistent, recursive) {
nullCheck(filename);
Expand Down Expand Up @@ -1289,7 +1290,7 @@ function StatWatcher() {
self.emit('stop');
};
}
util.inherits(StatWatcher, EventEmitter);
inherits(StatWatcher, EventEmitter);


StatWatcher.prototype.start = function(filename, persistent, interval) {
Expand Down Expand Up @@ -1319,7 +1320,7 @@ fs.watchFile = function(filename, options, listener) {
};

if (options !== null && typeof options === 'object') {
options = util._extend(defaults, options);
options = extend(defaults, options);
} else {
listener = options;
options = defaults;
Expand Down Expand Up @@ -1607,7 +1608,7 @@ fs.createReadStream = function(path, options) {
return new ReadStream(path, options);
};

util.inherits(ReadStream, Readable);
inherits(ReadStream, Readable);
fs.ReadStream = ReadStream;

function ReadStream(path, options) {
Expand Down Expand Up @@ -1779,7 +1780,7 @@ fs.createWriteStream = function(path, options) {
return new WriteStream(path, options);
};

util.inherits(WriteStream, Writable);
inherits(WriteStream, Writable);
fs.WriteStream = WriteStream;
function WriteStream(path, options) {
if (!(this instanceof WriteStream))
Expand Down Expand Up @@ -1887,7 +1888,7 @@ function SyncWriteStream(fd, options) {
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
}

util.inherits(SyncWriteStream, Stream);
inherits(SyncWriteStream, Stream);


// Export
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = function assert(expression, message) {
if (!expression)
throw new Error(`Internal assertion failed: ${message || 'no message'}`);
};
25 changes: 25 additions & 0 deletions lib/internal/debuglog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const debugs = {};
var debugEnviron;
var format;

module.exports = function(set) {
if (debugEnviron === undefined)
debugEnviron = process.env.NODE_DEBUG || '';
set = set.toUpperCase();
if (!debugs[set]) {
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
var pid = process.pid;
debugs[set] = function() {
if (format === undefined)
format = require('internal/format');
const msg = format.apply(exports, arguments);
console.error('%s %d: %s', set, pid, msg);
};
} else {
debugs[set] = function() {};
}
}
return debugs[set];
};
17 changes: 17 additions & 0 deletions lib/internal/errno_exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var uv;

module.exports = function errnoException(err, syscall, original) {
if (uv === undefined)
uv = process.binding('uv');
var errname = uv.errname(err);
var message = syscall + ' ' + errname;
if (original)
message += ' ' + original;
var e = new Error(message);
e.code = errname;
e.errno = errname;
e.syscall = syscall;
return e;
};
Loading