summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/util.js62
1 files changed, 24 insertions, 38 deletions
diff --git a/lib/util.js b/lib/util.js
index a0e8bb3c1d..12280e412a 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -302,16 +302,6 @@ function ensureDebugIsInitialized() {
}
-function inspectPromise(p) {
- // Only create a mirror if the object is a Promise.
- if (!binding.isPromise(p))
- return null;
- ensureDebugIsInitialized();
- const mirror = Debug.MakeMirror(p, true);
- return {status: mirror.status(), value: mirror.promiseValue().value_};
-}
-
-
function formatValue(ctx, value, recurseTimes) {
if (ctx.showProxy &&
((typeof value === 'object' && value !== null) ||
@@ -527,30 +517,25 @@ function formatValue(ctx, value, recurseTimes) {
'byteOffset',
'buffer');
}
+ } else if (binding.isPromise(value)) {
+ braces = ['{', '}'];
+ formatter = formatPromise;
+ } else if (binding.isMapIterator(value)) {
+ constructor = { name: 'MapIterator' };
+ braces = ['{', '}'];
+ empty = false;
+ formatter = formatCollectionIterator;
+ } else if (binding.isSetIterator(value)) {
+ constructor = { name: 'SetIterator' };
+ braces = ['{', '}'];
+ empty = false;
+ formatter = formatCollectionIterator;
} else {
- var promiseInternals = inspectPromise(value);
- if (promiseInternals) {
- braces = ['{', '}'];
- formatter = formatPromise;
- } else {
- if (binding.isMapIterator(value)) {
- constructor = { name: 'MapIterator' };
- braces = ['{', '}'];
- empty = false;
- formatter = formatCollectionIterator;
- } else if (binding.isSetIterator(value)) {
- constructor = { name: 'SetIterator' };
- braces = ['{', '}'];
- empty = false;
- formatter = formatCollectionIterator;
- } else {
- // Unset the constructor to prevent "Object {...}" for ordinary objects.
- if (constructor && constructor.name === 'Object')
- constructor = null;
- braces = ['{', '}'];
- empty = true; // No other data than keys.
- }
- }
+ // Unset the constructor to prevent "Object {...}" for ordinary objects.
+ if (constructor && constructor.name === 'Object')
+ constructor = null;
+ braces = ['{', '}'];
+ empty = true; // No other data than keys.
}
empty = empty === true && keys.length === 0;
@@ -779,14 +764,15 @@ function formatCollectionIterator(ctx, value, recurseTimes, visibleKeys, keys) {
}
function formatPromise(ctx, value, recurseTimes, visibleKeys, keys) {
- var output = [];
- var internals = inspectPromise(value);
- if (internals.status === 'pending') {
+ const output = [];
+ const [state, result] = binding.getPromiseDetails(value);
+
+ if (state === binding.kPending) {
output.push('<pending>');
} else {
var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
- var str = formatValue(ctx, internals.value, nextRecurseTimes);
- if (internals.status === 'rejected') {
+ var str = formatValue(ctx, result, nextRecurseTimes);
+ if (state === binding.kRejected) {
output.push('<rejected> ' + str);
} else {
output.push(str);