[Pkg-javascript-commits] [node-leveldown] 209/492: Merge remote-tracking branch 'levelup/master' into 0.1-wip

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:00 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 22414804000cfb7d4a3bbb6ebd78c96b55d1e0ab
Merge: ff4005d 4ab1126
Author: Rod Vagg <rod at vagg.org>
Date:   Sat Feb 16 10:48:14 2013 +1100

    Merge remote-tracking branch 'levelup/master' into 0.1-wip
    
    Conflicts:
    	README.md
    	lib/errors.js
    	lib/levelup.js
    	lib/read-stream.js
    	lib/util.js
    	lib/write-stream.js
    	package.json
    	src/async.cc
    	src/database.cc
    	src/database.h
    	src/database_async.cc
    	src/database_async.h
    	src/iterator_async.cc
    	src/iterator_async.h
    	src/levelup.cc
    	src/levelup.h
    	test/benchmarks/tests/index.js
    	test/compression-test.js
    	test/deferred-open-test.js
    	test/read-stream-test.js
    	test/simple-test.js

 .jshintrc             |   2 +-
 README.md             |   4 +-
 package.json          |   2 +-
 src/async.cc          |  35 +++++-----
 src/async.h           |  14 ++--
 src/batch.cc          |  11 ++--
 src/batch.h           |  37 ++++++-----
 src/database.cc       | 179 ++++++++++++++++++++++++++------------------------
 src/database.h        |  39 +++++++----
 src/database_async.cc | 100 ++++++++++++++--------------
 src/database_async.h  |  85 ++++++++++++------------
 src/iterator.cc       |  76 +++++++++++++++++----
 src/iterator.h        |  13 ++--
 src/iterator_async.cc |  53 ++++++++-------
 src/iterator_async.h  |  29 ++++----
 src/leveldown.cc      |  27 ++------
 src/leveldown.h       |  60 +++++++++--------
 17 files changed, 424 insertions(+), 342 deletions(-)

