[Pkg-javascript-commits] [node-leveldown] 55/492: falsey start/end on readstream kill proc, fixes #8

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:44 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 5dcbc5ba16ec9bdfb65c6c7f4bf370f9e0f32480
Author: Rod Vagg <rod at vagg.org>
Date:   Sat Oct 27 08:52:51 2012 +1100

    falsey start/end on readstream kill proc, fixes #8
---
 lib/read-stream.js       |  4 ++--
 src/database.cc          | 31 +++++++++++++++++++++++++++++++
 src/iterator.cc          |  4 ++--
 test/read-stream-test.js | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/lib/read-stream.js b/lib/read-stream.js
index c45a84d..d1309f5 100644
--- a/lib/read-stream.js
+++ b/lib/read-stream.js
@@ -34,9 +34,9 @@ function ReadStream (options, db, iteratorFactory) {
   this.writable = false
 
   this._options = extend(extend({}, defaultOptions), options)
-  if (this._options.start)
+  if (typeof this._options.start !== 'undefined')
     this._options.start = toBuffer(this._options.start)
-  if (this._options.end)
+  if (typeof this._options.end !== 'undefined')
     this._options.end = toBuffer(this._options.end)
 
   this._makeData = this._options.keys && this._options.values
diff --git a/src/database.cc b/src/database.cc
index afde696..90cad1e 100644
--- a/src/database.cc
+++ b/src/database.cc
@@ -151,6 +151,14 @@ Handle<Value> Database::Put (const Arguments& args) {
     return Undefined();
   }
 
+  if (!Buffer::HasInstance(args[0])) {
+    Local<Value> argv[] = {
+      Local<Value>::New(Exception::Error(String::New("Key must be an instance of Buffer")))
+    };
+    RunCallback(callback, argv, 1);
+    return Undefined();
+  }
+
   if (args[1]->IsNull() || args[1]->IsUndefined()) {
     Local<Value> argv[] = {
       Local<Value>::New(Exception::Error(String::New("Value cannot be `null` or `undefined`")))
@@ -159,6 +167,14 @@ Handle<Value> Database::Put (const Arguments& args) {
     return Undefined();
   }
 
+  if (!Buffer::HasInstance(args[1])) {
+    Local<Value> argv[] = {
+      Local<Value>::New(Exception::Error(String::New("Value must be an instance of Buffer")))
+    };
+    RunCallback(callback, argv, 1);
+    return Undefined();
+  }
+
   Persistent<Object> keyBuffer = Persistent<Object>::New(args[0]->ToObject());
   Slice key(Buffer::Data(keyBuffer), Buffer::Length(keyBuffer));
   Persistent<Object> valueBuffer = Persistent<Object>::New(args[1]->ToObject());
@@ -194,6 +210,13 @@ Handle<Value> Database::Get (const Arguments& args) {
     return Undefined();
   }
 
+  if (!Buffer::HasInstance(args[0])) {
+    Local<Value> argv[] = {
+      Local<Value>::New(Exception::Error(String::New("Key must be an instance of Buffer")))
+    };
+    RunCallback(callback, argv, 1);
+    return Undefined();
+  }
 
   Persistent<Object> keyBuffer = Persistent<Object>::New(args[0]->ToObject());
   Slice key(Buffer::Data(keyBuffer), Buffer::Length(keyBuffer));
@@ -224,6 +247,14 @@ Handle<Value> Database::Delete (const Arguments& args) {
     return Undefined();
   }
 
+  if (!Buffer::HasInstance(args[0])) {
+    Local<Value> argv[] = {
+      Local<Value>::New(Exception::Error(String::New("Key must be an instance of Buffer")))
+    };
+    RunCallback(callback, argv, 1);
+    return Undefined();
+  }
+
   Persistent<Object> keyBuffer = Persistent<Object>::New(args[0]->ToObject());
   Slice key(Buffer::Data(keyBuffer), Buffer::Length(keyBuffer));
   Local<Object> optionsObj = Local<Object>::Cast(args[1]);
diff --git a/src/iterator.cc b/src/iterator.cc
index 0dcafd6..9e85314 100644
--- a/src/iterator.cc
+++ b/src/iterator.cc
@@ -125,12 +125,12 @@ Handle<Value> levelup::Iterator::New (const Arguments& args) {
 
   Database* database = ObjectWrap::Unwrap<Database>(args[0]->ToObject());
   Slice* start = NULL;
-  if (args[1]->ToObject()->Has(option_start)) {
+  if (args[1]->ToObject()->Has(option_start) && Buffer::HasInstance(args[1]->ToObject()->Get(option_start))) {
     Local<Object> startBuffer = Local<Object>::New(args[1]->ToObject()->Get(option_start)->ToObject());
     start = new Slice(Buffer::Data(startBuffer), Buffer::Length(startBuffer));
   }
   string* end = NULL;
-  if (args[1]->ToObject()->Has(option_end)) {
+  if (args[1]->ToObject()->Has(option_end) && Buffer::HasInstance(args[1]->ToObject()->Get(option_end))) {
     Local<Object> endBuffer = Local<Object>::New(args[1]->ToObject()->Get(option_end)->ToObject());
     end = new string(Buffer::Data(endBuffer), Buffer::Length(endBuffer));
   }
diff --git a/test/read-stream-test.js b/test/read-stream-test.js
index 5c05817..250770e 100644
--- a/test/read-stream-test.js
+++ b/test/read-stream-test.js
@@ -455,4 +455,42 @@ buster.testCase('ReadStream', {
         }.bind(this))
       }.bind(this))
     }
+
+  , 'test ReadStream, start=0': function (done) {
+      this.openTestDatabase(function (db) {
+        // execute
+        db.batch(this.sourceData.slice(), function (err) {
+          refute(err)
+
+          var rs = db.readStream({ start: 0 })
+          assert.isFalse(rs.writable)
+          assert.isTrue(rs.readable)
+          rs.on('ready', this.readySpy)
+          rs.on('data' , this.dataSpy)
+          rs.on('end'  , this.endSpy)
+          rs.on('close', this.verify.bind(this, rs, done))
+        }.bind(this))
+      }.bind(this))
+    }
+
+    // we don't expect any data to come out of here because the keys start at '00' not 0
+    // we just want to ensure that we don't kill the process
+  , 'test ReadStream, end=0': function (done) {
+      this.openTestDatabase(function (db) {
+        // execute
+        db.batch(this.sourceData.slice(), function (err) {
+          refute(err)
+
+          var rs = db.readStream({ end: 0 })
+          assert.isFalse(rs.writable)
+          assert.isTrue(rs.readable)
+          rs.on('ready', this.readySpy)
+          rs.on('data' , this.dataSpy)
+          rs.on('end'  , this.endSpy)
+          rs.on('close', this.verify.bind(this, rs, done))
+
+          this.sourceData = [ ]
+        }.bind(this))
+      }.bind(this))
+    }
 })
\ No newline at end of file

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