lib: remove circular reference
PR-URL: https://github.com/nodejs/node/pull/14885 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
4ca8ff264f
commit
9aa709382a
@ -21,8 +21,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { compare } = process.binding('buffer');
|
const { compare } = process.binding('buffer');
|
||||||
const util = require('util');
|
const { isSet, isMap, isDate, isRegExp } = process.binding('util');
|
||||||
const { isSet, isMap } = process.binding('util');
|
|
||||||
const { objectToString } = require('internal/util');
|
const { objectToString } = require('internal/util');
|
||||||
const errors = require('internal/errors');
|
const errors = require('internal/errors');
|
||||||
|
|
||||||
@ -115,10 +114,9 @@ function areSimilarRegExps(a, b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For small buffers it's faster to compare the buffer in a loop. The c++
|
// For small buffers it's faster to compare the buffer in a loop. The c++
|
||||||
// barrier including the Buffer.from operation takes the advantage of the faster
|
// barrier including the Uint8Array operation takes the advantage of the faster
|
||||||
// compare otherwise. 300 was the number after which compare became faster.
|
// binary compare otherwise. The break even point was at about 300 characters.
|
||||||
function areSimilarTypedArrays(a, b) {
|
function areSimilarTypedArrays(a, b) {
|
||||||
const { from } = require('buffer').Buffer;
|
|
||||||
const len = a.byteLength;
|
const len = a.byteLength;
|
||||||
if (len !== b.byteLength) {
|
if (len !== b.byteLength) {
|
||||||
return false;
|
return false;
|
||||||
@ -131,8 +129,8 @@ function areSimilarTypedArrays(a, b) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return compare(from(a.buffer, a.byteOffset, len),
|
return compare(new Uint8Array(a.buffer, a.byteOffset, len),
|
||||||
from(b.buffer, b.byteOffset, b.byteLength)) === 0;
|
new Uint8Array(b.buffer, b.byteOffset, b.byteLength)) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isFloatTypedArrayTag(tag) {
|
function isFloatTypedArrayTag(tag) {
|
||||||
@ -186,11 +184,11 @@ function strictDeepEqual(actual, expected) {
|
|||||||
// Skip testing the part below and continue in the callee function.
|
// Skip testing the part below and continue in the callee function.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (util.isDate(actual)) {
|
if (isDate(actual)) {
|
||||||
if (actual.getTime() !== expected.getTime()) {
|
if (actual.getTime() !== expected.getTime()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (util.isRegExp(actual)) {
|
} else if (isRegExp(actual)) {
|
||||||
if (!areSimilarRegExps(actual, expected)) {
|
if (!areSimilarRegExps(actual, expected)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -219,10 +217,10 @@ function looseDeepEqual(actual, expected) {
|
|||||||
if (expected === null || typeof expected !== 'object') {
|
if (expected === null || typeof expected !== 'object') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (util.isDate(actual) && util.isDate(expected)) {
|
if (isDate(actual) && isDate(expected)) {
|
||||||
return actual.getTime() === expected.getTime();
|
return actual.getTime() === expected.getTime();
|
||||||
}
|
}
|
||||||
if (util.isRegExp(actual) && util.isRegExp(expected)) {
|
if (isRegExp(actual) && isRegExp(expected)) {
|
||||||
return areSimilarRegExps(actual, expected);
|
return areSimilarRegExps(actual, expected);
|
||||||
}
|
}
|
||||||
const actualTag = objectToString(actual);
|
const actualTag = objectToString(actual);
|
||||||
|
17
lib/util.js
17
lib/util.js
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
const errors = require('internal/errors');
|
const errors = require('internal/errors');
|
||||||
const { TextDecoder, TextEncoder } = require('internal/encoding');
|
const { TextDecoder, TextEncoder } = require('internal/encoding');
|
||||||
|
const { isBuffer } = require('buffer').Buffer;
|
||||||
|
|
||||||
const { errname } = process.binding('uv');
|
const { errname } = process.binding('uv');
|
||||||
|
|
||||||
@ -1134,6 +1135,7 @@ module.exports = exports = {
|
|||||||
inspect,
|
inspect,
|
||||||
isArray: Array.isArray,
|
isArray: Array.isArray,
|
||||||
isBoolean,
|
isBoolean,
|
||||||
|
isBuffer,
|
||||||
isNull,
|
isNull,
|
||||||
isNullOrUndefined,
|
isNullOrUndefined,
|
||||||
isNumber,
|
isNumber,
|
||||||
@ -1165,18 +1167,3 @@ module.exports = exports = {
|
|||||||
'util.puts is deprecated. Use console.log instead.',
|
'util.puts is deprecated. Use console.log instead.',
|
||||||
'DEP0027')
|
'DEP0027')
|
||||||
};
|
};
|
||||||
|
|
||||||
// Avoid a circular dependency
|
|
||||||
var isBuffer;
|
|
||||||
Object.defineProperty(exports, 'isBuffer', {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: true,
|
|
||||||
get() {
|
|
||||||
if (!isBuffer)
|
|
||||||
isBuffer = require('buffer').Buffer.isBuffer;
|
|
||||||
return isBuffer;
|
|
||||||
},
|
|
||||||
set(val) {
|
|
||||||
isBuffer = val;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user