Skip to content

Commit e0fffca

Browse files
evanlucasjasnell
authored andcommitted
util: fix for inspecting promises
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]>
1 parent 18a8b2e commit e0fffca

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/util.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const internalUtil = require('internal/util');
66
const binding = process.binding('util');
77

88
var Debug;
9-
var ObjectIsPromise;
109

1110
const formatRegExp = /%[sdj%]/g;
1211
exports.format = function(f) {
@@ -189,16 +188,14 @@ function getConstructorOf(obj) {
189188
function ensureDebugIsInitialized() {
190189
if (Debug === undefined) {
191190
const runInDebugContext = require('vm').runInDebugContext;
192-
const result = runInDebugContext('[Debug, ObjectIsPromise]');
193-
Debug = result[0];
194-
ObjectIsPromise = result[1];
191+
Debug = runInDebugContext('Debug');
195192
}
196193
}
197194

198195

199196
function inspectPromise(p) {
200197
ensureDebugIsInitialized();
201-
if (!ObjectIsPromise(p))
198+
if (!binding.isPromise(p))
202199
return null;
203200
const mirror = Debug.MakeMirror(p, true);
204201
return {status: mirror.status(), value: mirror.promiseValue().value_};

src/node_util.cc

+5
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ static void IsSetIterator(const FunctionCallbackInfo<Value>& args) {
2323
args.GetReturnValue().Set(args[0]->IsSetIterator());
2424
}
2525

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

2731
void Initialize(Local<Object> target,
2832
Local<Value> unused,
2933
Local<Context> context) {
3034
Environment* env = Environment::GetCurrent(context);
3135
env->SetMethod(target, "isMapIterator", IsMapIterator);
3236
env->SetMethod(target, "isSetIterator", IsSetIterator);
37+
env->SetMethod(target, "isPromise", IsPromise);
3338
}
3439

3540
} // namespace util

0 commit comments

Comments
 (0)