[Pkg-javascript-commits] [node-leveldown] 307/492: macro aesthetics (80-char \'s)

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:11 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.

commit 4ae229517de0bfb08b5510f1ab021505352637f8
Author: Rod Vagg <rod at vagg.org>
Date:   Mon Apr 8 09:47:18 2013 +1000

    macro aesthetics (80-char \'s)
---
 src/leveldown.h | 188 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 96 insertions(+), 92 deletions(-)

diff --git a/src/leveldown.h b/src/leveldown.h
index 85f99fe..c105227 100644
--- a/src/leveldown.h
+++ b/src/leveldown.h
@@ -5,6 +5,8 @@
 #ifndef LD_LEVELDOWN_H
 #define LD_LEVELDOWN_H
 
+#include <v8.h>
+
 // node_isolate stuff introduced with V8 upgrade, see https://github.com/joyent/node/pull/5077
 #if NODE_MODULE_VERSION > 0x000B
 #  define LD_NODE_ISOLATE node::node_isolate
@@ -16,94 +18,96 @@
 #  define LD_NODE_ISOLATE_POST
 #endif
 
-#define LD_SYMBOL(var, key) \
-  static const v8::Persistent<v8::String> var = \
-    v8::Persistent<v8::String>::New(LD_NODE_ISOLATE_PRE v8::String::NewSymbol(#key));
+#define LD_SYMBOL(var, key)                                                    \
+  static const v8::Persistent<v8::String> var =                                \
+    v8::Persistent<v8::String>::New(                                           \
+      LD_NODE_ISOLATE_PRE v8::String::NewSymbol(#key)                          \
+    );
 
-#define LD_V8_METHOD(name) \
+#define LD_V8_METHOD(name)                                                     \
   static v8::Handle<v8::Value> name (const v8::Arguments& args);
 
-#define LD_CB_ERR_IF_NULL_OR_UNDEFINED(thing, name) \
-  if (thing->IsNull() || thing->IsUndefined()) { \
+#define LD_CB_ERR_IF_NULL_OR_UNDEFINED(thing, name)                            \
+  if (thing->IsNull() || thing->IsUndefined()) {                               \
     LD_RETURN_CALLBACK_OR_ERROR(callback, #name " cannot be `null` or `undefined`") \
   }
 
-#define LD_FROM_V8_STRING(to, from) \
-  size_t to ## Sz_; \
-  char* to; \
-  v8::Local<v8::String> to ## Str = from->ToString(); \
-  to ## Sz_ = to ## Str->Utf8Length(); \
-  to = new char[to ## Sz_ + 1]; \
+#define LD_FROM_V8_STRING(to, from)                                            \
+  size_t to ## Sz_;                                                            \
+  char* to;                                                                    \
+  v8::Local<v8::String> to ## Str = from->ToString();                          \
+  to ## Sz_ = to ## Str->Utf8Length();                                         \
+  to = new char[to ## Sz_ + 1];                                                \
   to ## Str->WriteUtf8(to, -1, NULL, v8::String::NO_OPTIONS);
 
-#define LD_STRING_OR_BUFFER_TO_SLICE(to, from, name) \
-  size_t to ## Sz_; \
-  char* to ## Ch_; \
-  if (node::Buffer::HasInstance(from->ToObject())) { \
-    to ## Sz_ = node::Buffer::Length(from->ToObject()); \
-    if (to ## Sz_ == 0) { \
+#define LD_STRING_OR_BUFFER_TO_SLICE(to, from, name)                           \
+  size_t to ## Sz_;                                                            \
+  char* to ## Ch_;                                                             \
+  if (node::Buffer::HasInstance(from->ToObject())) {                           \
+    to ## Sz_ = node::Buffer::Length(from->ToObject());                        \
+    if (to ## Sz_ == 0) {                                                      \
       LD_RETURN_CALLBACK_OR_ERROR(callback, #name " cannot be an empty Buffer") \
-    } \
-    to ## Ch_ = node::Buffer::Data(from->ToObject()); \
-  } else { \
-    v8::Local<v8::String> to ## Str = from->ToString(); \
-    to ## Sz_ = to ## Str->Utf8Length(); \
-    if (to ## Sz_ == 0) { \
+    }                                                                          \
+    to ## Ch_ = node::Buffer::Data(from->ToObject());                          \
+  } else {                                                                     \
+    v8::Local<v8::String> to ## Str = from->ToString();                        \
+    to ## Sz_ = to ## Str->Utf8Length();                                       \
+    if (to ## Sz_ == 0) {                                                      \
       LD_RETURN_CALLBACK_OR_ERROR(callback, #name " cannot be an empty String") \
-    } \
-    to ## Ch_ = new char[to ## Sz_]; \
-    to ## Str->WriteUtf8( \
-        to ## Ch_ \
-      , -1 \
-      , NULL, v8::String::NO_NULL_TERMINATION \
-    ); \
-  } \
+    }                                                                          \
+    to ## Ch_ = new char[to ## Sz_];                                           \
+    to ## Str->WriteUtf8(                                                      \
+        to ## Ch_                                                              \
+      , -1                                                                     \
+      , NULL, v8::String::NO_NULL_TERMINATION                                  \
+    );                                                                         \
+  }                                                                            \
   leveldb::Slice to(to ## Ch_, to ## Sz_);
 
-#define LD_STRING_OR_BUFFER_LENGTH(obj) \
-  node::Buffer::HasInstance(obj->ToObject()) \
-    ? node::Buffer::Length(obj->ToObject()) \
+#define LD_STRING_OR_BUFFER_LENGTH(obj)                                        \
+  node::Buffer::HasInstance(obj->ToObject())                                   \
+    ? node::Buffer::Length(obj->ToObject())                                    \
     : obj->ToString()->Utf8Length()
 
-#define LD_BOOLEAN_OPTION_VALUE(optionsObj, opt) \
-  bool opt = !optionsObj.IsEmpty() \
-    && optionsObj->Has(option_ ## opt) \
+#define LD_BOOLEAN_OPTION_VALUE(optionsObj, opt)                               \
+  bool opt = !optionsObj.IsEmpty()                                             \
+    && optionsObj->Has(option_ ## opt)                                         \
     && optionsObj->Get(option_ ## opt)->BooleanValue();
 
-#define LD_BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, opt) \
-  bool opt = optionsObj.IsEmpty() \
-    || !optionsObj->Has(option_ ## opt) \
+#define LD_BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, opt)                       \
+  bool opt = optionsObj.IsEmpty()                                              \
+    || !optionsObj->Has(option_ ## opt)                                        \
     || optionsObj->Get(option_ ## opt)->BooleanValue();
 
-#define LD_UINT32_OPTION_VALUE(optionsObj, opt, default) \
-  uint32_t opt = !optionsObj.IsEmpty() \
-    && optionsObj->Has(option_ ## opt) \
-    && optionsObj->Get(option_ ## opt)->IsUint32() \
-      ? optionsObj->Get(option_ ## opt)->Uint32Value() \
+#define LD_UINT32_OPTION_VALUE(optionsObj, opt, default)                       \
+  uint32_t opt = !optionsObj.IsEmpty()                                         \
+    && optionsObj->Has(option_ ## opt)                                         \
+    && optionsObj->Get(option_ ## opt)->IsUint32()                             \
+      ? optionsObj->Get(option_ ## opt)->Uint32Value()                         \
       : default;
 
-#define LD_RETURN_CALLBACK_OR_ERROR(callback, msg) \
-  if (!callback.IsEmpty() && callback->IsFunction()) { \
-    v8::Local<v8::Value> argv[] = { \
-      v8::Local<v8::Value>::New(v8::Exception::Error( \
-        v8::String::New(msg)) \
-      ) \
-    }; \
-    LD_RUN_CALLBACK(callback, argv, 1) \
-    return v8::Undefined(); \
-  } \
-  v8::ThrowException(v8::Exception::Error(v8::String::New(msg))); \
+#define LD_RETURN_CALLBACK_OR_ERROR(callback, msg)                             \
+  if (!callback.IsEmpty() && callback->IsFunction()) {                         \
+    v8::Local<v8::Value> argv[] = {                                            \
+      v8::Local<v8::Value>::New(v8::Exception::Error(                          \
+        v8::String::New(msg))                                                  \
+      )                                                                        \
+    };                                                                         \
+    LD_RUN_CALLBACK(callback, argv, 1)                                         \
+    return v8::Undefined();                                                    \
+  }                                                                            \
+  v8::ThrowException(v8::Exception::Error(v8::String::New(msg)));              \
   return v8::Undefined();
 
-#define LD_RUN_CALLBACK(callback, argv, length) \
-  v8::TryCatch try_catch; \
-  callback->Call(v8::Context::GetCurrent()->Global(), length, argv); \
-  if (try_catch.HasCaught()) { \
-    node::FatalException(try_catch); \
+#define LD_RUN_CALLBACK(callback, argv, length)                                \
+  v8::TryCatch try_catch;                                                      \
+  callback->Call(v8::Context::GetCurrent()->Global(), length, argv);           \
+  if (try_catch.HasCaught()) {                                                 \
+    node::FatalException(try_catch);                                           \
   }
 
-#define LD_THROW_RETURN(...) \
-  v8::ThrowException(v8::Exception::Error(v8::String::New(#__VA_ARGS__))); \
+#define LD_THROW_RETURN(...)                                                   \
+  v8::ThrowException(v8::Exception::Error(v8::String::New(#__VA_ARGS__)));     \
   return v8::Undefined();
 
 /* LD_METHOD_SETUP_COMMON setup the following objects:
@@ -112,34 +116,34 @@
  *  - v8::Persistent<v8::Function> callback (won't be empty)
  * Will LD_THROW_RETURN if there isn't a callback in arg 0 or 1
  */
-#define LD_METHOD_SETUP_COMMON(name, optionPos, callbackPos) \
-  if (args.Length() == 0) { \
-    LD_THROW_RETURN(name() requires a callback argument) \
-  } \
-  leveldown::Database* database = \
-    node::ObjectWrap::Unwrap<leveldown::Database>(args.This()); \
-  v8::Local<v8::Object> optionsObj; \
-  v8::Persistent<v8::Function> callback; \
-  if (optionPos == -1 && args[callbackPos]->IsFunction()) { \
-    callback = v8::Persistent<v8::Function>::New( \
-      LD_NODE_ISOLATE_PRE \
-      v8::Local<v8::Function>::Cast(args[callbackPos]) \
-    ); \
-  } else if (optionPos != -1 && args[callbackPos - 1]->IsFunction()) { \
-    callback = v8::Persistent<v8::Function>::New( \
-      LD_NODE_ISOLATE_PRE \
-      v8::Local<v8::Function>::Cast(args[callbackPos - 1]) \
-    ); \
-  } else if (optionPos != -1 \
-        && args[optionPos]->IsObject() \
-        && args[callbackPos]->IsFunction()) { \
-    optionsObj = v8::Local<v8::Object>::Cast(args[optionPos]); \
-    callback = v8::Persistent<v8::Function>::New( \
-      LD_NODE_ISOLATE_PRE \
-      v8::Local<v8::Function>::Cast(args[callbackPos]) \
-    ); \
-  } else { \
-    LD_THROW_RETURN(name() requires a callback argument) \
+#define LD_METHOD_SETUP_COMMON(name, optionPos, callbackPos)                   \
+  if (args.Length() == 0) {                                                    \
+    LD_THROW_RETURN(name() requires a callback argument)                       \
+  }                                                                            \
+  leveldown::Database* database =                                              \
+    node::ObjectWrap::Unwrap<leveldown::Database>(args.This());                \
+  v8::Local<v8::Object> optionsObj;                                            \
+  v8::Persistent<v8::Function> callback;                                       \
+  if (optionPos == -1 && args[callbackPos]->IsFunction()) {                    \
+    callback = v8::Persistent<v8::Function>::New(                              \
+      LD_NODE_ISOLATE_PRE                                                      \
+      v8::Local<v8::Function>::Cast(args[callbackPos])                         \
+    );                                                                         \
+  } else if (optionPos != -1 && args[callbackPos - 1]->IsFunction()) {         \
+    callback = v8::Persistent<v8::Function>::New(                              \
+      LD_NODE_ISOLATE_PRE                                                      \
+      v8::Local<v8::Function>::Cast(args[callbackPos - 1])                     \
+    );                                                                         \
+  } else if (optionPos != -1                                                   \
+        && args[optionPos]->IsObject()                                         \
+        && args[callbackPos]->IsFunction()) {                                  \
+    optionsObj = v8::Local<v8::Object>::Cast(args[optionPos]);                 \
+    callback = v8::Persistent<v8::Function>::New(                              \
+      LD_NODE_ISOLATE_PRE                                                      \
+      v8::Local<v8::Function>::Cast(args[callbackPos])                         \
+    );                                                                         \
+  } else {                                                                     \
+    LD_THROW_RETURN(name() requires a callback argument)                       \
   }
 
 #define LD_METHOD_SETUP_COMMON_ONEARG(name) LD_METHOD_SETUP_COMMON(name, -1, 0)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git



More information about the Pkg-javascript-commits mailing list