From c079f6e21044053066a46c0533a6835c094aa706 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 7 Aug 2013 14:45:37 +0200 Subject: [PATCH] src: add IsEmpty() check to HasInstance() The check has virtually zero overhead and it simplifies the call sites because they were calling IsEmpty() anwyay. --- src/node_internals.h | 1 + src/node_wrap.h | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/node_internals.h b/src/node_internals.h index ced62e08b6..d9db29c1b7 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -318,6 +318,7 @@ v8::Handle MakeCallback( inline bool HasInstance( const v8::Persistent& function_template, v8::Handle value) { + if (function_template.IsEmpty()) return false; v8::Local function_template_handle = PersistentToLocal(node_isolate, function_template); return function_template_handle->HasInstance(value); diff --git a/src/node_wrap.h b/src/node_wrap.h index 7c3f63fb20..c5fe0fccd7 100644 --- a/src/node_wrap.h +++ b/src/node_wrap.h @@ -38,16 +38,13 @@ extern v8::Persistent 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 \ } \