lib: reduce usage of require('util') · nodejs/node@5f3b850 (original) (raw)

`@@ -30,6 +30,14 @@ function lazyInternalUtil() {

`

30

30

`return internalUtil;

`

31

31

`}

`

32

32

``

``

33

`+

let internalUtilInspect = null;

`

``

34

`+

function lazyInternalUtilInspect() {

`

``

35

`+

if (!internalUtilInspect) {

`

``

36

`+

internalUtilInspect = require('internal/util/inspect');

`

``

37

`+

}

`

``

38

`+

return internalUtilInspect;

`

``

39

`+

}

`

``

40

+

33

41

`let buffer;

`

34

42

`function lazyBuffer() {

`

35

43

`if (buffer === undefined)

`

`@@ -220,7 +228,6 @@ function E(sym, val, def, ...otherClasses) {

`

220

228

`function getMessage(key, args, self) {

`

221

229

`const msg = messages.get(key);

`

222

230

``

223

``

`-

if (util === undefined) util = require('util');

`

224

231

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

`

225

232

``

226

233

`if (typeof msg === 'function') {

`

`@@ -242,7 +249,7 @@ function getMessage(key, args, self) {

`

242

249

`return msg;

`

243

250

``

244

251

`args.unshift(msg);

`

245

``

`-

return util.format.apply(null, args);

`

``

252

`+

return lazyInternalUtilInspect().format.apply(null, args);

`

246

253

`}

`

247

254

``

248

255

`let uvBinding;

`

`@@ -773,7 +780,7 @@ E('ERR_INVALID_ARG_TYPE',

`

773

780

`return msg;

`

774

781

`}, TypeError);

`

775

782

`E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {

`

776

``

`-

let inspected = util.inspect(value);

`

``

783

`+

let inspected = lazyInternalUtilInspect().inspect(value);

`

777

784

`if (inspected.length > 128) {

`

778

785

`` inspected = ${inspected.slice(0, 128)}...;

``

779

786

`}

`