src: add IsEmpty() check to HasInstance()
authorBen Noordhuis <info@bnoordhuis.nl>
Wed, 7 Aug 2013 12:45:37 +0000 (14:45 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Wed, 7 Aug 2013 12:46:55 +0000 (14:46 +0200)
The check has virtually zero overhead and it simplifies the call sites
because they were calling IsEmpty() anwyay.

src/node_internals.h
src/node_wrap.h

index ced62e0..d9db29c 100644 (file)
@@ -318,6 +318,7 @@ v8::Handle<v8::Value> MakeCallback(
 inline bool HasInstance(
     const v8::Persistent<v8::FunctionTemplate>& function_template,
     v8::Handle<v8::Value> value) {
+  if (function_template.IsEmpty()) return false;
   v8::Local<v8::FunctionTemplate> function_template_handle =
       PersistentToLocal(node_isolate, function_template);
   return function_template_handle->HasInstance(value);
index 7c3f63f..c5fe0fc 100644 (file)
@@ -38,16 +38,13 @@ extern v8::Persistent<v8::FunctionTemplate> tcpConstructorTmpl;
 
 #define WITH_GENERIC_STREAM(obj, BODY)                    \
     do {                                                  \
-      if (!tcpConstructorTmpl.IsEmpty() &&                \
-          HasInstance(tcpConstructorTmpl, obj)) {         \
+      if (HasInstance(tcpConstructorTmpl, obj)) {         \
         TCPWrap* wrap = TCPWrap::Unwrap(obj);             \
         BODY                                              \
-      } else if (!ttyConstructorTmpl.IsEmpty() &&         \
-                 HasInstance(ttyConstructorTmpl, obj)) {  \
+      } else if (HasInstance(ttyConstructorTmpl, obj)) {  \
         TTYWrap* wrap = TTYWrap::Unwrap(obj);             \
         BODY                                              \
-      } else if (!pipeConstructorTmpl.IsEmpty() &&        \
-                 HasInstance(pipeConstructorTmpl, obj)) { \
+      } else if (HasInstance(pipeConstructorTmpl, obj)) { \
         PipeWrap* wrap = PipeWrap::Unwrap(obj);           \
         BODY                                              \
       }                                                   \