Skip to content

Commit

Permalink
lib: replace 'assert' with 'internal/assert' for many built-ins
Browse files Browse the repository at this point in the history
Replace large 'assert' module with tiny 'internal/assert' module for
many built-in uses.

PR-URL: #25956
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
  • Loading branch information
Trott authored and targos committed Feb 10, 2019
1 parent 8ade433 commit f40e0fc
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const util = require('util');
const net = require('net');
const url = require('url');
const assert = require('assert').ok;
const assert = require('internal/assert');
const {
_checkIsHttpToken: checkIsHttpToken,
debug,
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

const assert = require('assert').ok;
const assert = require('internal/assert');
const Stream = require('stream');
const util = require('util');
const internalUtil = require('internal/util');
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

const util = require('util');
const net = require('net');
const assert = require('assert').ok;
const assert = require('internal/assert');
const {
parsers,
freeParser,
Expand Down
2 changes: 1 addition & 1 deletion lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

require('internal/util').assertCrypto();

const assert = require('assert');
const assert = require('internal/assert');
const crypto = require('crypto');
const net = require('net');
const tls = require('tls');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const EventEmitter = require('events');
const net = require('net');
const dgram = require('dgram');
const util = require('util');
const assert = require('assert');
const assert = require('internal/assert');

const { Process } = internalBinding('process_wrap');
const {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/cluster/child.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const assert = require('assert');
const assert = require('internal/assert');
const path = require('path');
const EventEmitter = require('events');
const { owner_symbol } = require('internal/async_hooks').symbols;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/cluster/master.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const assert = require('assert');
const assert = require('internal/assert');
const { fork } = require('child_process');
const path = require('path');
const EventEmitter = require('events');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/cluster/shared_handle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const assert = require('assert');
const assert = require('internal/assert');
const dgram = require('internal/dgram');
const net = require('net');

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/crypto/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const {
publicEncrypt: _publicEncrypt
} = internalBinding('crypto');

const assert = require('assert');
const assert = require('internal/assert');
const LazyTransform = require('internal/streams/lazy_transform');

const { inherits } = require('util');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function getMessage(key, args) {
const msg = messages.get(key);

if (util === undefined) util = require('util');
if (assert === undefined) assert = require('assert');
if (assert === undefined) assert = require('internal/assert');

if (typeof msg === 'function') {
assert(
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { toNamespacedPath } = require('path');
const { validateUint32 } = require('internal/validators');
const { toPathIfFileURL } = require('internal/url');
const util = require('util');
const assert = require('assert');
const assert = require('internal/assert');

const kOldStatus = Symbol('kOldStatus');
const kUseBigint = Symbol('kUseBigint');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const assert = require('assert');
const assert = require('internal/assert');
const Stream = require('stream');
const Readable = Stream.Readable;
const binding = internalBinding('http2');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { NativeModule } = require('internal/bootstrap/loaders');
const { pathToFileURL } = require('internal/url');
const util = require('util');
const vm = require('vm');
const assert = require('assert').ok;
const assert = require('internal/assert');
const fs = require('fs');
const internalFS = require('internal/fs/utils');
const path = require('path');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
} = primordials;

const { decorateErrorStack } = require('internal/util');
const assert = require('assert');
const assert = require('internal/assert');
const resolvedPromise = SafePromise.resolve();

function noop() {}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/process/main_thread_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function createSignalHandlers() {
}

function setupChildProcessIpcChannel() {
const assert = require('assert').strict;
const assert = require('internal/assert');

const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
assert(fd >= 0);
Expand Down
9 changes: 5 additions & 4 deletions lib/internal/test/heap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ process.emitWarning(
'internal/test/heap');

const { createHeapDump, buildEmbedderGraph } = internalBinding('heap_utils');
const assert = require('assert');
const assert = require('internal/assert');

// This is not suitable for production code. It creates a full V8 heap dump,
// parses it as JSON, and then creates complex objects from it, leading
Expand Down Expand Up @@ -44,9 +44,10 @@ function createJSHeapDump() {
edgeIndex++;
}

for (const node of nodes)
assert.strictEqual(node.edge_count, node.outgoingEdges.length);

for (const node of nodes) {
assert(node.edge_count === node.outgoingEdges.length,
`${node.edge_count} !== ${node.outgoingEdges.length}`);
}
return nodes;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const {
normalizedArgsSymbol,
makeSyncWrite
} = require('internal/net');
const assert = require('assert');
const assert = require('internal/assert');
const {
UV_EADDRINUSE,
UV_EINVAL
Expand Down
2 changes: 1 addition & 1 deletion lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const {
}
} = require('util');
const binding = internalBinding('zlib');
const assert = require('assert').ok;
const assert = require('internal/assert');
const {
Buffer,
kMaxLength
Expand Down

0 comments on commit f40e0fc

Please sign in to comment.