summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2017-04-05 22:30:25 -0700
committerTimothy Gu <timothygu99@gmail.com>2017-04-08 11:07:00 -0700
commita37273c1e4b93ed048e1d45818fe6c525480b121 (patch)
treea1e86cf5a90921c90a21da4a8fab0b2cafe6b4ac /lib
parentafd5966fa9a874ebb958518633b70b6af4f78b8f (diff)
downloadandroid-node-v8-a37273c1e4b93ed048e1d45818fe6c525480b121.tar.gz
android-node-v8-a37273c1e4b93ed048e1d45818fe6c525480b121.tar.bz2
android-node-v8-a37273c1e4b93ed048e1d45818fe6c525480b121.zip
util: use V8 C++ API for inspecting Promises
PR-URL: https://github.com/nodejs/node/pull/12254 Refs: https://github.com/nodejs/node/issues/11875 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Josh Gavant <josh.gavant@outlook.com>
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);