diff --cc README.md
index 530eb5b,864893d..2380db8
--- a/README.md
+++ b/README.md
@@@ -1,78 -1,118 +1,80 @@@
 -LevelUP
 -=======
 +LevelDOWN
 +=========
  
 -Fast & simple storage - a Node.js-style LevelDB wrapper
 --------------------------------------------------------
 +A Node.js LevelDB binding (currently being extracted from LevelUP)
 +-------------------------
  
 -[![Build Status](https://secure.travis-ci.org/rvagg/node-levelup.png)](http://travis-ci.org/rvagg/node-levelup)
 +## READ THIS FIRST
  
 -**[LevelDB](http://code.google.com/p/leveldb/)** is a simple key/value data store built by Google, inspired by BigTable. It's used in Google Chrome and many other products. LevelDB supports arbitrary byte arrays as both keys and values, singular *get*, *put* and *delete* operations, *batched put and delete*, forward and reverse iteration and simple compression using the [Snappy](http://code.google.com/p/snappy/) algorithm which is optimised for speed over compression.
 +LevelDOWN is currently undergoing API development to prepare it for general use. Version 0.0.0 represents the API as it has been used internally within [LevelUP](https://github.com/rvagg/node-levelup) but this API is not ideal for public consumption.
  
 -**LevelUP** aims to expose the features of LevelDB in a Node.js-friendly way. Both keys and values are treated as `Buffer` objects and are automatically converted using a specified `'encoding'`. LevelDB's iterators are exposed as a Node.js style object-`ReadStream` and writing can be peformed via an object-`WriteStream`.
 +If you wish to contribute towards improving this API, please submit your suggestions in the form of a pull request against *this* README.md file, highlighting changes you believe ought to be made; discussion will then ensue!
  
 -An important feature of LevelDB is that it stores entries sorted by keys. This makes LevelUP's <a href="#readStream"><code>ReadStream</code></a> interface is a very powerful way to look up items, particularly when combined with the `start` option.
 +LevelDOWN is stable for general use as long as you are careful what arguments you provide (LevelUP sanitises most inputs prior to feeing them to the binding). You also need to be aware of the ongoing work on the API. Each time a breaking change is made to the API, the *Major* version will be incremented (i.e. where [semver](http://semver.org) specifies Major.Minor.Patch), so be careful with your npm dependencies!
  
 -**LevelUP** is an **OPEN Open Source Project**, see the <a href="#contributing">Contributing</a> section to find out what this means.
 +In general, the current API is fairly brittle and each method must be fed the right number and type of arguments; failing to adhere to the requirements of each method call may result in process death. Making the API more resilient will be a top priority.
  
 -  * <a href="#platforms">Tested & supported platforms</a>
 -  * <a href="#basic">Basic usage</a>
 -  * <a href="#api">API</a>
 -  * <a href="#events">Events</a>
 -  * <a href="#json">JSON data</a>
 -  * <a href="#considerations">Important considerations</a>
 -  * <a href="#contributing">Contributing</a>
 -  * <a href="#licence">Licence & copyright</a>
 +The other major priority for API-change will be to make it as easy and natural to use without unnecessary fluff (the fluff can go in LevelUP if it's really needed). The API will be as minimal as possible while still providing enough async access to LevelDB for efficient use.
  
 -See also a list of <a href="https://github.com/rvagg/node-levelup/wiki/Modules"><b>Node.js LevelDB modules and projects</b></a> in the wiki.
 -
 -<a name="platforms"></a>
 -Tested & supported platforms
 -----------------------------
 -
 -  * **Linux** (including ARM platforms such as Raspberry Pi)
 -  * **Mac OS**
 -  * **Solaris** (SmartOS & Nodejitsu)
 +<a name="api"></a>
 +## API
  
 -**Windows** support is a work in progress; see [issue #5](https://github.com/rvagg/node-levelup/issues/5) if you would like to help on that front. 
 +  * <a href="#createDatabase"><code><b>createDatabase()</b></code></a>
 +  * <a href="#createIterator"><code><b>createIterator()</b></code></a>
 +  * <a href="#leveldown_open"><code><b>leveldown#open()</b></code></a>
 +  * <a href="#leveldown_close"><code><b>leveldown#close()</b></code></a>
 +  * <a href="#leveldown_put"><code><b>leveldown#put()</b></code></a>
 +  * <a href="#leveldown_get"><code><b>leveldown#get()</b></code></a>
 +  * <a href="#leveldown_del"><code><b>leveldown#del()</b></code></a>
 +  * <a href="#leveldown_batch"><code><b>leveldown#batch()</b></code></a>
 +  * <a href="#leveldown_approximateSize"><code><b>leveldown#approximateSize()</b></code></a>
 +  * <a href="#iterator_next"><code><b>iterator#next()</b></code></a>
 +  * <a href="#iterator_end"><code><b>iterator#end()</b></code></a>
  
 -<a name="basic"></a>
 -Basic usage
 ------------
  
 -All operations are asynchronous although they don't necessarily require a callback if you don't need to know when the operation was performed.
 +--------------------------------------------------------
 +<a name="createDatabase"></a>
 +### leveldown.createDatabase()
 +<code>createDatabase()</code> returns a new **LevelDOWN** instance.
  
 -```js
 -var levelup = require('levelup')
 +--------------------------------------------------------
 +<a name="createIterator"></a>
 +### leveldown.createIterator(database, options)
 +<code>createIterator()</code> returns a new **Iterator** instance for the given `database` instance. Both arguments are required.
  
 -// 1) Create our database, supply location and options.
 -//    This will create or open the underlying LevelDB store.
 -var db = levelup('./mydb')
 +#### `options`
  
 -// 2) put a key & value
 -db.put('name', 'LevelUP', function (err) {
 -  if (err) return console.log('Ooops!', err) // some kind of I/O error
 +The `options` object may contain:
  
 -  // 3) fetch by key
 -  db.get('name', function (err, value) {
 -    if (err) return console.log('Ooops!', err) // likely the key was not found
 +* `'start'`: the key you wish to start the read at. By default it will start at the beginning of the store. Note that the *start* doesn't have to be an actual key that exists, LevelDB will simply find the *next* key, greater than the key you provide.
  
 -    // ta da!
 -    console.log('name=' + value)
 -  })
 -})
 -```
 +* `'end'`: the key you wish to end the read on. By default it will continue until the end of the store. Again, the *end* doesn't have to be an actual key as an (inclusive) `<=`-type operation is performed to detect the end. You can also use the `destroy()` method instead of supplying an `'end'` parameter to achieve the same effect.
  
 -<a name="api"></a>
 -## API
 +* `'reverse'` *(boolean, default: `false`)*: a boolean, set to true if you want the stream to go in reverse order. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek.
  
 -  * <a href="#ctor"><code><b>levelup()</b></code></a>
 -  * <a href="#open"><code>db.<b>open()</b></code></a>
 -  * <a href="#close"><code>db.<b>close()</b></code></a>
 -  * <a href="#put"><code>db.<b>put()</b></code></a>
 -  * <a href="#get"><code>db.<b>get()</b></code></a>
 -  * <a href="#del"><code>db.<b>del()</b></code></a>
 -  * <a href="#batch"><code>db.<b>batch()</b></code></a>
 -  * <a href="#approximateSize"><code>db.<b>approximateSize()</b></code></a>
 -  * <a href="#isOpen"><code>db.<b>isOpen()</b></code></a>
 -  * <a href="#isClosed"><code>db.<b>isClosed()</b></code></a>
 -  * <a href="#readStream"><code>db.<b>readStream()</b></code></a>
 -  * <a href="#keyStream"><code>db.<b>keyStream()</b></code></a>
 -  * <a href="#valueStream"><code>db.<b>valueStream()</b></code></a>
 -  * <a href="#writeStream"><code>db.<b>writeStream()</b></code></a>
 +* `'keys'` *(boolean, default: `true`)*: whether the `'data'` event should contain keys. If set to `true` and `'values'` set to `false` then `'data'` events will simply be keys, rather than objects with a `'key'` property. Used internally by the `keyStream()` method.
  
 +* `'values'` *(boolean, default: `true`)*: whether the `'data'` event should contain values. If set to `true` and `'keys'` set to `false` then `'data'` events will simply be values, rather than objects with a `'value'` property. Used internally by the `valueStream()` method.
  
 ---------------------------------------------------------
 -<a name="ctor"></a>
 -### levelup(location[, options[, callback]])
 -<code>levelup()</code> is the main entry point for creating a new LevelUP instance and opening the underlying store with LevelDB.
 +* `'limit'` *(number, default: `-1`)*: limit the number of results collected by this stream. This number represents a *maximum* number of results and may not be reached if you get to the end of the store or your `'end'` value first. A value of `-1` means there is no limit.
  
 -This function returns a new instance of LevelUP and will also initiate an <a href="#open"><code>open()</code></a> operation. Opening the database is an asynchronous operation which will trigger your callback if you provide one. The callback should take the form: `function (err, db) {}` where the `db` is the LevelUP instance. If you don't provide a callback, any read & write operations are simply queued internally until the database is fully opened.
 +* `'fillCache'` *(boolean, default: `false`)*: wheather LevelDB's LRU-cache should be filled with data read.
  
 -This leads to two alternative ways of managing a new LevelUP instance:
 +* `'keyAsBuffer'` *(boolean, default: `true`)*: Used to determine whether to return the `key` of each entry as a `String` or a Node.js `Buffer` object. Note that converting from a `Buffer` to a `String` incurs a cost so if you need a `String` (and the `value` can legitimately become a UFT8 string) then you should fetch it as one.
  
 -```js
 -levelup(location, options, function (err, db) {
 -  if (err) throw err
 -  db.get('foo', function (err, value) {
 -    if (err) return console.log('foo does not exist')
 -    console.log('got foo =', value)
 -  })
 -})
 +* `'valueAsBuffer'` *(boolean, default: `true`)*: Used to determine whether to return the `value` of each entry as a `String` or a Node.js `Buffer` object.
  
 -// vs the equivalent:
  
 -var db = levelup(location, options) // will throw if an error occurs
 -db.get('foo', function (err, value) {
 -  if (err) return console.log('foo does not exist')
 -  console.log('got foo =', value)
 -})
 -```
 +--------------------------------------------------------
 +<a name="leveldown_open"></a>
 +### leveldown#open(location, options, callback)
 +<code>open()</code> is an instance method on an existing database object. `location` is a String pointing to the LevelDB location to be opened.
  
+ The `location` argument is available as a read-only property on the returned LevelUP instance.
+ 
  #### `options`
  
 -`levelup()` takes an optional options object as its second argument; the following properties are accepted:
 +The `options` object may contain:
  
  * `'createIfMissing'` *(boolean, default: `true`)*: If `true`, will initialise an empty database at the specified location if one doesn't already exist. If `false` and a database doesn't exist you will receive an error in your `open()` callback and your database won't open.
  
@@@ -228,8 -416,8 +230,8 @@@ LevelDOWN is only possible due to the e
  Licence & copyright
  -------------------
  
 -Copyright (c) 2012-2013 LevelUP contributors (listed above).
 +Copyright (c) 2012-2013 LevelDOWN contributors (listed above).
  
 -LevelUP is licensed under an MIT +no-false-attribs license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
 +LevelDOWN is licensed under an MIT +no-false-attribs license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
  
- *LevelDOWN builds on the excellent work of the LevelDB and Snappy teams from Google and additional contributors. LevelDB and Snappy are both issued under the [New BSD Licence](http://opensource.org/licenses/BSD-3-Clause).*
 -*LevelUP builds on the excellent work of the LevelDB and Snappy teams from Google and additional contributors. LevelDB and Snappy are both issued under the [New BSD Licence](http://opensource.org/licenses/BSD-3-Clause).*
++*LevelDOWN builds on the excellent work of the LevelDB and Snappy teams from Google and additional contributors. LevelDB and Snappy are both issued under the [New BSD Licence](http://opensource.org/licenses/BSD-3-Clause).*
diff --cc src/async.cc
index a75e705,00d15eb..0835e2d
--- a/src/async.cc
+++ b/src/async.cc
@@@ -1,17 -1,12 +1,12 @@@
 -/* Copyright (c) 2012-2013 LevelUP contributors
 - * See list at <https://github.com/rvagg/node-levelup#contributing>
 - * MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE>
 +/* Copyright (c) 2012-2013 LevelDOWN contributors
 + * See list at <https://github.com/rvagg/node-leveldown#contributing>
 + * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
   */
  
- #include <cstdlib>
  #include <node.h>
- #include <node_buffer.h>
- #include <iostream>
- #include <pthread.h>
  
  #include "database.h"
- 
 -#include "levelup.h"
 +#include "leveldown.h"
  #include "async.h"
  #include "batch.h"
  
diff --cc src/batch.cc
index 55e790d,8a17b2a..4ade9f1
--- a/src/batch.cc
+++ b/src/batch.cc
@@@ -1,11 -1,8 +1,8 @@@
 -/* Copyright (c) 2012-2013 LevelUP contributors
 - * See list at <https://github.com/rvagg/node-levelup#contributing>
 - * MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE>
 +/* Copyright (c) 2012-2013 LevelDOWN contributors
 + * See list at <https://github.com/rvagg/node-leveldown#contributing>
 + * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
   */
  
- #include <cstdlib>
- #include <iostream>
- 
  #include "leveldb/write_batch.h"
  
  #include "batch.h"
diff --cc src/database.cc
index df793d3,ee4cf59..45e03ef
--- a/src/database.cc
+++ b/src/database.cc
@@@ -1,15 -1,10 +1,11 @@@
 -/* Copyright (c) 2012-2013 LevelUP contributors
 - * See list at <https://github.com/rvagg/node-levelup#contributing>
 - * MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE>
 +/* Copyright (c) 2012-2013 LevelDOWN contributors
 + * See list at <https://github.com/rvagg/node-leveldown#contributing>
 + * MIT +no-false-attribs License
 + * <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
   */
  
- #include <cstdlib>
- #include <vector>
  #include <node.h>
  #include <node_buffer.h>
- #include <iostream>
- #include <pthread.h>
  
  #include "leveldb/db.h"
  
@@@ -20,12 -15,9 +16,9 @@@
  #include "batch.h"
  #include "iterator.h"
  
- using namespace std;
- using namespace v8;
- using namespace node;
- using namespace leveldb;
+ namespace levelup {
  
 -Database::Database () {
 +Database::Database (char* location) : location(location) {
    db = NULL;
  };
  
@@@ -85,71 -73,73 +78,86 @@@ void Database::CloseDatabase () 
  
  /* V8 exposed functions *****************************/
  
- Persistent<Function> Database::constructor;
+ v8::Persistent<v8::Function> Database::constructor;
  
 -Handle<Value> CreateDatabase (const Arguments& args) {
 +Handle<Value> LevelDOWN (const Arguments& args) {
    HandleScope scope;
    return scope.Close(Database::NewInstance(args));
  }
  
  void Database::Init () {
-   Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
-   tpl->SetClassName(String::NewSymbol("Database"));
+   v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(New);
+   tpl->SetClassName(v8::String::NewSymbol("Database"));
    tpl->InstanceTemplate()->SetInternalFieldCount(1);
-   tpl->PrototypeTemplate()->Set(String::NewSymbol("open")
-       , FunctionTemplate::New(Open)->GetFunction());
-   tpl->PrototypeTemplate()->Set(String::NewSymbol("close")
-       , FunctionTemplate::New(Close)->GetFunction());
-   tpl->PrototypeTemplate()->Set(String::NewSymbol("put")
-       , FunctionTemplate::New(Put)->GetFunction());
-   tpl->PrototypeTemplate()->Set(String::NewSymbol("get")
-       , FunctionTemplate::New(Get)->GetFunction());
-   tpl->PrototypeTemplate()->Set(String::NewSymbol("del")
-       , FunctionTemplate::New(Delete)->GetFunction());
-   tpl->PrototypeTemplate()->Set(String::NewSymbol("batch")
-       , FunctionTemplate::New(Batch)->GetFunction());
-   tpl->PrototypeTemplate()->Set(String::NewSymbol("approximateSize")
-       , FunctionTemplate::New(ApproximateSize)->GetFunction());
-   constructor = Persistent<Function>::New(tpl->GetFunction());
+   tpl->PrototypeTemplate()->Set(
+       v8::String::NewSymbol("open")
+     , v8::FunctionTemplate::New(Open)->GetFunction()
+   );
+   tpl->PrototypeTemplate()->Set(
+       v8::String::NewSymbol("close")
+     , v8::FunctionTemplate::New(Close)->GetFunction()
+   );
+   tpl->PrototypeTemplate()->Set(
+       v8::String::NewSymbol("put")
+     , v8::FunctionTemplate::New(Put)->GetFunction()
+   );
+   tpl->PrototypeTemplate()->Set(
+       v8::String::NewSymbol("get")
+     , v8::FunctionTemplate::New(Get)->GetFunction()
+   );
+   tpl->PrototypeTemplate()->Set(
+       v8::String::NewSymbol("del")
+     , v8::FunctionTemplate::New(Delete)->GetFunction()
+   );
+   tpl->PrototypeTemplate()->Set(
+       v8::String::NewSymbol("batch")
+     , v8::FunctionTemplate::New(Batch)->GetFunction()
+   );
+   tpl->PrototypeTemplate()->Set(
+       v8::String::NewSymbol("approximateSize")
+     , FunctionTemplate::New(ApproximateSize)->GetFunction()
+   );
+   constructor = v8::Persistent<Function>::New(tpl->GetFunction());
  }
  
- Handle<Value> Database::New (const Arguments& args) {
-   HandleScope scope;
+ v8::Handle<Value> Database::New (const v8::Arguments& args) {
+   v8::HandleScope scope;
  
 -  Database* obj = new Database();
 +  if (args.Length() == 0) {
 +    THROW_RETURN("leveldown() requires at least a location argument")
 +  }
 +
 +  if (!args[0]->IsString()) {
 +    THROW_RETURN("leveldown() requires a location string argument")
 +  }
 +
 +  FROM_V8_STRING(location, Handle<String>::Cast(args[0]))
 +
 +  Database* obj = new Database(location);
    obj->Wrap(args.This());
  
    return args.This();
  }
  
- Handle<Value> Database::NewInstance (const Arguments& args) {
-   HandleScope scope;
+ v8::Handle<Value> Database::NewInstance (const v8::Arguments& args) {
+   v8::HandleScope scope;
+ 
 -  v8::Handle<v8::Value> argv[0];
 -  v8::Local<v8::Object> instance = constructor->NewInstance(0, argv);
++  v8::Handle<v8::Value> argv[args.Length()];
 +
-   Handle<Value> argv[args.Length()];
 +  for (int i = 0; i < args.Length(); i++)
 +    argv[i] = args[i];
 +
-   Local<Object> instance = constructor->NewInstance(args.Length(), argv);
++  v8::Local<v8::Object> instance = constructor->NewInstance(args.Length(), argv);
  
    return scope.Close(instance);
  }
  
- Handle<Value> Database::Open (const Arguments& args) {
-   HandleScope scope;
+ v8::Handle<Value> Database::Open (const v8::Arguments& args) {
+   v8::HandleScope scope;
  
 -  Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
 -  v8::String::Utf8Value location(args[0]->ToString());
 -  v8::Local<v8::Object> optionsObj = v8::Local<v8::Object>::Cast(args[1]);
 -  BOOLEAN_OPTION_VALUE(optionsObj, createIfMissing)
 +  METHOD_SETUP_COMMON(open, 0, 1)
 +
 +  BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, createIfMissing)
    BOOLEAN_OPTION_VALUE(optionsObj, errorIfExists)
    BOOLEAN_OPTION_VALUE(optionsObj, compression)
    UINT32_OPTION_VALUE(optionsObj, cacheSize, 8 << 20)
@@@ -162,16 -155,18 +170,16 @@@
      , compression
      , cacheSize
    );
 +
    AsyncQueueWorker(worker);
  
-   return Undefined();
+   return v8::Undefined();
  }
  
- Handle<Value> Database::Close (const Arguments& args) {
-   HandleScope scope;
+ v8::Handle<Value> Database::Close (const v8::Arguments& args) {
+   v8::HandleScope scope;
  
 -  Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
 -  v8::Persistent<v8::Function> callback;
 -  if (args.Length() > 0)
 -    callback = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[0]));
 +  METHOD_SETUP_COMMON_ONEARG(close)
  
    CloseWorker* worker = new CloseWorker(database, callback);
    AsyncQueueWorker(worker);
@@@ -235,15 -230,15 +243,15 @@@ v8::Handle<Value> Database::Get (const 
    );
    AsyncQueueWorker(worker);
  
-   return Undefined();
+   return v8::Undefined();
  }
  
- Handle<Value> Database::Delete (const Arguments& args) {
-   HandleScope scope;
+ v8::Handle<Value> Database::Delete (const v8::Arguments& args) {
+   v8::HandleScope scope;
  
 -  Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
 -  v8::Persistent<v8::Function> callback =
 -      v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[2]));
 +  Database* database = ObjectWrap::Unwrap<Database>(args.This());
 +  Persistent<Function> callback =
 +      Persistent<Function>::New(Local<Function>::Cast(args[2]));
  
    CB_ERR_IF_NULL_OR_UNDEFINED(0, "Key")
  
diff --cc src/database.h
index 5383f6e,4ee6637..85c99e3
--- a/src/database.h
+++ b/src/database.h
@@@ -11,11 -10,9 +10,9 @@@
  
  #include "leveldb/db.h"
  
 -#include "levelup.h"
 +#include "leveldown.h"
  
- using namespace std;
- using namespace v8;
- using namespace leveldb;
+ namespace levelup {
  
  LU_OPTION ( createIfMissing ); // for open()
  LU_OPTION ( errorIfExists   ); // for open()
@@@ -32,7 -29,7 +29,7 @@@ LU_STR    ( put   )
  
  struct AsyncDescriptor;
  
- Handle<Value> LevelDOWN (const Arguments& args);
 -v8::Handle<v8::Value> CreateDatabase (const v8::Arguments& args);
++v8::Handle<v8::Value> LevelDOWN (const v8::Arguments& args);
  
  class Database : public node::ObjectWrap {
  public:
@@@ -49,14 -60,12 +60,14 @@@
    const leveldb::Snapshot* NewSnapshot ();
    void ReleaseSnapshot (const leveldb::Snapshot* snapshot);
    void CloseDatabase ();
 +  const char* Location() const;
  
  private:
 -  Database ();
 +  Database (char* location);
    ~Database ();
  
-   DB* db;
+   leveldb::DB* db;
 +  char* location;
  
    static v8::Persistent<v8::Function> constructor;
  
diff --cc src/database_async.cc
index efeb950,1dd9b65..c264063
--- a/src/database_async.cc
+++ b/src/database_async.cc
@@@ -1,17 -1,13 +1,13 @@@
 -/* Copyright (c) 2012-2013 LevelUP contributors
 - * See list at <https://github.com/rvagg/node-levelup#contributing>
 - * MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE>
 +/* Copyright (c) 2012-2013 LevelDOWN contributors
 + * See list at <https://github.com/rvagg/node-leveldown#contributing>
 + * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
   */
  
- #include <cstdlib>
  #include <node.h>
  #include <node_buffer.h>
- #include <iostream>
- #include <pthread.h>
  
  #include "database.h"
- 
 -#include "levelup.h"
 +#include "leveldown.h"
  #include "async.h"
  #include "database_async.h"
  #include "batch.h"
@@@ -25,18 -18,22 +18,20 @@@ namespace levelup 
  
  OpenWorker::OpenWorker (
      Database* database
-   , Persistent<Function> callback
+   , v8::Persistent<v8::Function> callback
 -  , std::string location
    , bool createIfMissing
    , bool errorIfExists
    , bool compression
    , uint32_t cacheSize
  ) : AsyncWorker(database, callback)
 -  , location(location)
  {
-   options = new Options();
+   options = new leveldb::Options();
    options->create_if_missing = createIfMissing;
    options->error_if_exists = errorIfExists;
-   options->compression = compression ? kSnappyCompression : kNoCompression;
-   options->block_cache = NewLRUCache(cacheSize);
+   options->compression = compression
+     ? leveldb::kSnappyCompression
+     : leveldb::kNoCompression;
+   options->block_cache = leveldb::NewLRUCache(cacheSize);
  };
  
  OpenWorker::~OpenWorker () {
diff --cc src/database_async.h
index 8f1b95f,71b48fc..dcb83ba
--- a/src/database_async.h
+++ b/src/database_async.h
@@@ -21,7 -20,8 +20,7 @@@ class OpenWorker : public AsyncWorker 
  public:
    OpenWorker (
        Database* database
-     , Persistent<Function> callback
+     , v8::Persistent<v8::Function> callback
 -    , std::string location
      , bool createIfMissing
      , bool errorIfExists
      , bool compression
@@@ -32,7 -32,8 +31,7 @@@
    virtual void Execute ();
  
  private:
-   Options* options;
 -  std::string location;
+   leveldb::Options* options;
  };
  
  class CloseWorker : public AsyncWorker {
diff --cc src/iterator.cc
index 7d154b6,911f16a..941842d
--- a/src/iterator.cc
+++ b/src/iterator.cc
@@@ -1,13 -1,10 +1,10 @@@
 -/* Copyright (c) 2012-2013 LevelUP contributors
 - * See list at <https://github.com/rvagg/node-levelup#contributing>
 - * MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE>
 +/* Copyright (c) 2012-2013 LevelDOWN contributors
 + * See list at <https://github.com/rvagg/node-leveldown#contributing>
 + * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
   */
  
- #include <cstdlib>
  #include <node.h>
  #include <node_buffer.h>
- #include <iostream>
- #include <pthread.h>
  
  #include "database.h"
  #include "iterator.h"
@@@ -68,12 -65,32 +65,32 @@@ void leveldown::Iterator::IteratorEnd (
    dbIterator = NULL;
  }
  
+ void checkEndCallback (levelup::Iterator* iterator) {
+   iterator->nexting = false;
+   if (iterator->endWorker != NULL) {
+     AsyncQueueWorker(iterator->endWorker);
+     iterator->endWorker = NULL;
+   }
+ }
+ 
  //void *ctx, void (*callback)(void *ctx, Slice key, Slice value)
 -Handle<Value> levelup::Iterator::Next (const Arguments& args) {
 +Handle<Value> leveldown::Iterator::Next (const Arguments& args) {
    HandleScope scope;
    Iterator* iterator = ObjectWrap::Unwrap<Iterator>(args.This());
-   Persistent<Function> endCallback = Persistent<Function>::New(Local<Function>::Cast(args[0]));
-   Persistent<Function> dataCallback = Persistent<Function>::New(Local<Function>::Cast(args[1]));
+ 
+   if (iterator->ended) {
+     THROW_RETURN("Cannot call next() after end()")
+   }
+ 
+   if (iterator->nexting) {
+     THROW_RETURN("Cannot call next() before previous next() has completed")
+   }
+ 
+   Persistent<Function> endCallback =
+       Persistent<Function>::New(Local<Function>::Cast(args[0]));
+   Persistent<Function> dataCallback =
+       Persistent<Function>::New(Local<Function>::Cast(args[1]));
+ 
    NextWorker* worker = new NextWorker(
        iterator
      , dataCallback
@@@ -83,15 -102,27 +102,27 @@@
    return Undefined();
  }
  
 -Handle<Value> levelup::Iterator::End (const Arguments& args) {
 +Handle<Value> leveldown::Iterator::End (const Arguments& args) {
    HandleScope scope;
    Iterator* iterator = ObjectWrap::Unwrap<Iterator>(args.This());
-   Persistent<Function> endCallback = Persistent<Function>::New(Local<Function>::Cast(args[0]));
+ 
+   if (iterator->ended) {
+     THROW_RETURN("end() already called on iterator")
+   }
+ 
+   Persistent<Function> callback =
+       Persistent<Function>::New(Local<Function>::Cast(args[0]));
    EndWorker* worker = new EndWorker(
        iterator
-     , endCallback
+     , callback
    );
-   AsyncQueueWorker(worker);
+   iterator->ended = true;
+   if (iterator->nexting) {
+     // waiting for a next() to return, queue the end
+     iterator->endWorker = worker;
+   } else {
+     AsyncQueueWorker(worker);
+   }
    return Undefined();
  }
  
diff --cc src/iterator.h
index 8d967fb,d62b2ba..e12d96b
--- a/src/iterator.h
+++ b/src/iterator.h
@@@ -6,11 -6,11 +6,11 @@@
  #ifndef LU_ITERATOR_H
  #define LU_ITERATOR_H
  
- #include <cstdlib>
  #include <node.h>
  
 -#include "levelup.h"
 +#include "leveldown.h"
  #include "database.h"
+ #include "async.h"
  
  using namespace std;
  using namespace v8;
diff --cc src/iterator_async.cc
index 34691b3,cb33a0b..365bcda
--- a/src/iterator_async.cc
+++ b/src/iterator_async.cc
@@@ -1,17 -1,13 +1,13 @@@
 -/* Copyright (c) 2012-2013 LevelUP contributors
 - * See list at <https://github.com/rvagg/node-levelup#contributing>
 - * MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE>
 +/* Copyright (c) 2012-2013 LevelDOWN contributors
 + * See list at <https://github.com/rvagg/node-leveldown#contributing>
 + * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
   */
  
- #include <cstdlib>
  #include <node.h>
  #include <node_buffer.h>
- #include <iostream>
- #include <pthread.h>
  
  #include "database.h"
- 
 -#include "levelup.h"
 +#include "leveldown.h"
  #include "async.h"
  #include "iterator_async.h"
  
@@@ -23,9 -16,10 +16,10 @@@ namespace levelup 
  /** NEXT WORKER **/
  
  NextWorker::NextWorker (
 -    levelup::Iterator* iterator
 +    leveldown::Iterator* iterator
    , Persistent<Function> dataCallback
    , Persistent<Function> endCallback
+   , void (*localCallback)(levelup::Iterator*)
  ) : AsyncWorker(database, dataCallback)
    , iterator(iterator)
    , endCallback(endCallback)
diff --cc src/iterator_async.h
index 25be7b1,e0362a7..84eb160
--- a/src/iterator_async.h
+++ b/src/iterator_async.h
@@@ -47,7 -46,9 +46,9 @@@ public
    virtual void Execute ();
  
  private:
 -  levelup::Iterator* iterator;
 +  leveldown::Iterator* iterator;
  };
  
+ } // namespace levelup
+ 
  #endif
diff --cc src/leveldown.cc
index a8f78e5,0000000..b17e385
mode 100644,000000..100644
--- a/src/leveldown.cc
+++ b/src/leveldown.cc
@@@ -1,41 -1,0 +1,26 @@@
 +/* Copyright (c) 2012-2013 LevelDOWN contributors
 + * See list at <https://github.com/rvagg/node-leveldown#contributing>
 + * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
 + */
 +
 +#include <node.h>
 +
 +#include "leveldown.h"
 +#include "database.h"
 +#include "iterator.h"
 +
- using namespace v8;
- using namespace node;
- using namespace leveldown;
++namespace levelup {
 +
 +void Init (Handle<Object> target) {
 +  Database::Init();
 +  leveldown::Iterator::Init();
 +
-   target->Set(String::NewSymbol("leveldown")
-       , FunctionTemplate::New(LevelDOWN)->GetFunction());
-   target->Set(String::NewSymbol("createIterator")
-       , FunctionTemplate::New(CreateIterator)->GetFunction());
++  target->Set(v8::String::NewSymbol("leveldown")
++      , v8::FunctionTemplate::New(LevelDOWN)->GetFunction());
++  target->Set(v8::String::NewSymbol("createIterator")
++      , v8::FunctionTemplate::New(CreateIterator)->GetFunction());
 +}
 +
 +NODE_MODULE(leveldown, Init)
 +
- // util
- 
- void RunCallback (
-       Persistent<Function> callback
-     , Local<Value> argv[]
-     , int length) {
- 
-   TryCatch try_catch;
-  
-   callback->Call(Context::GetCurrent()->Global(), length, argv);
-   if (try_catch.HasCaught()) {
-     FatalException(try_catch);
-   }
- }
++} // namespace levelup
diff --cc src/leveldown.h
index 1228e9d,0000000..297cb78
mode 100644,000000..100644
--- a/src/leveldown.h
+++ b/src/leveldown.h
@@@ -1,109 -1,0 +1,117 @@@
 +/* Copyright (c) 2012-2013 LevelDOWN contributors
 + * See list at <https://github.com/rvagg/node-leveldown#contributing>
 + * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
 + */
 +
 +#ifndef LU_LEVELDOWN_H
 +#define LU_LEVELDOWN_H
 +
 +#define LU_STR(key) \
-   static Persistent<String> str_ ## key = Persistent<String>::New(String::New(#key));
++  static v8::Persistent<v8::String> str_ ## key = \
++    v8::Persistent<v8::String>::New(v8::String::New(#key));
 +
 +#define LU_OPTION(key) \
-   static Persistent<String> option_ ## key = Persistent<String>::New(String::New(#key));
++  static v8::Persistent<v8::String> option_ ## key = \
++    v8::Persistent<v8::String>::New(v8::String::New(#key));
 +
 +#define LU_V8_METHOD(name) \
 +  static v8::Handle<v8::Value> name (const v8::Arguments& args);
 +
 +#define CB_ERR_IF_NULL_OR_UNDEFINED(index, name) \
 +  if (args[index]->IsNull() || args[index]->IsUndefined()) { \
-     Local<Value> argv[] = { \
-       Local<Value>::New(Exception::Error(String::New("#name cannot be `null` or `undefined`"))) \
++    v8::Local<v8::Value> argv[] = { \
++      v8::Local<v8::Value>::New(Exception::Error( \
++        v8::String::New("#name cannot be `null` or `undefined`")) \
++      ) \
 +    }; \
-     RunCallback(callback, argv, 1); \
++    RUN_CALLBACK(callback, argv, 1); \
 +    return Undefined(); \
 +  }
 +
 +#define FROM_V8_STRING(to, from) \
 +  size_t to ## Sz_; \
 +  char* to; \
-   Local<String> to ## Str = from->ToString(); \
++  v8::Local<v8::String> to ## Str = from->Tov8::String(); \
 +  to ## Sz_ = to ## Str->Utf8Length(); \
 +  to = new char[to ## Sz_ + 1]; \
-   to ## Str->WriteUtf8(to, -1, NULL, String::NO_OPTIONS);
++  to ## Str->WriteUtf8(to, -1, NULL, v8::String::NO_OPTIONS);
 +
 +#define STRING_OR_BUFFER_TO_SLICE(to, from) \
 +  size_t to ## Sz_; \
 +  char* to ## Ch_; \
 +  if (Buffer::HasInstance(from->ToObject())) { \
 +    to ## Sz_ = Buffer::Length(from->ToObject()); \
 +    to ## Ch_ = Buffer::Data(from->ToObject()); \
 +  } else { \
-     Local<String> to ## Str = from->ToString(); \
++    v8::Local<v8::String> to ## Str = from->Tov8::String(); \
 +    to ## Sz_ = to ## Str->Utf8Length(); \
 +    to ## Ch_ = new char[to ## Sz_]; \
-     to ## Str->WriteUtf8(to ## Ch_, -1, NULL, String::NO_NULL_TERMINATION); \
++    to ## Str->WriteUtf8(to ## Ch_, -1, NULL, v8::String::NO_NULL_TERMINATION); \
 +  } \
 +  Slice to(to ## Ch_, to ## Sz_);
 +
 +#define BOOLEAN_OPTION_VALUE(optionsObj, opt) \
 +  bool opt = !optionsObj.IsEmpty() \
 +    && optionsObj->Has(option_ ## opt) \
-     && optionsObj->Get(option_ ## opt)->BooleanValue();
++    && optionsObj->Get(option_ ## opt)->Booleanv8::Value();
 +
 +#define BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, opt) \
 +  bool opt = optionsObj.IsEmpty() \
 +    || !optionsObj->Has(option_ ## opt) \
-     || optionsObj->Get(option_ ## opt)->BooleanValue();
++    || optionsObj->Get(option_ ## opt)->Booleanv8::Value();
 +
 +#define 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() \
++      ? optionsObj->Get(option_ ## opt)->Uint32v8::Value() \
 +      : default;
 +
- #define RUN_CALLBACK(callback, length, argv) \
++#define RUN_CALLBACK(callback, argv, length) \
 +  TryCatch try_catch; \
 +  callback->Call(Context::GetCurrent()->Global(), length, argv); \
 +  if (try_catch.HasCaught()) { \
 +    FatalException(try_catch); \
 +  }
 +
 +#define THROW_RETURN(msg) \
-   ThrowException(Exception::Error(String::New(#msg))); \
++  ThrowException(Exception::Error(v8::String::New(#msg))); \
 +  return Undefined();
 +
 +/* METHOD_SETUP_COMMON setup the following objects:
 + *  - Database* database
-  *  - Local<Object> optionsObj (may be empty)
-  *  - Persistent<Function> callback (won't be empty)
++ *  - v8::Local<Object> optionsObj (may be empty)
++ *  - v8::Persistent<v8::Function> callback (won't be empty)
 + * Will THROW_RETURN if there isn't a callback in arg 0 or 1
 + */
 +#define METHOD_SETUP_COMMON(name, optionPos, callbackPos) \
 +  if (args.Length() == 0) { \
 +    THROW_RETURN(name() requires a callback argument 2) \
 +  } \
 +  Database* database = ObjectWrap::Unwrap<Database>(args.This()); \
-   Local<Object> optionsObj; \
-   Persistent<Function> callback; \
++  v8::Local<Object> optionsObj; \
++  v8::Persistent<v8::Function> callback; \
 +  if (optionPos == -1) { \
-     callback = Persistent<Function>::New(Local<Function>::Cast(args[callbackPos])); \
-   } else if (args[callbackPos - 1]->IsFunction()) { \
-     callback = Persistent<Function>::New(Local<Function>::Cast(args[callbackPos - 1])); \
++    callback = v8::Persistent<v8::Function>::New( \
++      v8::Local<v8::Function>::Cast(args[callbackPos]) \
++    ); \
++  } else if (args[callbackPos - 1]->Isv8::Function()) { \
++    callback = v8::Persistent<v8::Function>::New( \
++      v8::Local<v8::Function>::Cast(args[callbackPos - 1]) \
++    ); \
 +  } else if (args[optionPos]->IsObject()) { \
-     optionsObj = Local<Object>::Cast(args[optionPos]); \
-     callback = Persistent<Function>::New(Local<Function>::Cast(args[callbackPos])); \
++    optionsObj = v8::Local<Object>::Cast(args[optionPos]); \
++    callback = v8::Persistent<v8::Function>::New( \
++      v8::Local<v8::Function>::Cast(args[callbackPos]) \
++    ); \
 +  } else { \
 +    THROW_RETURN(name() requires a callback argument 3) \
 +  }
 +
 +#define METHOD_SETUP_COMMON_ONEARG(name) \
-   if (!args[0]->IsFunction()) { \
++  if (!args[0]->Isv8::Function()) { \
 +    THROW_RETURN(name() requires a callback argument 1) \
 +  } \
 +  METHOD_SETUP_COMMON(name, -1, 0)
 +
- void RunCallback (v8::Persistent<v8::Function> callback, v8::Local<v8::Value> argv[], int length);
- 
 +#endif

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