Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d8ab4e1

Browse filesBrowse files
bnoordhuisrvagg
authored andcommitted
util: optimize promise introspection
Use V8's builtin ObjectIsPromise() to check that the value is a promise before creating the promise mirror. Reduces garbage collector strain in the (common) non-promise case, which is beneficial when inspecting deep object graphs. PR-URL: #3130 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent a0b35bf commit d8ab4e1
Copy full SHA for d8ab4e1

File tree

Expand file treeCollapse file tree

1 file changed

+15
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-3
lines changed
Open diff view settings
Collapse file

‎lib/util.js‎

Copy file name to clipboardExpand all lines: lib/util.js
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
const uv = process.binding('uv');
44
const Buffer = require('buffer').Buffer;
55
const internalUtil = require('internal/util');
6+
67
var Debug;
8+
var ObjectIsPromise;
79

810
const formatRegExp = /%[sdj%]/g;
911
exports.format = function(f) {
@@ -183,11 +185,21 @@ function getConstructorOf(obj) {
183185
}
184186

185187

188+
function ensureDebugIsInitialized() {
189+
if (Debug === undefined) {
190+
const runInDebugContext = require('vm').runInDebugContext;
191+
const result = runInDebugContext('[Debug, ObjectIsPromise]');
192+
Debug = result[0];
193+
ObjectIsPromise = result[1];
194+
}
195+
}
196+
197+
186198
function inspectPromise(p) {
187-
Debug = Debug || require('vm').runInDebugContext('Debug');
188-
var mirror = Debug.MakeMirror(p, true);
189-
if (!mirror.isPromise())
199+
ensureDebugIsInitialized();
200+
if (!ObjectIsPromise(p))
190201
return null;
202+
const mirror = Debug.MakeMirror(p, true);
191203
return {status: mirror.status(), value: mirror.promiseValue().value_};
192204
}
193205

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.