Skip to content

Commit

Permalink
util: fix for inspecting promises
Browse files Browse the repository at this point in the history
The upgrade to v8 4.6 removes ObjectIsPromise. This change utilizes
v8::Value::IsPromise to verify that the argument is indeed a promise.

PR-URL: #3221
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
evanlucas authored and jasnell committed Oct 8, 2015
1 parent 18a8b2e commit e0fffca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit e0fffca

Please sign in to comment.