Browse Source

util: don't init Debug if it's not needed yet

Because any call to util.inspect() with an object results in
inspectPromise() being called, Debug was being initialized even when
it's not needed. Instead, the initialization is placed after the
isPromise check.

PR-URL: https://github.com/nodejs/node/pull/8452
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
v4.x
Bryan English 8 years ago
committed by Myles Borins
parent
commit
2c84601062
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 2
      lib/util.js

2
lib/util.js

@ -231,10 +231,10 @@ function ensureDebugIsInitialized() {
function inspectPromise(p) { function inspectPromise(p) {
ensureDebugIsInitialized();
// Only create a mirror if the object is a Promise. // Only create a mirror if the object is a Promise.
if (!binding.isPromise(p)) if (!binding.isPromise(p))
return null; return null;
ensureDebugIsInitialized();
const mirror = Debug.MakeMirror(p, true); const mirror = Debug.MakeMirror(p, true);
return {status: mirror.status(), value: mirror.promiseValue().value_}; return {status: mirror.status(), value: mirror.promiseValue().value_};
} }

Loading…
Cancel
Save