Skip to content

util: fix for inspecting promises #3197

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

Merged
merged 1 commit into from
Oct 6, 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
7 changes: 2 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const internalUtil = require('internal/util');
const binding = process.binding('util');

var Debug;
var ObjectIsPromise;

const formatRegExp = /%[sdj%]/g;
exports.format = function(f) {
Expand Down Expand Up @@ -189,16 +188,14 @@ function getConstructorOf(obj) {
function ensureDebugIsInitialized() {
if (Debug === undefined) {
const runInDebugContext = require('vm').runInDebugContext;
const result = runInDebugContext('[Debug, ObjectIsPromise]');
Debug = result[0];
ObjectIsPromise = result[1];
Debug = runInDebugContext('Debug');
}
}


function inspectPromise(p) {
ensureDebugIsInitialized();
if (!ObjectIsPromise(p))
if (!binding.isPromise(p))
return null;
const mirror = Debug.MakeMirror(p, true);
return {status: mirror.status(), value: mirror.promiseValue().value_};
Expand Down
5 changes: 5 additions & 0 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ static void IsSetIterator(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(args[0]->IsSetIterator());
}

static void IsPromise(const FunctionCallbackInfo<Value>& args) {
CHECK_EQ(1, args.Length());
args.GetReturnValue().Set(args[0]->IsPromise());
}

void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);
env->SetMethod(target, "isMapIterator", IsMapIterator);
env->SetMethod(target, "isSetIterator", IsSetIterator);
env->SetMethod(target, "isPromise", IsPromise);
}

} // namespace util
Expand Down