From f40e0fcdcb77ad072cf9ce394bb4bad99cc5f359 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 5 Feb 2019 21:45:46 -0800 Subject: [PATCH] lib: replace 'assert' with 'internal/assert' for many built-ins Replace large 'assert' module with tiny 'internal/assert' module for many built-in uses. PR-URL: https://github.com/nodejs/node/pull/25956 Reviewed-By: Ruben Bridgewater Reviewed-By: Minwoo Jung --- lib/_http_client.js | 2 +- lib/_http_outgoing.js | 2 +- lib/_http_server.js | 2 +- lib/_tls_wrap.js | 2 +- lib/internal/child_process.js | 2 +- lib/internal/cluster/child.js | 2 +- lib/internal/cluster/master.js | 2 +- lib/internal/cluster/shared_handle.js | 2 +- lib/internal/crypto/cipher.js | 2 +- lib/internal/errors.js | 2 +- lib/internal/fs/watchers.js | 2 +- lib/internal/http2/compat.js | 2 +- lib/internal/modules/cjs/loader.js | 2 +- lib/internal/modules/esm/module_job.js | 2 +- lib/internal/process/main_thread_only.js | 2 +- lib/internal/test/heap.js | 9 +++++---- lib/net.js | 2 +- lib/zlib.js | 2 +- 18 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index c4259184a6c5b3..fdbce5af266879 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -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, diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 7395a02f331af0..667d07801c6497 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -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'); diff --git a/lib/_http_server.js b/lib/_http_server.js index a22189b486f612..fae91018519dd1 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -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, diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 098ed76f27b5d0..5e3239ae200832 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -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'); diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index ba8bca9220713a..f15bf14d230139 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -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 { diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js index 272b0d2bd95008..38d52948e56da3 100644 --- a/lib/internal/cluster/child.js +++ b/lib/internal/cluster/child.js @@ -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; diff --git a/lib/internal/cluster/master.js b/lib/internal/cluster/master.js index c4f8e2b0efa299..a0e194c63ef3c3 100644 --- a/lib/internal/cluster/master.js +++ b/lib/internal/cluster/master.js @@ -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'); diff --git a/lib/internal/cluster/shared_handle.js b/lib/internal/cluster/shared_handle.js index 0b5f1531931b6c..408657623b2e3b 100644 --- a/lib/internal/cluster/shared_handle.js +++ b/lib/internal/cluster/shared_handle.js @@ -1,5 +1,5 @@ 'use strict'; -const assert = require('assert'); +const assert = require('internal/assert'); const dgram = require('internal/dgram'); const net = require('net'); diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index 0a0514103399a0..0be2ee668ec95f 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -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'); diff --git a/lib/internal/errors.js b/lib/internal/errors.js index d8071e00639a6b..13a6194d0cb016 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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( diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js index e026aa8192c3cf..7bc6f2ac97365a 100644 --- a/lib/internal/fs/watchers.js +++ b/lib/internal/fs/watchers.js @@ -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'); diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index faecf2441ce4c8..8043bd492a8990 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -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'); diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 0da026843f6232..c37233ffd45252 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -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'); diff --git a/lib/internal/modules/esm/module_job.js b/lib/internal/modules/esm/module_job.js index e900babefd6261..016495096c3b33 100644 --- a/lib/internal/modules/esm/module_job.js +++ b/lib/internal/modules/esm/module_job.js @@ -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() {} diff --git a/lib/internal/process/main_thread_only.js b/lib/internal/process/main_thread_only.js index 290d2f7e9e2eb8..0ce063f928974a 100644 --- a/lib/internal/process/main_thread_only.js +++ b/lib/internal/process/main_thread_only.js @@ -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); diff --git a/lib/internal/test/heap.js b/lib/internal/test/heap.js index 3f4a905fc51836..52e00b9da5e136 100644 --- a/lib/internal/test/heap.js +++ b/lib/internal/test/heap.js @@ -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 @@ -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; } diff --git a/lib/net.js b/lib/net.js index d2925b060eb658..46d4994927a6d0 100644 --- a/lib/net.js +++ b/lib/net.js @@ -33,7 +33,7 @@ const { normalizedArgsSymbol, makeSyncWrite } = require('internal/net'); -const assert = require('assert'); +const assert = require('internal/assert'); const { UV_EADDRINUSE, UV_EINVAL diff --git a/lib/zlib.js b/lib/zlib.js index 2a840fe036abad..560435d7f1fff8 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -38,7 +38,7 @@ const { } } = require('util'); const binding = internalBinding('zlib'); -const assert = require('assert').ok; +const assert = require('internal/assert'); const { Buffer, kMaxLength