Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up promise introspection #3130

Merged
merged 2 commits into from
Sep 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions deps/v8/src/mirror-debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ function ToggleMirrorCache(value) {
}


// Wrapper to check whether an object is a Promise. The call may not work
// if promises are not enabled.
// TODO(yangguo): remove try-catch once promises are enabled by default.
function ObjectIsPromise(value) {
try {
return IS_SPEC_OBJECT(value) &&
!IS_UNDEFINED(%DebugGetProperty(value, builtins.$promiseStatus));
} catch (e) {
return false;
}
return IS_SPEC_OBJECT(value) &&
!IS_UNDEFINED(%DebugGetProperty(value, builtins.$promiseStatus));
}


Expand Down
18 changes: 15 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
const uv = process.binding('uv');
const Buffer = require('buffer').Buffer;
const internalUtil = require('internal/util');

var Debug;
var ObjectIsPromise;

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


function ensureDebugIsInitialized() {
if (Debug === undefined) {
const runInDebugContext = require('vm').runInDebugContext;
const result = runInDebugContext('[Debug, ObjectIsPromise]');
Debug = result[0];
ObjectIsPromise = result[1];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prepare the ground for the use of MakeMirror in #3119, may I suggest to move this to a separate function ? setupDebugObjects() for example.

}


function inspectPromise(p) {
Debug = Debug || require('vm').runInDebugContext('Debug');
var mirror = Debug.MakeMirror(p, true);
if (!mirror.isPromise())
ensureDebugIsInitialized();
if (!ObjectIsPromise(p))
return null;
const mirror = Debug.MakeMirror(p, true);
return {status: mirror.status(), value: mirror.promiseValue().value_};
}

Expand Down