From 62942e9ad7a59b76e9255ea2560bad2245709efc 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 1ccb289b24791a..b893a934fc7405 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -23,7 +23,7 @@ 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 d89a34e664fe6b..eb889a6eff2106 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 f87c316345ab7f..8d39d468963be5 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 79b9c6d3951a2f..182dab75843f8c 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 cb0d8ec6b65bbe..edbf396cf543d6 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 0e8e5c4cf8baf9..a2ede771ac3fa0 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 { deprecate, normalizeEncoding } = require('internal/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 83c9b429ef6063..32d660a594171c 100644 --- a/lib/internal/fs/watchers.js +++ b/lib/internal/fs/watchers.js @@ -19,7 +19,7 @@ const { const { toNamespacedPath } = require('path'); const { validateUint32 } = require('internal/validators'); const { toPathIfFileURL } = require('internal/url'); -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 23c4e2e0f08893..ae5958912ed05e 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 3405ef43229bcc..158dda2fdc04ee 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 1cea5bf6ced0f0..2726e73272c73d 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 5bb7f8bfcb0970..b267fda4eab1d5 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -37,7 +37,7 @@ const { } } = require('util'); const binding = internalBinding('zlib'); -const assert = require('assert').ok; +const assert = require('internal/assert'); const { Buffer, kMaxLength