[Pkg-javascript-commits] [node-leveldown] 347/492: track batch() state, no changes post-write()
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:16 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 2c33617acfbe06f034f493cc7c6cc4af433203f1
Author: Rod Vagg <rod at vagg.org>
Date: Sat May 18 20:51:02 2013 +1000
track batch() state, no changes post-write()
---
src/batch.cc | 25 ++++++++++++++++++++++++-
src/batch.h | 1 +
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/batch.cc b/src/batch.cc
index 2b09454..9e15a4e 100644
--- a/src/batch.cc
+++ b/src/batch.cc
@@ -15,6 +15,7 @@ Batch::Batch (leveldown::Database* database, bool sync) : database(database) {
batch = new leveldb::WriteBatch();
references = new std::vector<Reference>;
hasData = false;
+ written = false;
}
Batch::~Batch () {
@@ -91,8 +92,13 @@ v8::Handle<v8::Value> Batch::NewInstance (
v8::Handle<v8::Value> Batch::Put (const v8::Arguments& args) {
v8::HandleScope scope;
+
Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder());
+ if (batch->written) {
+ LD_THROW_RETURN(write() already called on this batch)
+ }
+
v8::Handle<v8::Function> callback; // purely for the error macros
LD_CB_ERR_IF_NULL_OR_UNDEFINED(args[0], key)
@@ -121,8 +127,13 @@ v8::Handle<v8::Value> Batch::Put (const v8::Arguments& args) {
v8::Handle<v8::Value> Batch::Del (const v8::Arguments& args) {
v8::HandleScope scope;
+
Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder());
+ if (batch->written) {
+ LD_THROW_RETURN(write() already called on this batch)
+ }
+
v8::Handle<v8::Function> callback; // purely for the error macros
LD_CB_ERR_IF_NULL_OR_UNDEFINED(args[0], key)
@@ -144,8 +155,13 @@ v8::Handle<v8::Value> Batch::Del (const v8::Arguments& args) {
v8::Handle<v8::Value> Batch::Clear (const v8::Arguments& args) {
v8::HandleScope scope;
+
Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder());
+ if (batch->written) {
+ LD_THROW_RETURN(write() already called on this batch)
+ }
+
batch->batch->Clear();
batch->hasData = false;
@@ -154,12 +170,19 @@ v8::Handle<v8::Value> Batch::Clear (const v8::Arguments& args) {
v8::Handle<v8::Value> Batch::Write (const v8::Arguments& args) {
v8::HandleScope scope;
-
+
Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder());
+
+ if (batch->written) {
+ LD_THROW_RETURN(write() already called on this batch)
+ }
+
if (args.Length() == 0) {
LD_THROW_RETURN(write() requires a callback argument)
}
+ batch->written = true;
+
if (batch->hasData) {
v8::Persistent<v8::Function> callback = v8::Persistent<v8::Function>::New(
LD_NODE_ISOLATE_PRE
diff --git a/src/batch.h b/src/batch.h
index dc07ce4..31f1f04 100644
--- a/src/batch.h
+++ b/src/batch.h
@@ -28,6 +28,7 @@ private:
leveldb::WriteBatch* batch;
std::vector<Reference>* references;
bool hasData; // keep track of whether we're writing data or not
+ bool written;
static v8::Persistent<v8::Function> constructor;
--
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