Commit 6c2295dc by Dane Springmeyer

Merge remote-tracking branch 'kkoopa/master'

Conflicts:
	package.json
parents 6ec345d9 4267d542
......@@ -4,6 +4,7 @@ env:
matrix:
- export NODE_VERSION="0.8"
- export NODE_VERSION="0.10" NODE_WEBKIT="0.8.6"
- export NODE_VERSION="0.11"
global:
- secure: QhuP5E/kYL1j1KDkHGJtk6DSJr1RH4DR/JrC62Viuf5Du8jE+i0kPWfF2MxtuEmKo35orhpu8t8mzKygWfuO63WPuuIE9qd/+V/y99Lqcj0tEN6wJ5RnywktbTJWg23zphjhmYq3Xj8DLVEikCZBwHtlbygkO9Q60cn1PK+bnPg=
- secure: HxCS2dQAWI0KmCFnFNNZoucG4FeAW+itG7+Hp0dNtwmxZzGOZYFO2bZcGvTAMNfVN++oqLxTebYQI1oB5yUl5mPJjrjthaGS6Zq3S6rfJcXiv+icYgEXlR6ejQ97dsHw1Jeg8nedCQlI4kHfvG6pgBLhq9hnugxH1Cjhdt14E9U=
......
......@@ -7,6 +7,7 @@
"targets": [
{
"target_name": "<(module_name)",
"include_dirs": ["<!(node -e \"require('nan')\")"],
"conditions": [
["sqlite != 'internal'", {
"libraries": [
......
......@@ -36,7 +36,10 @@
"url": "git://github.com/mapbox/node-sqlite3.git"
},
"dependencies": {
"node-pre-gyp": "0.5.13"
"node-pre-gyp": "0.5.13",
"nan": "1.1.2",
"node-pre-gyp": "0.5.13",
"set-immediate": "0.1.1"
},
"bundledDependencies": [
"node-pre-gyp"
......@@ -45,7 +48,7 @@
"mocha": "*"
},
"engines": {
"node": ">= 0.8.0 < 0.11.0"
"node": ">= 0.8.0 < 0.13.0"
},
"scripts": {
"install": "node-pre-gyp install --fallback-to-build",
......
......@@ -26,7 +26,7 @@ public:
: callback(cb_), parent(parent_) {
watcher.data = this;
NODE_SQLITE3_MUTEX_INIT
uv_async_init(uv_default_loop(), &watcher, listener);
uv_async_init(uv_default_loop(), &watcher, reinterpret_cast<uv_async_cb>(listener));
}
static void listener(uv_async_t* handle, int status) {
......
#ifndef NODE_SQLITE3_SRC_DATABASE_H
#define NODE_SQLITE3_SRC_DATABASE_H
......@@ -7,6 +8,7 @@
#include <queue>
#include <sqlite3.h>
#include "nan.h"
#include "async.h"
using namespace v8;
......@@ -23,9 +25,10 @@ public:
static void Init(Handle<Object> target);
static inline bool HasInstance(Handle<Value> val) {
NanScope();
if (!val->IsObject()) return false;
Local<Object> obj = val->ToObject();
return constructor_template->HasInstance(obj);
return NanNew(constructor_template)->HasInstance(obj);
}
struct Baton {
......@@ -39,11 +42,11 @@ public:
db(db_), status(SQLITE_OK) {
db->Ref();
request.data = this;
callback = Persistent<Function>::New(cb_);
NanAssignPersistent(callback, cb_);
}
virtual ~Baton() {
db->Unref();
callback.Dispose();
NanDisposePersistent(callback);
}
};
......@@ -99,7 +102,7 @@ public:
protected:
Database() : ObjectWrap(),
handle(NULL),
_handle(NULL),
open(false),
locked(false),
pending(0),
......@@ -107,48 +110,47 @@ protected:
debug_trace(NULL),
debug_profile(NULL),
update_event(NULL) {
}
~Database() {
RemoveCallbacks();
sqlite3_close(handle);
handle = NULL;
sqlite3_close(_handle);
_handle = NULL;
open = false;
}
static Handle<Value> New(const Arguments& args);
static NAN_METHOD(New);
static void Work_BeginOpen(Baton* baton);
static void Work_Open(uv_work_t* req);
static void Work_AfterOpen(uv_work_t* req);
static Handle<Value> OpenGetter(Local<String> str, const AccessorInfo& accessor);
static NAN_GETTER(OpenGetter);
void Schedule(Work_Callback callback, Baton* baton, bool exclusive = false);
void Process();
static Handle<Value> Exec(const Arguments& args);
static NAN_METHOD(Exec);
static void Work_BeginExec(Baton* baton);
static void Work_Exec(uv_work_t* req);
static void Work_AfterExec(uv_work_t* req);
static Handle<Value> Wait(const Arguments& args);
static NAN_METHOD(Wait);
static void Work_Wait(Baton* baton);
static Handle<Value> Close(const Arguments& args);
static NAN_METHOD(Close);
static void Work_BeginClose(Baton* baton);
static void Work_Close(uv_work_t* req);
static void Work_AfterClose(uv_work_t* req);
static Handle<Value> LoadExtension(const Arguments& args);
static NAN_METHOD(LoadExtension);
static void Work_BeginLoadExtension(Baton* baton);
static void Work_LoadExtension(uv_work_t* req);
static void Work_AfterLoadExtension(uv_work_t* req);
static Handle<Value> Serialize(const Arguments& args);
static Handle<Value> Parallelize(const Arguments& args);
static NAN_METHOD(Serialize);
static NAN_METHOD(Parallelize);
static Handle<Value> Configure(const Arguments& args);
static NAN_METHOD(Configure);
static void SetBusyTimeout(Baton* baton);
......@@ -167,7 +169,7 @@ protected:
void RemoveCallbacks();
protected:
sqlite3* handle;
sqlite3* _handle;
bool open;
bool locked;
......
......@@ -7,35 +7,27 @@ const char* sqlite_authorizer_string(int type);
#define REQUIRE_ARGUMENTS(n) \
if (args.Length() < (n)) { \
return ThrowException( \
Exception::TypeError(String::New("Expected " #n "arguments")) \
); \
return NanThrowTypeError("Expected " #n "arguments"); \
}
#define REQUIRE_ARGUMENT_EXTERNAL(i, var) \
if (args.Length() <= (i) || !args[i]->IsExternal()) { \
return ThrowException( \
Exception::TypeError(String::New("Argument " #i " invalid")) \
); \
return NanThrowTypeError("Argument " #i " invalid"); \
} \
Local<External> var = Local<External>::Cast(args[i]);
#define REQUIRE_ARGUMENT_FUNCTION(i, var) \
if (args.Length() <= (i) || !args[i]->IsFunction()) { \
return ThrowException(Exception::TypeError( \
String::New("Argument " #i " must be a function")) \
); \
return NanThrowTypeError("Argument " #i " must be a function"); \
} \
Local<Function> var = Local<Function>::Cast(args[i]);
#define REQUIRE_ARGUMENT_STRING(i, var) \
if (args.Length() <= (i) || !args[i]->IsString()) { \
return ThrowException(Exception::TypeError( \
String::New("Argument " #i " must be a string")) \
); \
return NanThrowTypeError("Argument " #i " must be a string"); \
} \
String::Utf8Value var(args[i]->ToString());
......@@ -44,9 +36,7 @@ const char* sqlite_authorizer_string(int type);
Local<Function> var; \
if (args.Length() > i && !args[i]->IsUndefined()) { \
if (!args[i]->IsFunction()) { \
return ThrowException(Exception::TypeError( \
String::New("Argument " #i " must be a function")) \
); \
return NanThrowTypeError("Argument " #i " must be a function"); \
} \
var = Local<Function>::Cast(args[i]); \
}
......@@ -61,68 +51,62 @@ const char* sqlite_authorizer_string(int type);
var = args[i]->Int32Value(); \
} \
else { \
return ThrowException(Exception::TypeError( \
String::New("Argument " #i " must be an integer")) \
); \
return NanThrowTypeError("Argument " #i " must be an integer"); \
}
#define DEFINE_CONSTANT_INTEGER(target, constant, name) \
(target)->Set( \
String::NewSymbol(#name), \
Integer::New(constant), \
NanNew(#name), \
NanNew<Integer>(constant), \
static_cast<PropertyAttribute>(ReadOnly | DontDelete) \
);
#define DEFINE_CONSTANT_STRING(target, constant, name) \
(target)->Set( \
String::NewSymbol(#name), \
String::NewSymbol(constant), \
NanNew(#name), \
NanNew(constant), \
static_cast<PropertyAttribute>(ReadOnly | DontDelete) \
);
#define NODE_SET_GETTER(target, name, function) \
(target)->InstanceTemplate() \
->SetAccessor(String::NewSymbol(name), (function));
->SetAccessor(NanNew(name), (function));
#define GET_STRING(source, name, property) \
String::Utf8Value name((source)->Get(String::NewSymbol(property)));
String::Utf8Value name((source)->Get(NanNew(property)));
#define GET_INTEGER(source, name, property) \
int name = (source)->Get(String::NewSymbol(property))->Int32Value();
int name = (source)->Get(NanNew(property))->Int32Value();
#define EXCEPTION(msg, errno, name) \
Local<Value> name = Exception::Error( \
String::Concat( \
String::Concat( \
String::NewSymbol(sqlite_code_string(errno)), \
String::NewSymbol(": ") \
NanNew(sqlite_code_string(errno)), \
NanNew(": ") \
), \
(msg) \
) \
); \
Local<Object> name ##_obj = name->ToObject(); \
name ##_obj->Set(NODE_PSYMBOL("errno"), Integer::New(errno)); \
name ##_obj->Set(NODE_PSYMBOL("code"), \
String::NewSymbol(sqlite_code_string(errno)));
name ##_obj->Set(NanNew("errno"), NanNew<Integer>(errno)); \
name ##_obj->Set(NanNew("code"), \
NanNew(sqlite_code_string(errno)));
#define EMIT_EVENT(obj, argc, argv) \
TRY_CATCH_CALL((obj), \
Local<Function>::Cast((obj)->Get(String::NewSymbol("emit"))), \
Local<Function>::Cast((obj)->Get(NanNew("emit"))), \
argc, argv \
);
#define TRY_CATCH_CALL(context, callback, argc, argv) \
{ TryCatch try_catch; \
(callback)->Call((context), (argc), (argv)); \
if (try_catch.HasCaught()) { \
FatalException(try_catch); \
} }
NanMakeCallback((context), (callback), (argc), (argv))
#define WORK_DEFINITION(name) \
static Handle<Value> name(const Arguments& args); \
static NAN_METHOD(name); \
static void Work_Begin##name(Baton* baton); \
static void Work_##name(uv_work_t* req); \
static void Work_After##name(uv_work_t* req);
......@@ -164,4 +148,3 @@ const char* sqlite_authorizer_string(int type);
}
#endif
......@@ -16,6 +16,7 @@ using namespace node_sqlite3;
namespace {
void RegisterModule(v8::Handle<Object> target) {
NanScope();
Database::Init(target);
Statement::Init(target);
......@@ -103,4 +104,4 @@ const char* sqlite_authorizer_string(int type) {
}
}
NODE_MODULE(node_sqlite3, RegisterModule);
NODE_MODULE(node_sqlite3, RegisterModule)
......@@ -13,6 +13,7 @@
#include <vector>
#include <sqlite3.h>
#include "nan.h"
using namespace v8;
using namespace node;
......@@ -76,7 +77,7 @@ public:
static Persistent<FunctionTemplate> constructor_template;
static void Init(Handle<Object> target);
static Handle<Value> New(const Arguments& args);
static NAN_METHOD(New);
struct Baton {
uv_work_t request;
......@@ -87,7 +88,7 @@ public:
Baton(Statement* stmt_, Handle<Function> cb_) : stmt(stmt_) {
stmt->Ref();
request.data = this;
callback = Persistent<Function>::New(cb_);
NanAssignPersistent(callback, cb_);
}
virtual ~Baton() {
for (unsigned int i = 0; i < parameters.size(); i++) {
......@@ -95,7 +96,7 @@ public:
DELETE_FIELD(field);
}
stmt->Unref();
callback.Dispose();
NanDisposePersistent(callback);
}
};
......@@ -175,15 +176,15 @@ public:
~Async() {
stmt->Unref();
item_cb.Dispose();
completed_cb.Dispose();
NanDisposePersistent(item_cb);
NanDisposePersistent(completed_cb);
NODE_SQLITE3_MUTEX_DESTROY
}
};
Statement(Database* db_) : ObjectWrap(),
db(db_),
handle(NULL),
_handle(NULL),
status(SQLITE_OK),
prepared(false),
locked(true),
......@@ -202,7 +203,7 @@ public:
WORK_DEFINITION(Each);
WORK_DEFINITION(Reset);
static Handle<Value> Finalize(const Arguments& args);
static NAN_METHOD(Finalize);
protected:
static void Work_BeginPrepare(Database::Baton* baton);
......@@ -216,8 +217,8 @@ protected:
void Finalize();
template <class T> inline Values::Field* BindParameter(const Handle<Value> source, T pos);
template <class T> T* Bind(const Arguments& args, int start = 0, int end = -1);
bool Bind(const Parameters & parameters);
template <class T> T* Bind(_NAN_METHOD_ARGS, int start = 0, int end = -1);
bool Bind(const Parameters &parameters);
static void GetRow(Row* row, sqlite3_stmt* stmt);
static Local<Object> RowToJS(Row* row);
......@@ -229,7 +230,7 @@ protected:
protected:
Database* db;
sqlite3_stmt* handle;
sqlite3_stmt* _handle;
int status;
std::string message;
......
var sqlite3 = require('..');
var assert = require('assert');
require('set-immediate');
describe('profiling', function() {
var create = false;
......@@ -14,6 +15,7 @@ describe('profiling', function() {
if (sql.match(/^SELECT/)) {
assert.ok(!select);
assert.equal(sql, "SELECT * FROM foo");
console.log('profile select');
select = true;
}
else if (sql.match(/^CREATE/)) {
......@@ -31,7 +33,7 @@ describe('profiling', function() {
assert.ok(!create);
db.run("CREATE TABLE foo (id int)", function(err) {
if (err) throw err;
process.nextTick(function() {
setImmediate(function() {
assert.ok(create);
done();
});
......@@ -43,10 +45,10 @@ describe('profiling', function() {
assert.ok(!select);
db.run("SELECT * FROM foo", function(err) {
if (err) throw err;
process.nextTick(function() {
setImmediate(function() {
assert.ok(select);
done();
});
}, 0);
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment