util: fix for inspecting promises
authorEvan Lucas <evanlucas@me.com>
Tue, 6 Oct 2015 01:44:09 +0000 (20:44 -0500)
committerJames M Snell <jasnell@gmail.com>
Thu, 8 Oct 2015 03:39:16 +0000 (20:39 -0700)
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: https://github.com/nodejs/node/pull/3221
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
lib/util.js
src/node_util.cc

index 41c5b44..399a4ee 100644 (file)
@@ -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) {
@@ -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_};
index cc86478..19c3e32 100644 (file)
@@ -23,6 +23,10 @@ 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,
@@ -30,6 +34,7 @@ void Initialize(Local<Object> target,
   Environment* env = Environment::GetCurrent(context);
   env->SetMethod(target, "isMapIterator", IsMapIterator);
   env->SetMethod(target, "isSetIterator", IsSetIterator);
+  env->SetMethod(target, "isPromise", IsPromise);
 }
 
 }  // namespace util