Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added node v0.11 support.

Change-Id: I076aad52a12349417c33808dba25798211839fd9
Reviewed-on: http://review.couchbase.org/30486
Reviewed-by: Mark Nunberg <mnunberg@haskalah.org>
Tested-by: Brett Lawson <brett19@gmail.com>
  • Loading branch information...
commit 0beb117845e9b6a3ad48287062df94c7c9728a36 1 parent 00fce25
@brett19 brett19 authored
View
1  binding.gyp
@@ -102,6 +102,7 @@
'src/valueformat.cc'
],
'include_dirs': [
+ '<!(node -e "require(\'nan\')")',
'./',
'./src/io'
]
View
3  deps/lcb/libcouchbase.gyp
@@ -214,7 +214,8 @@
}, {
'files': [
'plugins/io/libuv/plugin-libuv.c',
- 'plugins/io/libuv/plugin-internal.h'
+ 'plugins/io/libuv/plugin-internal.h',
+ 'plugins/io/libuv/libuv_compat.h'
],
'destination': 'include/libcouchbase/plugins/io/libuv/'
}],
View
156 deps/lcb/plugins/io/libuv/libuv_compat.h
@@ -0,0 +1,156 @@
+/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ * Copyright 2013 Couchbase, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LIBUV_COMPAT_H
+#define LIBUV_COMPAT_H
+
+#ifdef UV_VERSION_MAJOR
+#define UV_VERSION ((UV_VERSION_MAJOR << 16) | \
+ (UV_VERSION_MINOR << 8) | \
+ (UV_VERSION_PATCH))
+#else
+#define UV_VERSION 0x000b00
+#endif
+
+#if defined(_WIN32) && defined(LIBCOUCHBASE_INTERNAL)
+#include "win32/win_errno_sock.h"
+#endif
+
+#ifndef UNKNOWN
+#define UNKNOWN -1
+#endif
+
+#ifndef EAIFAMNOSUPPORT
+#define EAIFAMNOSUPPORT EAI_FAMILY
+#endif
+
+#ifndef EAISERVICE
+#define EAISERVICE EAI_SERVICE
+#endif
+
+#ifndef EAI_SYSTEM
+#define EAI_SYSTEM -11
+#endif
+#ifndef EADDRINFO
+#define EADDRINFO EAI_SYSTEM
+#endif
+
+#ifndef EAISOCKTYPE
+#define EAISOCKTYPE EAI_SOCKTYPE
+#endif
+
+#ifndef ECHARSET
+#define ECHARSET 0
+#endif
+
+#ifndef EOF
+#define EOF -1
+#endif
+
+#ifndef ENONET
+#define ENONET ENETDOWN
+#endif
+
+#ifndef ESHUTDOWN
+#define ESHUTDOWN WSAESHUTDOWN
+#endif
+
+#ifndef EAI_CANCELED
+#define EAI_CANCELED -101
+#endif
+
+#ifndef EAI_ADDRFAMILY
+#define EAI_ADDRFAMILY -9
+#endif
+
+#define OK 0
+
+#if UV_VERSION < 0x000900
+ #define UVC_RUN_ONCE(l) uv_run_once(l)
+ #define UVC_RUN_DEFAULT(l) uv_run(l)
+#else
+ #define UVC_RUN_ONCE(l) uv_run(l, UV_RUN_ONCE)
+ #define UVC_RUN_DEFAULT(l) uv_run(l, UV_RUN_DEFAULT)
+#endif
+
+#if UV_VERSION < 0x000b00
+
+ #define UVC_TCP_CONNECT(req, handle, addr, cb) \
+ uv_tcp_connect(req, handle, *(struct sockaddr_in *)addr, cb);
+
+ #define UVC_TCP_CONNECT6(req, handle, addr, cb) \
+ uv_tcp_connect6(req, handle, *(struct sockaddr_in6 *)addr, cb);
+
+ #define UVC_ALLOC_CB(func) \
+ uv_buf_t func(uv_handle_t *handle, size_t suggested_size)
+
+ #define UVC_ALLOC_CB_VARS() \
+ uv_buf_t _buf; uv_buf_t *buf = &_buf;
+
+ #define UVC_ALLOC_CB_RETURN() \
+ return _buf;
+
+ #define UVC_READ_CB(func) \
+ void func(uv_stream_t *stream, ssize_t nread, const uv_buf_t _buf)
+
+ #define UVC_READ_CB_VARS() \
+ const uv_buf_t *buf = &_buf;
+
+ static int uvc_last_errno(uv_loop_t *loop, int error) {
+ int uverr = 0;
+
+ if (!error) {
+ return 0;
+ }
+
+ uverr = uv_last_error(loop).code;
+#define X(errnum,errname,errdesc) \
+ if (uverr == UV_##errname) { \
+ return errname; \
+ }
+ UV_ERRNO_MAP(X);
+#undef X
+
+ return 0;
+ }
+
+#else
+
+ #define UVC_TCP_CONNECT(req, handle, addr, cb) \
+ uv_tcp_connect(req, handle, addr, cb);
+
+ #define UVC_TCP_CONNECT6(req, handle, addr, cb) \
+ uv_tcp_connect(req, handle, addr, cb);
+
+ #define UVC_ALLOC_CB(func) \
+ void func(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
+
+ #define UVC_ALLOC_CB_VARS()
+
+ #define UVC_ALLOC_CB_RETURN()
+
+ #define UVC_READ_CB(func) \
+ void func(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
+
+ #define UVC_READ_CB_VARS()
+
+ static int uvc_last_errno(uv_loop_t *loop, int error) {
+ return error;
+ }
+
+#endif
+#endif
View
10 deps/lcb/plugins/io/libuv/plugin-internal.h
@@ -28,6 +28,8 @@
#include <string.h>
#include <sys/types.h>
+#include "libuv_compat.h"
+
#ifdef LCBUV_EMBEDDED_SOURCE
#include <libcouchbase/libuv_io_opts.h>
#else
@@ -158,14 +160,6 @@ typedef struct {
#define incref_iops(io) (io)->iops_refcount++
-#if (UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR < 10)
-#define LCBUV_LOOP_ONCE(l) uv_run_once(l)
-#define LCBUV_LOOP_DEFL(l) uv_run(l)
-#else
-#define LCBUV_LOOP_ONCE(l) uv_run(l, UV_RUN_ONCE)
-#define LCBUV_LOOP_DEFL(l) uv_run(l, UV_RUN_DEFAULT)
-#endif
-
#ifdef _WIN32
typedef ULONG lcb_uvbuf_len_t;
#else
View
102 deps/lcb/plugins/io/libuv/plugin-libuv.c
@@ -47,7 +47,7 @@ static void iops_lcb_dtor(lcb_io_opt_t iobase)
}
while (io->iops_refcount > 1) {
- LCBUV_LOOP_ONCE(io->loop);
+ UVC_RUN_ONCE(io->loop);
}
if (io->external_loop == 0) {
@@ -63,7 +63,7 @@ static void iops_lcb_dtor(lcb_io_opt_t iobase)
******************************************************************************
******************************************************************************/
-#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR < 10
+#if UV_VERSION < 0x000900
static void do_run_loop(my_iops_t *io)
{
while (uv_run_once(io->loop) && io->do_stop == 0) {
@@ -358,15 +358,15 @@ static int start_connect(lcb_io_opt_t iobase,
}
if (namelen == sizeof(struct sockaddr_in)) {
- ret = uv_tcp_connect(&uvr->uvreq.conn,
+ ret = UVC_TCP_CONNECT(&uvr->uvreq.conn,
&sock->tcp.t,
- *(struct sockaddr_in *)name,
+ name,
connect_callback);
} else if (namelen == sizeof(struct sockaddr_in6)) {
- ret = uv_tcp_connect6(&uvr->uvreq.conn,
+ ret = UVC_TCP_CONNECT6(&uvr->uvreq.conn,
&sock->tcp.t,
- *(struct sockaddr_in6 *)name,
+ name,
connect_callback);
} else {
@@ -478,26 +478,29 @@ static int start_write(lcb_io_opt_t iobase,
** Read Functions **
******************************************************************************
******************************************************************************/
-static uv_buf_t alloc_cb(uv_handle_t *handle, size_t suggested_size)
+static UVC_ALLOC_CB(alloc_cb)
{
- uv_buf_t ret;
+ UVC_ALLOC_CB_VARS()
+
my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, handle, tcp);
struct lcb_buf_info *bi = &sock->base.read_buffer;
lcb_assert(sock->cur_iov == 0);
- ret.base = bi->iov[0].iov_base;
- ret.len = (lcb_uvbuf_len_t)bi->iov[0].iov_len;
+ buf->base = bi->iov[0].iov_base;
+ buf->len = (lcb_uvbuf_len_t)bi->iov[0].iov_len;
sock->cur_iov++;
sock->read_done = 1;
(void)suggested_size;
- return ret;
+ UVC_ALLOC_CB_RETURN();
}
-static void read_cb(uv_stream_t *stream, ssize_t nread, uv_buf_t buf)
+static UVC_READ_CB(read_cb)
{
+ UVC_READ_CB_VARS()
+
my_tcp_t *mt = (my_tcp_t *)stream;
my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, mt, tcp);
@@ -709,75 +712,6 @@ static void wire_timer_ops(lcb_io_opt_t iop)
iop->v.v1.destroy_timer = destroy_timer;
}
-#if defined(_WIN32) && defined(LIBCOUCHBASE_INTERNAL)
-#include "win32/win_errno_sock.h"
-#endif
-
-static int errno_map(int uverr)
-{
-
-#ifndef UNKNOWN
-#define UNKNOWN -1
-#endif
-
-#ifndef EAIFAMNOSUPPORT
-#define EAIFAMNOSUPPORT EAI_FAMILY
-#endif
-
-#ifndef EAISERVICE
-#define EAISERVICE EAI_SERVICE
-#endif
-
-#ifndef EAI_SYSTEM
-#define EAI_SYSTEM -11
-#endif
-#ifndef EADDRINFO
-#define EADDRINFO EAI_SYSTEM
-#endif
-
-#ifndef EAISOCKTYPE
-#define EAISOCKTYPE EAI_SOCKTYPE
-#endif
-
-#ifndef ECHARSET
-#define ECHARSET 0
-#endif
-
-#ifndef EOF
-#define EOF -1
-#endif
-
-#ifndef ENONET
-#define ENONET ENETDOWN
-#endif
-
-#ifndef ESHUTDOWN
-#define ESHUTDOWN WSAESHUTDOWN
-#endif
-
-#ifndef EAI_CANCELED
-#define EAI_CANCELED -101
-#endif
-
-#ifndef EAI_ADDRFAMILY
-#define EAI_ADDRFAMILY -9
-#endif
-
-#define OK 0
-
- int ret = 0;
-#define X(errnum,errname,errdesc) \
- if (uverr == UV_##errname) { \
- return errname; \
- }
- UV_ERRNO_MAP(X);
-
- return ret;
-
-#undef X
-}
-
-
static my_uvreq_t *alloc_uvreq(my_sockdata_t *sock, generic_callback_t callback)
{
my_uvreq_t *ret = calloc(1, sizeof(*ret));
@@ -793,11 +727,7 @@ static my_uvreq_t *alloc_uvreq(my_sockdata_t *sock, generic_callback_t callback)
static void set_last_error(my_iops_t *io, int error)
{
- if (!error) {
- io->base.v.v1.error = 0;
- return;
- }
- io->base.v.v1.error = errno_map(uv_last_error(io->loop).code);
+ io->base.v.v1.error = uvc_last_errno(io->loop, error);
}
static void generic_close_cb(uv_handle_t *handle)
View
3  package.json
@@ -9,7 +9,8 @@
"license" : "Apache2",
"name": "couchbase",
"dependencies": {
- "bindings": "~1.0.0"
+ "bindings": "~1.0.0",
+ "nan": "git+https://github.com/brett19/nan.git#b0e8b0fe1bfd4518f2417ce81e06be26dc22c3d1"
},
"devDependencies": {
"async": "0.2.9",
View
14 src/cas.cc
@@ -41,10 +41,10 @@ bool Cas::GetCas(Handle<Value> obj, uint64_t *p)
#else
-static void casDtor(Persistent<Value> obj, void *p) {
- delete (uint64_t*)p;
- obj.Dispose();
- obj.Clear();
+static NAN_WEAK_CALLBACK(uint64_t*, casDtor) {
+ delete NAN_WEAK_CALLBACK_DATA(uint64_t*);
+ NAN_WEAK_CALLBACK_OBJECT.Dispose();
+ NAN_WEAK_CALLBACK_OBJECT.Clear();
}
@@ -52,12 +52,14 @@ static void casDtor(Persistent<Value> obj, void *p) {
#define CAS_ARRAY_ELEMENTS 2
Handle<Value> Cas::CreateCas(uint64_t cas) {
- Persistent<Object> ret = Persistent<Object>::New(Object::New());
+ Local<Object> ret = Object::New();
uint64_t *p = new uint64_t(cas);
ret->SetIndexedPropertiesToExternalArrayData(p,
CAS_ARRAY_MTYPE,
CAS_ARRAY_ELEMENTS);
- ret.MakeWeak(p, casDtor);
+
+ NanInitPersistent(Object, retp, ret);
+ NanMakeWeak(retp, p, casDtor);
return ret;
}
View
24 src/commandbase.cc
@@ -42,16 +42,21 @@ void KeysInfo::setKeys(Handle<Value> k)
Handle<Array> KeysInfo::getSafeKeysArray()
{
+ Handle<Value> myKeys = keys;
+ if (isPersistent) {
+ myKeys = NanPersistentToLocal(persKeys);
+ }
+
if (kcollType == ArrayKeys) {
- return keys.As<Array>()->Clone().As<Array>();
+ return myKeys.As<Array>()->Clone().As<Array>();
} else if (kcollType == ObjectKeys) {
- return keys.As<Object>()->GetPropertyNames();
+ return myKeys.As<Object>()->GetPropertyNames();
} else {
Handle<Array> ret = Array::New(1);
- if (keys.IsEmpty()) {
+ if (myKeys.IsEmpty()) {
ret->Set(0, v8::Undefined());
} else {
- ret->Set(0, keys);
+ ret->Set(0, myKeys);
}
return ret;
}
@@ -61,18 +66,15 @@ void KeysInfo::makePersistent()
{
assert(!isPersistent);
isPersistent = true;
- keys = Persistent<Value>::New(keys);
+ NanAssignPersistent(Value, persKeys, keys);
}
KeysInfo::~KeysInfo()
{
- if (keys.IsEmpty() || isPersistent == false) {
- return;
+ if (!persKeys.IsEmpty()) {
+ persKeys.Dispose();
+ persKeys.Clear();
}
-
- Persistent<Value> persist(keys);
- persist.Dispose();
- persist.Clear();
}
bool Command::handleBadString(const char *msg, char **k, size_t *n)
View
2  src/commandoptions.h
@@ -27,7 +27,7 @@ namespace Couchnode {
struct name : base \
{ \
virtual Handle<String> getName() const { \
- return NameMap::names[NameMap::fld]; \
+ return NameMap::get(NameMap::fld); \
} \
}
View
28 src/commands.h
@@ -35,7 +35,7 @@ enum ArgMode {
#define CTOR_COMMON(cls) \
- cls(const Arguments &args, int mode) : Command(args, mode) {}
+ cls(_NAN_METHOD_ARGS, int mode) : Command(args, mode) {}
class KeysInfo
@@ -48,7 +48,13 @@ class KeysInfo
unsigned int size() const { return ncmds; }
void setKeys(Handle<Value> k);
KeysType getType() const { return kcollType; }
- Handle<Value> getKeys() { return keys; }
+ Handle<Value> getKeys() {
+ if (isPersistent) {
+ return NanPersistentToLocal(persKeys);
+ } else {
+ return keys;
+ }
+ }
// Provides a "safe" keys array that is guaranteed not to be modified. This
// is potentially a fairly expensive function and should only be called on
@@ -60,6 +66,7 @@ class KeysInfo
private:
Handle<Value> keys;
+ Persistent<Value> persKeys;
KeysType kcollType;
bool isPersistent;
unsigned int ncmds;
@@ -118,7 +125,7 @@ class Command
unsigned int ix);
- Command(const Arguments& args, int cmdMode) : apiArgs(args) {
+ Command(_NAN_METHOD_ARGS, int cmdMode) : apiArgs(args) {
mode = cmdMode;
cookie = NULL;
}
@@ -164,7 +171,8 @@ class Command
void setCookieKeyOption(Handle<Value> key, Handle<Value> option);
Command(Command &other);
- const Arguments& apiArgs;
+ _NAN_METHOD_ARGS_TYPE apiArgs;
+
NAMED_OPTION(SpooledOption, BooleanOption, SPOOLED);
NAMED_OPTION(HashkeyOption, StringOption, HASHKEY);
@@ -241,8 +249,8 @@ class GetReplicaCommand : public Command
class LockCommand : public GetCommand
{
public:
- LockCommand(const Arguments& origArgs, int mode)
- : GetCommand(origArgs, mode) {
+ LockCommand(_NAN_METHOD_ARGS, int mode)
+ : GetCommand(args, mode) {
}
bool initialize() {
@@ -258,8 +266,8 @@ class LockCommand : public GetCommand
class StoreCommand : public Command
{
public:
- StoreCommand(const Arguments& origArgs, lcb_storage_t sop, int mode)
- : Command(origArgs, mode), op(sop) { }
+ StoreCommand(_NAN_METHOD_ARGS, lcb_storage_t sop, int mode)
+ : Command(args, mode), op(sop) { }
static bool handleSingle(Command*, CommandKey&,
Handle<Value>, unsigned int);
@@ -300,8 +308,8 @@ class UnlockCommand : public Command
class TouchCommand : public Command
{
public:
- TouchCommand(const Arguments& origArgs, int mode)
- : Command(origArgs, mode) { }
+ TouchCommand(_NAN_METHOD_ARGS, int mode)
+ : Command(args, mode) { }
static bool handleSingle(Command *, CommandKey&,
Handle<Value>, unsigned int);
lcb_error_t execute(lcb_t);
View
34 src/control.cc
@@ -25,9 +25,9 @@
namespace Couchnode
{
-Handle<Value> CouchbaseImpl::_Control(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::_Control)
{
- HandleScope scope;
+ NanScope();
CBExc exc;
CouchbaseImpl *me;
lcb_t instance;
@@ -37,7 +37,7 @@ Handle<Value> CouchbaseImpl::_Control(const Arguments &args)
instance = me->getLibcouchbaseHandle();
if (args.Length() < 2) {
- return exc.eArguments("Too few arguments").throwV8();
+ NanReturnValue(exc.eArguments("Too few arguments").throwV8());
}
int mode = args[0]->IntegerValue();
@@ -46,11 +46,11 @@ Handle<Value> CouchbaseImpl::_Control(const Arguments &args)
Handle<Value> optVal = args[2];
if (option != LCB_CNTL_SET && option != LCB_CNTL_GET) {
- return exc.eArguments("Invalid option mode").throwV8();
+ NanReturnValue(exc.eArguments("Invalid option mode").throwV8());
}
if (option == LCB_CNTL_SET && optVal.IsEmpty()) {
- return exc.eArguments("Valid argument missing for 'CNTL_SET'").throwV8();
+ NanReturnValue(exc.eArguments("Valid argument missing for 'CNTL_SET'").throwV8());
}
switch (mode) {
@@ -66,9 +66,9 @@ Handle<Value> CouchbaseImpl::_Control(const Arguments &args)
if (option == LCB_CNTL_GET) {
err = lcb_cntl(instance, option, mode, &tmoval);
if (err != LCB_SUCCESS) {
- return exc.eLcb(err).throwV8();
+ NanReturnValue(exc.eLcb(err).throwV8());
} else {
- return Number::New(tmoval / 1000);
+ NanReturnValue(Number::New(tmoval / 1000));
}
} else {
tmoval = optVal->NumberValue() * 1000;
@@ -85,9 +85,9 @@ Handle<Value> CouchbaseImpl::_Control(const Arguments &args)
if (option == LCB_CNTL_GET) {
err = lcb_cntl(instance, option, mode, &bufszval);
if (err != LCB_SUCCESS) {
- return exc.eLcb(err).throwV8();
+ NanReturnValue(exc.eLcb(err).throwV8());
} else {
- return scope.Close(Number::New(bufszval));
+ NanReturnValue(scope.Close(Number::New(bufszval)));
}
} else {
bufszval = optVal->Uint32Value();
@@ -105,13 +105,13 @@ Handle<Value> CouchbaseImpl::_Control(const Arguments &args)
vbi.v.v0.nkey = v.length();
err = lcb_cntl(instance, LCB_CNTL_GET, mode, &vbi);
if (err != LCB_SUCCESS) {
- return exc.eLcb(err).throwV8();
+ NanReturnValue(exc.eLcb(err).throwV8());
}
Handle<Array> arr = Array::New(2);
arr->Set(0, Integer::New(vbi.v.v0.vbucket));
arr->Set(1, Integer::New(vbi.v.v0.server_index));
- return scope.Close(arr);
+ NanReturnValue(arr);
}
case CNTL_LIBCOUCHBASE_VERSION: {
@@ -126,7 +126,7 @@ Handle<Value> CouchbaseImpl::_Control(const Arguments &args)
// Version and changeset of the headers
ret->Set(2, String::New("HDR(VERSION): "LCB_VERSION_STRING));
ret->Set(3, String::New("HDR(CHANGESET): "STRINGIFY(LCB_VERSION_CHANGESET)));
- return scope.Close(ret);
+ NanReturnValue(ret);
}
case CNTL_CLNODES: {
@@ -144,23 +144,23 @@ Handle<Value> CouchbaseImpl::_Control(const Arguments &args)
arr->Set(nItems, s);
}
- return scope.Close(arr);
+ NanReturnValue(arr);
}
case CNTL_RESTURI: {
const char *s = lcb_get_host(instance);
- return scope.Close(String::New(s));
+ NanReturnValue(String::New(s));
}
default:
- return exc.eArguments("Not supported yet").throwV8();
+ NanReturnValue(exc.eArguments("Not supported yet").throwV8());
}
if (err == LCB_SUCCESS) {
- return scope.Close(v8::True());
+ NanReturnValue(v8::True());
} else {
- return exc.eLcb(err).throwV8();
+ NanReturnValue(exc.eLcb(err).throwV8());
}
}
View
65 src/cookie.cc
@@ -28,9 +28,9 @@ Cookie::~Cookie()
parent.Clear();
}
- if (!callback.IsEmpty()) {
- callback.Dispose();
- callback.Clear();
+ if (callback) {
+ delete callback;
+ callback = NULL;
}
if (!spooledInfo.IsEmpty()) {
@@ -55,7 +55,7 @@ void Cookie::addSpooledInfo(Handle<Value>& ec, ResponseInfo& info)
info.setField(NameMap::ERR, ec);
}
- spooledInfo->ForceSet(info.getKey(), payload);
+ NanPersistentToLocal(spooledInfo)->ForceSet(info.getKey(), payload);
}
void Cookie::invokeSingleCallback(Handle<Value>& errObj, ResponseInfo& info)
@@ -66,8 +66,7 @@ void Cookie::invokeSingleCallback(Handle<Value>& errObj, ResponseInfo& info)
argc = 1;
}
- node::MakeCallback(v8::Context::GetCurrent()->Global(),
- callback, argc, args);
+ callback->Call(argc, args);
}
void Cookie::invokeSpooledCallback()
@@ -83,9 +82,8 @@ void Cookie::invokeSpooledCallback()
globalErr = v8::Undefined();
}
- Handle<Value> args[2] = { globalErr, spooledInfo };
- node::MakeCallback(v8::Context::GetCurrent()->Global(),
- callback, 2, args);
+ Handle<Value> args[2] = { globalErr, NanPersistentToLocal(spooledInfo) };
+ callback->Call(2, args);
}
bool Cookie::hasRemaining() {
@@ -139,7 +137,7 @@ void Cookie::cancel(lcb_error_t err, Handle<Array> keys)
void StatsCookie::invoke(lcb_error_t err)
{
- HandleScope scope;
+ NanScope();
Handle<Value> errObj;
if (err != LCB_SUCCESS) {
@@ -148,19 +146,19 @@ void StatsCookie::invoke(lcb_error_t err)
errObj = v8::Undefined();
}
- Handle<Value> argv[2] = { errObj, spooledInfo };
- if (spooledInfo.IsEmpty()) {
+ Local<Value> localSpooledInfo = NanPersistentToLocal(spooledInfo);
+ Handle<Value> argv[2] = { errObj, localSpooledInfo };
+ if (localSpooledInfo.IsEmpty()) {
argv[1] = Object::New();
}
- node::MakeCallback(v8::Context::GetCurrent()->Global(),
- callback, 2, argv);
+ callback->Call(2, argv);
delete this;
}
void StatsCookie::update(lcb_error_t err,
const lcb_server_stat_resp_t *resp)
{
- HandleScope scope;
+ NanScope();
if (err != LCB_SUCCESS && lastError == LCB_SUCCESS) {
lastError = err;
}
@@ -171,13 +169,14 @@ void StatsCookie::update(lcb_error_t err,
}
// Otherwise, add to the information
+ Local<Object> localSpooledInfo = NanPersistentToLocal(spooledInfo);
Handle<String> serverString = String::New(resp->v.v0.server_endpoint);
Handle<Object> serverStats;
- if (!spooledInfo->Has(serverString)) {
+ if (!localSpooledInfo->Has(serverString)) {
serverStats = Object::New();
- spooledInfo->ForceSet(serverString, serverStats);
+ localSpooledInfo->ForceSet(serverString, serverStats);
} else {
- serverStats = spooledInfo->Get(serverString).As<Object>();
+ serverStats = localSpooledInfo->Get(serverString).As<Object>();
}
Handle<String> statsKey = String::New((const char *)resp->v.v0.key,
@@ -194,7 +193,7 @@ void StatsCookie::cancel(lcb_error_t err, Handle<Array>)
void HttpCookie::update(lcb_error_t err, const lcb_http_resp_t *resp)
{
- HandleScope scope;
+ NanScope();
Handle<Value> errObj;
if (err) {
@@ -207,18 +206,17 @@ void HttpCookie::update(lcb_error_t err, const lcb_http_resp_t *resp)
if (!resp) {
// Cancellation
Handle<Value> args[] = { errObj };
- node::MakeCallback(v8::Context::GetCurrent()->Global(),
- callback, 1, args);
+ callback->Call(1, args);
delete this;
return;
}
Handle<Object> payload = Object::New();
- payload->ForceSet(NameMap::names[NameMap::HTTP_STATUS],
+ payload->ForceSet(NameMap::get(NameMap::HTTP_STATUS),
Number::New(resp->v.v0.status));
if (err != LCB_SUCCESS) {
- payload->ForceSet(NameMap::names[NameMap::ERR], errObj);
+ payload->ForceSet(NameMap::get(NameMap::ERR), errObj);
}
if (resp->v.v0.nbytes) {
@@ -228,16 +226,16 @@ void HttpCookie::update(lcb_error_t err, const lcb_http_resp_t *resp)
// binary?
body = node::Encode(resp->v.v0.bytes, resp->v.v0.nbytes);
}
- payload->ForceSet(NameMap::names[NameMap::HTTP_CONTENT], body);
+ payload->ForceSet(NameMap::get(NameMap::HTTP_CONTENT), body);
}
if (resp->v.v0.path) {
- payload->ForceSet(NameMap::names[NameMap::HTTP_PATH],
+ payload->ForceSet(NameMap::get(NameMap::HTTP_PATH),
String::New((const char *)resp->v.v0.path,
resp->v.v0.npath));
}
- Handle<Value> args[] = { errObj, payload, callback };
+ Handle<Value> args[] = { errObj, payload, callback->GetFunction() };
node::MakeCallback(v8::Context::GetCurrent()->Global(),
getGlobalRestHandler(), 3, args);
delete this;
@@ -258,11 +256,12 @@ void ObserveCookie::update(lcb_error_t err, const lcb_observe_resp_t *resp)
}
// Insert this into the keys array
- Handle<Value> kArray = spooledInfo->Get(ri.getKey());
+ Local<Object> localSpooledInfo = NanPersistentToLocal(spooledInfo);
+ Handle<Value> kArray = localSpooledInfo->Get(ri.getKey());
if (kArray->IsUndefined()) {
kArray = Array::New(1);
- spooledInfo->Set(ri.getKey(), kArray);
+ localSpooledInfo->Set(ri.getKey(), kArray);
}
kArray.As<Array>()->Set(kArray.As<Array>()->Length()-1, ri.payload);
@@ -433,6 +432,7 @@ static void get_callback(lcb_t,
Cookie *cc = getInstance(cookie);
+ NanScope();
ResponseInfo ri(error, resp, cc);
cc->markProgress(ri);
}
@@ -447,6 +447,7 @@ static void store_callback(lcb_t,
unknownLibcouchbaseType("store", resp->version);
}
+ NanScope();
ResponseInfo ri(error, resp);
getInstance(cookie)->markProgress(ri);
}
@@ -456,6 +457,7 @@ static void arithmetic_callback(lcb_t,
lcb_error_t error,
const lcb_arithmetic_resp_t *resp)
{
+ NanScope();
ResponseInfo ri(error, resp);
getInstance(cookie)->markProgress(ri);
}
@@ -471,6 +473,7 @@ static void remove_callback(lcb_t,
unknownLibcouchbaseType("remove", resp->version);
}
+ NanScope();
ResponseInfo ri(error, resp);
getInstance(cookie)->markProgress(ri);
@@ -485,6 +488,7 @@ static void touch_callback(lcb_t,
unknownLibcouchbaseType("touch", resp->version);
}
+ NanScope();
ResponseInfo ri(error, resp);
getInstance(cookie)->markProgress(ri);
}
@@ -506,6 +510,7 @@ static void unlock_callback(lcb_t,
unknownLibcouchbaseType("unlock", resp->version);
}
+ NanScope();
ResponseInfo ri(error, resp);
getInstance(cookie)->markProgress(ri);
}
@@ -515,6 +520,7 @@ static void durability_callback(lcb_t,
lcb_error_t error,
const lcb_durability_resp_t *resp)
{
+ NanScope();
ResponseInfo ri(error, resp);
getInstance(cookie)->markProgress(ri);
}
@@ -524,6 +530,7 @@ static void observe_callback(lcb_t,
lcb_error_t error,
const lcb_observe_resp_t *resp)
{
+ NanScope();
ObserveCookie *oc =
reinterpret_cast<ObserveCookie *>(
const_cast<void *>(cookie));
@@ -535,6 +542,7 @@ static void stats_callback(lcb_t,
lcb_error_t error,
const lcb_server_stat_resp_t *resp)
{
+ NanScope();
StatsCookie *sc =
reinterpret_cast<StatsCookie *>(
const_cast<void *>(cookie));
@@ -547,6 +555,7 @@ static void http_complete_callback(lcb_http_request_t,
lcb_error_t error,
const lcb_http_resp_t *resp)
{
+ NanScope();
HttpCookie *hc =
reinterpret_cast<HttpCookie *>(
const_cast<void *>(cookie));
View
27 src/cookie.h
@@ -48,7 +48,7 @@ class ResponseInfo {
bool hasKey() { return key != NULL && nkey > 0; }
void setField(NameMap::dict_t name, Handle<Value> val) {
- payload->ForceSet(NameMap::names[name], val);
+ payload->ForceSet(NameMap::get(name), val);
}
void setError(lcb_error_t err) {
@@ -70,7 +70,7 @@ class ResponseInfo {
const void *key;
size_t nkey;
- HandleScope scope;
+ //HandleScope scope;
Handle<Value> keyObj;
private:
@@ -90,12 +90,13 @@ class Cookie
{
public:
Cookie(unsigned int numRemaining)
- : hasError(false), cbType(CBMODE_SINGLE), remaining(numRemaining),
- isCancelled(false) {}
+ : callback(NULL), hasError(false), cbType(CBMODE_SINGLE),
+ remaining(numRemaining), isCancelled(false) {}
void setCallback(Handle<Function> cb, CallbackMode mode) {
- assert(callback.IsEmpty());
- callback = Persistent<Function>::New(cb);
+ assert(callback == NULL);
+
+ callback = new NanCallback(cb);
cbType = mode;
if (cbType == CBMODE_SPOOLED) {
@@ -105,12 +106,12 @@ class Cookie
void setParent(v8::Handle<v8::Value> cbo) {
assert(parent.IsEmpty());
- parent = v8::Persistent<v8::Value>::New(cbo);
+ NanAssignPersistent(v8::Value, parent, cbo);
}
void setOptions(Handle<Object> options) {
assert(keyOptions.IsEmpty());
- keyOptions = Persistent<Object>::New(options);
+ NanAssignPersistent(Object, keyOptions, options);
}
virtual ~Cookie();
@@ -121,7 +122,8 @@ class Cookie
if (keyOptions.IsEmpty()) {
return Handle<Value>(); // null
}
- return keyOptions->GetRealNamedProperty(key.As<String>());
+ Local<Object> localKeyOptions = NanPersistentToLocal(keyOptions);
+ return localKeyOptions->GetRealNamedProperty(key.As<String>());
}
bool hasKeyOptions() const {
@@ -134,11 +136,11 @@ class Cookie
// Processed a single command
bool hasRemaining();
- Persistent<Function> callback;
+ NanCallback *callback;
void initSpooledInfo() {
if (spooledInfo.IsEmpty()) {
- spooledInfo = Persistent<Object>::New(Object::New());
+ NanAssignPersistent(Object, spooledInfo, Object::New());
}
}
@@ -186,8 +188,9 @@ class HttpCookie : public Cookie
private:
inline Local<Function> getGlobalRestHandler() {
+ Local<Value> localParent = NanPersistentToLocal(parent);
return Local<Function>::Cast(
- parent->ToObject()->Get(NameMap::get(NameMap::RESTHANDLER)));
+ localParent->ToObject()->Get(NameMap::get(NameMap::RESTHANDLER)));
}
};
View
211 src/couchbase_impl.cc
@@ -45,7 +45,7 @@ unsigned int CouchbaseImpl::objectCount;
#endif
-static Handle<Value> bailOut(const Arguments &args, CBExc &ex)
+static Handle<Value> bailOut(_NAN_METHOD_ARGS, CBExc &ex)
{
Handle<Function> cb;
if (args.Length()) {
@@ -89,9 +89,9 @@ CouchbaseImpl::~CouchbaseImpl()
EventMap::iterator iter = events.begin();
while (iter != events.end()) {
- if (!iter->second.IsEmpty()) {
- iter->second.Dispose();
- iter->second.Clear();
+ if (iter->second) {
+ delete iter->second;
+ iter->second = NULL;
}
++iter;
}
@@ -99,56 +99,55 @@ CouchbaseImpl::~CouchbaseImpl()
void CouchbaseImpl::Init(Handle<Object> target)
{
- HandleScope scope;
+ NanScope();
Local<FunctionTemplate> t = FunctionTemplate::New(New);
- Persistent<FunctionTemplate> s_ct;
- s_ct = Persistent<FunctionTemplate>::New(t);
- s_ct->InstanceTemplate()->SetInternalFieldCount(1);
- s_ct->SetClassName(String::NewSymbol("CouchbaseImpl"));
-
- NODE_SET_PROTOTYPE_METHOD(s_ct, "strError", StrError);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "on", On);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "shutdown", Shutdown);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "setMulti", SetMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "addMulti", AddMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "replaceMulti", ReplaceMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "appendMulti", AppendMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "prependMulti", PrependMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "getMulti", GetMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "getReplicaMulti", GetReplicaMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "touchMulti", TouchMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "lockMulti", LockMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "unlockMulti", UnlockMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "arithmeticMulti", ArithmeticMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "removeMulti", RemoveMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "deleteMulti", RemoveMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "observeMulti", ObserveMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "endureMulti", EndureMulti);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "stats", Stats);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "httpRequest", HttpRequest);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "_control", _Control);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "_connect", Connect);
- target->Set(String::NewSymbol("CouchbaseImpl"), s_ct->GetFunction());
+ //NanInitPersistent(FunctionTemplate, s_ct, t);
+ t->InstanceTemplate()->SetInternalFieldCount(1);
+ t->SetClassName(String::NewSymbol("CouchbaseImpl"));
+
+ NODE_SET_PROTOTYPE_METHOD(t, "strError", StrError);
+ NODE_SET_PROTOTYPE_METHOD(t, "on", On);
+ NODE_SET_PROTOTYPE_METHOD(t, "shutdown", Shutdown);
+ NODE_SET_PROTOTYPE_METHOD(t, "setMulti", SetMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "addMulti", AddMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "replaceMulti", ReplaceMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "appendMulti", AppendMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "prependMulti", PrependMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "getMulti", GetMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "getReplicaMulti", GetReplicaMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "touchMulti", TouchMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "lockMulti", LockMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "unlockMulti", UnlockMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "arithmeticMulti", ArithmeticMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "removeMulti", RemoveMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "deleteMulti", RemoveMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "observeMulti", ObserveMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "endureMulti", EndureMulti);
+ NODE_SET_PROTOTYPE_METHOD(t, "stats", Stats);
+ NODE_SET_PROTOTYPE_METHOD(t, "httpRequest", HttpRequest);
+ NODE_SET_PROTOTYPE_METHOD(t, "_control", _Control);
+ NODE_SET_PROTOTYPE_METHOD(t, "_connect", Connect);
+ target->Set(String::NewSymbol("CouchbaseImpl"), t->GetFunction());
target->Set(String::NewSymbol("Constants"), createConstants());
NameMap::initialize();
ValueFormat::initialize();
}
-Handle<Value> CouchbaseImpl::On(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::On)
{
CouchbaseImpl *me = ObjectWrap::Unwrap<CouchbaseImpl>(args.This());
return me->on(args);
}
-Handle<Value> CouchbaseImpl::on(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::on)
{
- HandleScope scope;
+ NanScope();
CBExc ex;
if (args.Length() != 2) {
- return ex.eArguments("Need event and callback").throwV8();
+ NanReturnValue(ex.eArguments("Need event and callback").throwV8());
}
Handle<Value> cbName = args[0];
@@ -156,37 +155,37 @@ Handle<Value> CouchbaseImpl::on(const Arguments &args)
String::AsciiValue func(cbName);
if (func.length() == 0) {
- return ex.eArguments("Bad callback parameter", cbName).throwV8();
+ NanReturnValue(ex.eArguments("Bad callback parameter", cbName).throwV8());
}
if (!cbTarget->IsFunction()) {
- return ex.eArguments("Parameter is not a function", cbTarget).throwV8();
+ NanReturnValue(ex.eArguments("Parameter is not a function", cbTarget).throwV8());
}
EventMap::iterator iter = events.find(*func);
if (iter != events.end()) {
- if (!iter->second.IsEmpty()) {
- iter->second.Dispose();
- iter->second.Clear();
+ if (iter->second) {
+ delete iter->second;
+ iter->second = NULL;
}
events.erase(iter);
}
- events[*func] = Persistent<Function>::New(cbTarget.As<Function>());
- return scope.Close(True());
+ events[*func] = new NanCallback(cbTarget.As<Function>());
+ NanReturnValue(True());
}
-Handle<Value> CouchbaseImpl::New(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::New)
{
- HandleScope scope;
+ NanScope();
CBExc exc;
if (args.Length() < 1) {
- return exc.eArguments("Need a URI").throwV8();
+ NanReturnValue(exc.eArguments("Need a URI").throwV8());
}
if (args.Length() > 4) {
- return exc.eArguments("Too many arguments").throwV8();
+ NanReturnValue(exc.eArguments("Too many arguments").throwV8());
}
std::string argv[4];
@@ -200,7 +199,7 @@ Handle<Value> CouchbaseImpl::New(const Arguments &args)
} else if (arg->IsNull() || arg->IsUndefined()) {
continue;
} else {
- return exc.eArguments("Incorrect argument", args[ii]).throwV8();
+ NanReturnValue(exc.eArguments("Incorrect argument", args[ii]).throwV8());
}
}
@@ -214,7 +213,7 @@ Handle<Value> CouchbaseImpl::New(const Arguments &args)
err = lcb_create_libuv_io_opts(0, &iops, &iopsOptions);
if (iops == NULL) {
- return exc.eLcb(err).throwV8();
+ NanReturnValue(exc.eLcb(err).throwV8());
}
lcb_create_st createOptions(argv[0].c_str(),
@@ -227,38 +226,38 @@ Handle<Value> CouchbaseImpl::New(const Arguments &args)
err = lcb_create(&instance, &createOptions);
if (err != LCB_SUCCESS) {
- return exc.eLcb(err).throwV8();
+ NanReturnValue(exc.eLcb(err).throwV8());
}
CouchbaseImpl *hw = new CouchbaseImpl(instance);
hw->Wrap(args.This());
- return args.This();
+ NanReturnValue(args.This());
}
-Handle<Value> CouchbaseImpl::Connect(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::Connect)
{
- HandleScope scope;
+ NanScope();
CouchbaseImpl *me = ObjectWrap::Unwrap<CouchbaseImpl>(args.This());
lcb_error_t ec = lcb_connect(me->getLibcouchbaseHandle());
if (ec != LCB_SUCCESS) {
- return CBExc().eLcb(ec).throwV8();
+ NanReturnValue(CBExc().eLcb(ec).throwV8());
}
- return scope.Close(True());
+ NanReturnValue(True());
}
-Handle<Value> CouchbaseImpl::StrError(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::StrError)
{
- HandleScope scope;
+ NanScope();
if (args.Length() != 1) {
- return CBExc().eArguments("Method takes a single parameter").throwV8();
+ NanReturnValue(CBExc().eArguments("Method takes a single parameter").throwV8());
}
Handle<Value> errObj = args[0]->ToInt32();
if (errObj.IsEmpty()) {
- return CBExc().eArguments("Couldn't convert to number", args[0]).throwV8();
+ NanReturnValue(CBExc().eArguments("Couldn't convert to number", args[0]).throwV8());
}
- return scope.Close(String::NewSymbol(lcb_strerror(NULL,
+ NanReturnValue(String::NewSymbol(lcb_strerror(NULL,
(lcb_error_t)errObj->IntegerValue())));
}
@@ -270,7 +269,7 @@ void CouchbaseImpl::onConnect(lcb_error_t err)
}
connected = true;
- HandleScope scope;
+ NanScope();
Handle<Value> errObj;
if (err != LCB_SUCCESS) {
@@ -280,12 +279,11 @@ void CouchbaseImpl::onConnect(lcb_error_t err)
}
EventMap::iterator iter = events.find("connect");
- if (iter == events.end() || iter->second.IsEmpty()) {
+ if (iter == events.end() || !iter->second) {
return;
}
- node::MakeCallback(v8::Context::GetCurrent()->Global(),
- iter->second, 1, &errObj);
+ iter->second->Call(1, &errObj);
}
void CouchbaseImpl::errorCallback(lcb_error_t err, const char *errinfo)
@@ -296,19 +294,18 @@ void CouchbaseImpl::errorCallback(lcb_error_t err, const char *errinfo)
}
EventMap::iterator iter = events.find("error");
- if (iter == events.end() || iter->second.IsEmpty()) {
+ if (iter == events.end() || !iter->second) {
return;
}
- HandleScope scope;
+ NanScope();
CBExc ex;
ex.eLcb(err);
if (errinfo) {
ex.setMessage(errinfo);
}
Handle<Value> exObj = ex.asValue();
- node::MakeCallback(v8::Context::GetCurrent()->Global(),
- iter->second, 1, &exObj);
+ iter->second->Call(1, &exObj);
return;
}
@@ -350,9 +347,9 @@ void CouchbaseImpl::runScheduledOperations(lcb_error_t globalerr)
// static
template <typename T>
-Handle<Value> CouchbaseImpl::makeOperation(const Arguments &args, T &op)
+Handle<Value> CouchbaseImpl::makeOperation(_NAN_METHOD_ARGS, T &op)
{
- HandleScope scope;
+ NanScope();
CouchbaseImpl *me = ObjectWrap::Unwrap<CouchbaseImpl>(args.This());
if (!op.initialize()) {
@@ -391,10 +388,11 @@ Handle<Value> CouchbaseImpl::makeOperation(const Arguments &args, T &op)
******************************************/
#define DEFINE_STOREOP(name, mode) \
-Handle<Value> CouchbaseImpl::name##Multi(const Arguments &args) \
+NAN_METHOD(CouchbaseImpl::name##Multi) \
{ \
+ NanScope(); \
StoreCommand op(args, mode, ARGMODE_MULTI); \
- return makeOperation(args, op); \
+ NanReturnValue(makeOperation(args, op)); \
}
DEFINE_STOREOP(Set, LCB_SET)
@@ -403,78 +401,89 @@ DEFINE_STOREOP(Replace, LCB_REPLACE)
DEFINE_STOREOP(Append, LCB_APPEND)
DEFINE_STOREOP(Prepend, LCB_PREPEND)
-Handle<Value> CouchbaseImpl::GetMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::GetMulti)
{
+ NanScope();
GetCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::GetReplicaMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::GetReplicaMulti)
{
+ NanScope();
GetReplicaCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::LockMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::LockMulti)
{
+ NanScope();
LockCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::UnlockMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::UnlockMulti)
{
+ NanScope();
UnlockCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::TouchMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::TouchMulti)
{
+ NanScope();
TouchCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::ArithmeticMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::ArithmeticMulti)
{
+ NanScope();
ArithmeticCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::RemoveMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::RemoveMulti)
{
+ NanScope();
DeleteCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::ObserveMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::ObserveMulti)
{
+ NanScope();
ObserveCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::EndureMulti(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::EndureMulti)
{
+ NanScope();
EndureCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::Stats(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::Stats)
{
+ NanScope();
StatsCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::HttpRequest(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::HttpRequest)
{
+ NanScope();
HttpCommand op(args, ARGMODE_MULTI);
- return makeOperation(args, op);
+ NanReturnValue(makeOperation(args, op));
}
-Handle<Value> CouchbaseImpl::Shutdown(const Arguments &args)
+NAN_METHOD(CouchbaseImpl::Shutdown)
{
- HandleScope scope;
+ NanScope();
CouchbaseImpl *me = ObjectWrap::Unwrap<CouchbaseImpl>(args.This());
me->shutdown();
- return scope.Close(True());
+ NanReturnValue(True());
}
extern "C" {
@@ -508,10 +517,4 @@ void CouchbaseImpl::shutdown(void)
void CouchbaseImpl::dumpMemoryInfo(const std::string& mark="")
{
- HeapStatistics stats;
- return;
-
- V8::GetHeapStatistics(&stats);
- printf("%-20s: HEAP: Used %lu/%lu\n", mark.c_str(), stats.used_heap_size(),
- stats.total_heap_size());
}
View
68 src/couchbase_impl.h
@@ -37,6 +37,7 @@
#endif
#include <node.h>
+#include "nan.h"
#if __GNUC__
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
@@ -53,7 +54,6 @@ using v8::HandleScope;
using v8::String;
using v8::Number;
using v8::Object;
-using v8::Arguments;
};
#include <iostream>
@@ -87,7 +87,6 @@ using v8::HandleScope;
using v8::String;
using v8::Number;
using v8::Object;
-using v8::Arguments;
// These codes *should* be in lcb_cntl, but currently aren't.
enum ControlCode {
@@ -106,41 +105,42 @@ class CouchbaseImpl: public node::ObjectWrap
// Methods called directly from JavaScript
static void Init(Handle<Object> target);
- static Handle<Value> New(const Arguments &args);
- static Handle<Value> StrError(const Arguments &args);
- static Handle<Value> SetHandler(const Arguments &);
-
- static Handle<Value> GetLastError(const Arguments &);
- static Handle<Value> GetMulti(const Arguments &);
- static Handle<Value> GetReplicaMulti(const Arguments &);
- static Handle<Value> LockMulti(const Arguments &);
- static Handle<Value> SetMulti(const Arguments &);
- static Handle<Value> ReplaceMulti(const Arguments &);
- static Handle<Value> AddMulti(const Arguments &);
- static Handle<Value> AppendMulti(const Arguments &);
- static Handle<Value> PrependMulti(const Arguments &);
- static Handle<Value> RemoveMulti(const Arguments &);
- static Handle<Value> ArithmeticMulti(const Arguments &);
- static Handle<Value> TouchMulti(const Arguments &);
- static Handle<Value> UnlockMulti(const Arguments &);
- static Handle<Value> ObserveMulti(const Arguments &);
- static Handle<Value> EndureMulti(const Arguments &);
- static Handle<Value> Stats(const Arguments &);
- static Handle<Value> View(const Arguments &);
- static Handle<Value> Shutdown(const Arguments &);
- static Handle<Value> HttpRequest(const Arguments &);
- static Handle<Value> _Control(const Arguments &);
- static Handle<Value> Connect(const Arguments &);
+
+ static NAN_METHOD(New);
+ static NAN_METHOD(StrError);
+ static NAN_METHOD(SetHandler);
+
+ static NAN_METHOD(GetLastError);
+ static NAN_METHOD(GetMulti);
+ static NAN_METHOD(GetReplicaMulti);
+ static NAN_METHOD(LockMulti);
+ static NAN_METHOD(SetMulti);
+ static NAN_METHOD(ReplaceMulti);
+ static NAN_METHOD(AddMulti);
+ static NAN_METHOD(AppendMulti);
+ static NAN_METHOD(PrependMulti);
+ static NAN_METHOD(RemoveMulti);
+ static NAN_METHOD(ArithmeticMulti);
+ static NAN_METHOD(TouchMulti);
+ static NAN_METHOD(UnlockMulti);
+ static NAN_METHOD(ObserveMulti);
+ static NAN_METHOD(EndureMulti);
+ static NAN_METHOD(Stats);
+ static NAN_METHOD(View);
+ static NAN_METHOD(Shutdown);
+ static NAN_METHOD(HttpRequest);
+ static NAN_METHOD(_Control);
+ static NAN_METHOD(Connect);
// Design Doc Management
- static Handle<Value> GetDesignDoc(const Arguments &);
- static Handle<Value> SetDesignDoc(const Arguments &);
- static Handle<Value> DeleteDesignDoc(const Arguments &);
+ static NAN_METHOD(GetDesignDoc);
+ static NAN_METHOD(SetDesignDoc);
+ static NAN_METHOD(DeleteDesignDoc);
// Setting up the event emitter
- static Handle<Value> On(const Arguments &);
- Handle<Value> on(const Arguments &);
+ static NAN_METHOD(On);
+ NAN_METHOD(on);
// Method called from libcouchbase
void onConfig(lcb_configuration_t config);
@@ -171,7 +171,7 @@ class CouchbaseImpl: public node::ObjectWrap
lcb_t instance;
lcb_error_t lastError;
- typedef std::map<std::string, Persistent<Function> > EventMap;
+ typedef std::map<std::string, NanCallback* > EventMap;
EventMap events;
Persistent<Function> connectHandler;
std::queue<Command *> pendingCommands;
@@ -181,7 +181,7 @@ class CouchbaseImpl: public node::ObjectWrap
#endif
private:
template <class T>
- static Handle<Value> makeOperation(const Arguments&, T&);
+ static Handle<Value> makeOperation(_NAN_METHOD_ARGS, T&);
bool isShutdown;
};
View
7 src/exception.cc
@@ -40,7 +40,7 @@ void CBExc::setMessage(const std::string &msg, const Handle<Value> value)
}
if (!value.IsEmpty()) {
obj_set_ = true;
- atObject = Persistent<Value>::New(value);
+ NanAssignPersistent(Value, atObject, value);
}
}
@@ -73,9 +73,10 @@ Handle<Value> CBExc::asValue()
}
Handle<Value> e = Exception::Error(omsg);
Handle<Object> obj = e->ToObject();
- obj->Set(NameMap::names[NameMap::EXC_CODE], Number::New(code));
+ obj->Set(NameMap::get(NameMap::EXC_CODE), Number::New(code));
if (!atObject.IsEmpty()) {
- obj->Set(String::NewSymbol("at"), atObject);
+ Local<Value> localAtObject = NanPersistentToLocal(atObject);
+ obj->Set(String::NewSymbol("at"), localAtObject);
}
return e;
}
View
2  src/namemap.cc
@@ -78,5 +78,5 @@ void NameMap::initialize()
void NameMap::install(const char *name, dict_t val)
{
using namespace v8;
- names[val] = Persistent<String>::New(String::NewSymbol(name, strlen(name)));
+ NanAssignPersistent(String, names[val], String::NewSymbol(name, strlen(name)));
}
View
4 src/namemap.h
@@ -83,8 +83,8 @@ namespace Couchnode
} dict_t;
static v8::Persistent<v8::String> names[MAX];
static void initialize();
- static Handle<Value> get(dict_t ix) {
- return names[ix];
+ static Handle<String> get(dict_t ix) {
+ return NanPersistentToLocal(names[ix]);
}
protected:
static void install(const char *name, dict_t val);
View
12 src/options.h
@@ -95,7 +95,7 @@ struct CasSlot : ParamSlot
lcb_cas_t v;
CasSlot() : v(0) {}
virtual Handle<String> getName() const {
- return NameMap::names[NameMap::CAS];
+ return NameMap::get(NameMap::CAS);
}
ParseStatus parseValue(const Handle<Value>, CBExc &);
@@ -104,28 +104,28 @@ struct CasSlot : ParamSlot
struct ExpOption : UInt32Option
{
virtual Handle<String> getName() const {
- return NameMap::names[NameMap::EXPIRY];
+ return NameMap::get(NameMap::EXPIRY);
}
};
struct LockOption : ExpOption
{
virtual Handle<String> getName() const {
- return NameMap::names[NameMap::LOCKTIME];
+ return NameMap::get(NameMap::LOCKTIME);
}
};
struct FlagsOption : UInt32Option
{
virtual Handle<String> getName() const {
- return NameMap::names[NameMap::FLAGS];
+ return NameMap::get(NameMap::FLAGS);
}
};
struct IndexOption : Int32Option
{
virtual Handle<String> getName() const {
- return NameMap::names[NameMap::INDEX];
+ return NameMap::get(NameMap::INDEX);
}
};
@@ -169,7 +169,7 @@ struct StringOption : ParamSlot
struct KeyOption : StringOption
{
virtual Handle<String> getName() const {
- return NameMap::names[NameMap::KEY];
+ return NameMap::get(NameMap::KEY);
}
};
View
18 src/valueformat.cc
@@ -23,16 +23,15 @@ Persistent<Function> ValueFormat::jsonStringify;
void ValueFormat::initialize()
{
- HandleScope scope;
+ NanScope();
Handle<Object> jMod = v8::Context::GetEntered()->Global()->Get(
String::NewSymbol("JSON")).As<Object>();
assert(!jMod.IsEmpty());
-
- jsonParse = Persistent<Function>::New(
+ NanAssignPersistent(Function, jsonParse,
jMod->Get(String::NewSymbol("parse")).As<Function>());
- jsonStringify = Persistent<Function>::New(jMod->Get(
- String::NewSymbol("stringify")).As<Function>());
+ NanAssignPersistent(Function, jsonStringify,
+ jMod->Get(String::NewSymbol("stringify")).As<Function>());
assert(!jsonParse.IsEmpty());
assert(!jsonStringify.IsEmpty());
@@ -46,13 +45,13 @@ Handle<Value> ValueFormat::decode(const char *bytes, size_t n,
} else if (flags == RAW) {
// 0.8 defines this as char*, hence the cast
- node::Buffer *buf = node::Buffer::New(const_cast<char*>(bytes), n);
- return buf->handle_;
+ return NanNewBufferHandle(const_cast<char*>(bytes), n);
} else if (flags == JSON) {
Handle<Value> s = decode(bytes, n, UTF8);
v8::TryCatch try_catch;
- Handle<Value> ret = jsonParse->Call(
+ Local<Function> jsonParseLcl = NanPersistentToLocal(jsonParse);
+ Handle<Value> ret = jsonParseLcl->Call(
v8::Context::GetEntered()->Global(), 1, &s);
if (try_catch.HasCaught()) {
return decode(bytes, n, RAW);
@@ -174,7 +173,8 @@ bool ValueFormat::encode(Handle<Value> input,
} else if (spec == JSON) {
v8::TryCatch try_catch;
- Handle<Value> ret = jsonStringify->Call(
+ Local<Function> jsonStringifyLcl = NanPersistentToLocal(jsonStringify);
+ Handle<Value> ret = jsonStringifyLcl->Call(
v8::Context::GetEntered()->Global(), 1, &input);
if (try_catch.HasCaught()) {

2 comments on commit 0beb117

@zachaller

just wanted to say super awesome and thank you for this, I can now start pushing our company to start using couchbase

@brett19
Owner

Glad to hear it!

Please sign in to comment.
Something went wrong with that request. Please try again.