Browse Source

src: add IsEmpty() check to HasInstance()

The check has virtually zero overhead and it simplifies the call sites
because they were calling IsEmpty() anwyay.
v0.11.6-release
Ben Noordhuis 12 years ago
parent
commit
c079f6e210
  1. 1
      src/node_internals.h
  2. 9
      src/node_wrap.h

1
src/node_internals.h

@ -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);

9
src/node_wrap.h

@ -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 \
} \

Loading…
Cancel
Save