[Pkg-javascript-commits] [node-leveldown] 303/492: clean up LD_RETURN_CALLBACK_OR_ERROR calls

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 60421fe8009c06235704c4568802a7e39c9c7375
Author: Rod Vagg <rod at vagg.org>
Date:   Mon Apr 8 09:19:13 2013 +1000

    clean up LD_RETURN_CALLBACK_OR_ERROR calls
---
 src/batch.cc    | 4 ++--
 src/database.cc | 5 +++++
 src/iterator.cc | 8 +++++---
 src/leveldown.h | 5 +++--
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/batch.cc b/src/batch.cc
index a1394a7..4762c8f 100644
--- a/src/batch.cc
+++ b/src/batch.cc
@@ -98,7 +98,7 @@ v8::Handle<v8::Value> Batch::Put (const v8::Arguments& args) {
   v8::HandleScope scope;
   Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder());
 
-  v8::Local<v8::Function> callback; // purely for the error macros
+  v8::Handle<v8::Function> callback; // purely for the error macros
 
   LD_CB_ERR_IF_NULL_OR_UNDEFINED(args[0], key)
   LD_CB_ERR_IF_NULL_OR_UNDEFINED(args[1], value)
@@ -126,7 +126,7 @@ v8::Handle<v8::Value> Batch::Del (const v8::Arguments& args) {
   v8::HandleScope scope;
   Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder());
 
-  v8::Local<v8::Function> callback; // purely for the error macros
+  v8::Handle<v8::Function> callback; // purely for the error macros
 
   LD_CB_ERR_IF_NULL_OR_UNDEFINED(args[0], key)
 
diff --git a/src/database.cc b/src/database.cc
index e824ee9..0539610 100644
--- a/src/database.cc
+++ b/src/database.cc
@@ -495,11 +495,16 @@ v8::Handle<v8::Value> Database::Iterator (const v8::Arguments& args) {
   // each iterator gets a unique id for this Database, so we can
   // easily store & lookup on our `iterators` map
   uint32_t id = database->currentIteratorId++;
+  v8::TryCatch try_catch;
   v8::Handle<v8::Object> iterator = Iterator::NewInstance(
       args.This()
     , v8::Number::New(id)
     , optionsObj
   );
+  if (try_catch.HasCaught()) {
+    node::FatalException(try_catch);
+  }
+
   // register our iterator
   database->iterators[id] =
       node::ObjectWrap::Unwrap<leveldown::Iterator>(iterator)->handle_;
diff --git a/src/iterator.cc b/src/iterator.cc
index 424782b..afd98ee 100644
--- a/src/iterator.cc
+++ b/src/iterator.cc
@@ -128,6 +128,7 @@ void checkEndCallback (Iterator* iterator) {
 //void *ctx, void (*callback)(void *ctx, leveldb::Slice key, leveldb::Slice value)
 v8::Handle<v8::Value> Iterator::Next (const v8::Arguments& args) {
   v8::HandleScope scope;
+
   Iterator* iterator = node::ObjectWrap::Unwrap<Iterator>(args.This());
 
   if (args.Length() == 0 || !args[0]->IsFunction()) {
@@ -160,6 +161,7 @@ v8::Handle<v8::Value> Iterator::Next (const v8::Arguments& args) {
 
 v8::Handle<v8::Value> Iterator::End (const v8::Arguments& args) {
   v8::HandleScope scope;
+
   Iterator* iterator = node::ObjectWrap::Unwrap<Iterator>(args.This());
 
   if (args.Length() == 0 || !args[0]->IsFunction()) {
@@ -233,11 +235,11 @@ v8::Handle<v8::Object> Iterator::NewInstance (
 v8::Handle<v8::Value> Iterator::New (const v8::Arguments& args) {
   v8::HandleScope scope;
 
-  //TODO: remove this, it's only here to make LD_STRING_OR_BUFFER_TO_SLICE happy
-  v8::Local<v8::Function> callback;
-
   Database* database = node::ObjectWrap::Unwrap<Database>(args[0]->ToObject());
 
+  //TODO: remove this, it's only here to make LD_STRING_OR_BUFFER_TO_SLICE happy
+  v8::Handle<v8::Function> callback;
+
   v8::Local<v8::Value> startBuffer;
   leveldb::Slice* start = NULL;
   std::string* end = NULL;
diff --git a/src/leveldown.h b/src/leveldown.h
index 43377dd..1ddbf16 100644
--- a/src/leveldown.h
+++ b/src/leveldown.h
@@ -78,7 +78,7 @@
       : default;
 
 #define LD_RETURN_CALLBACK_OR_ERROR(callback, msg) \
-  if (callback->IsFunction()) { \
+  if (!callback.IsEmpty() && callback->IsFunction()) { \
     v8::Local<v8::Value> argv[] = { \
       v8::Local<v8::Value>::New(v8::Exception::Error( \
         v8::String::New(msg)) \
@@ -87,7 +87,8 @@
     LD_RUN_CALLBACK(callback, argv, 1) \
     return v8::Undefined(); \
   } \
-  LD_THROW_RETURN(msg)
+  v8::ThrowException(v8::Exception::Error(v8::String::New(msg))); \
+  return v8::Undefined();
 
 #define LD_RUN_CALLBACK(callback, argv, length) \
   v8::TryCatch try_catch; \

-- 
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