Skip to content

Commit

Permalink
V8 upgrade requiring isolate argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Mar 20, 2013
1 parent 6889703 commit cc48eef
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void AsyncWorker::WorkComplete () {
HandleOKCallback();
else
HandleErrorCallback();
callback.Dispose();
callback.Dispose(LD_NODE_ISOLATE);
}

void AsyncWorker::HandleOKCallback () {
Expand Down
19 changes: 14 additions & 5 deletions src/batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Batch::~Batch () {
for (std::vector< v8::Persistent<v8::Value> >::iterator it = references->begin()
; it != references->end()
; ) {
it->Dispose();
it->Dispose(LD_NODE_ISOLATE);
it = references->erase(it);
}
delete references;
Expand Down Expand Up @@ -52,7 +52,9 @@ void Batch::Init () {
v8::String::NewSymbol("write")
, v8::FunctionTemplate::New(Batch::Write)->GetFunction()
);
constructor = v8::Persistent<v8::Function>::New(tpl->GetFunction());
constructor = v8::Persistent<v8::Function>::New(
LD_NODE_ISOLATE_PRE
tpl->GetFunction());
}

v8::Handle<v8::Value> Batch::New (const v8::Arguments& args) {
Expand Down Expand Up @@ -107,9 +109,13 @@ v8::Handle<v8::Value> Batch::Put (const v8::Arguments& args) {
LD_STRING_OR_BUFFER_TO_SLICE(value, valueBuffer, value)

if (node::Buffer::HasInstance(keyBuffer->ToObject()))
batch->references->push_back(v8::Persistent<v8::Value>::New(keyBuffer));
batch->references->push_back(v8::Persistent<v8::Value>::New(
LD_NODE_ISOLATE_PRE
keyBuffer));
if (node::Buffer::HasInstance(valueBuffer->ToObject()))
batch->references->push_back(v8::Persistent<v8::Value>::New(valueBuffer));
batch->references->push_back(v8::Persistent<v8::Value>::New(
LD_NODE_ISOLATE_PRE
valueBuffer));

batch->batch->Put(key, value);

Expand All @@ -128,7 +134,9 @@ v8::Handle<v8::Value> Batch::Del (const v8::Arguments& args) {
LD_STRING_OR_BUFFER_TO_SLICE(key, keyBuffer, key)

if (node::Buffer::HasInstance(keyBuffer->ToObject()))
batch->references->push_back(v8::Persistent<v8::Value>::New(keyBuffer));
batch->references->push_back(v8::Persistent<v8::Value>::New(
LD_NODE_ISOLATE_PRE
keyBuffer));

batch->batch->Delete(key);

Expand All @@ -152,6 +160,7 @@ v8::Handle<v8::Value> Batch::Write (const v8::Arguments& args) {
LD_THROW_RETURN(name() requires a callback argument)
}
v8::Persistent<v8::Function> callback = v8::Persistent<v8::Function>::New(
LD_NODE_ISOLATE_PRE
v8::Local<v8::Function>::Cast(args[0]));

BatchWriteWorker* worker = new BatchWriteWorker(batch, callback);
Expand Down
30 changes: 20 additions & 10 deletions src/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ void Database::Init () {
v8::String::NewSymbol("iterator")
, v8::FunctionTemplate::New(Iterator)->GetFunction()
);
constructor = v8::Persistent<v8::Function>::New(tpl->GetFunction());
constructor = v8::Persistent<v8::Function>::New(
LD_NODE_ISOLATE_PRE
tpl->GetFunction());
}

v8::Handle<v8::Value> Database::New (const v8::Arguments& args) {
Expand Down Expand Up @@ -224,9 +226,9 @@ v8::Handle<v8::Value> Database::Put (const v8::Arguments& args) {
LD_STRING_OR_BUFFER_TO_SLICE(value, valueBufferV, value)

v8::Persistent<v8::Value> keyBuffer =
v8::Persistent<v8::Value>::New(keyBufferV);
v8::Persistent<v8::Value>::New(LD_NODE_ISOLATE_PRE keyBufferV);
v8::Persistent<v8::Value> valueBuffer =
v8::Persistent<v8::Value>::New(valueBufferV);
v8::Persistent<v8::Value>::New(LD_NODE_ISOLATE_PRE valueBufferV);

LD_BOOLEAN_OPTION_VALUE(optionsObj, sync)

Expand Down Expand Up @@ -254,7 +256,9 @@ v8::Handle<v8::Value> Database::Get (const v8::Arguments& args) {
v8::Local<v8::Value> keyBufferV = args[0];
LD_STRING_OR_BUFFER_TO_SLICE(key, keyBufferV, key)

v8::Persistent<v8::Value> keyBuffer = v8::Persistent<v8::Value>::New(keyBufferV);
v8::Persistent<v8::Value> keyBuffer = v8::Persistent<v8::Value>::New(
LD_NODE_ISOLATE_PRE
keyBufferV);

LD_BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, asBuffer)
LD_BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, fillCache)
Expand Down Expand Up @@ -283,7 +287,7 @@ v8::Handle<v8::Value> Database::Delete (const v8::Arguments& args) {
LD_STRING_OR_BUFFER_TO_SLICE(key, keyBufferV, key)

v8::Persistent<v8::Value> keyBuffer =
v8::Persistent<v8::Value>::New(keyBufferV);
v8::Persistent<v8::Value>::New(LD_NODE_ISOLATE_PRE keyBufferV);

LD_BOOLEAN_OPTION_VALUE(optionsObj, sync)

Expand Down Expand Up @@ -343,7 +347,9 @@ v8::Handle<v8::Value> Database::Batch (const v8::Arguments& args) {

batch->Delete(key);
if (node::Buffer::HasInstance(keyBuffer->ToObject()))
references->push_back(v8::Persistent<v8::Value>::New(keyBuffer));
references->push_back(v8::Persistent<v8::Value>::New(
LD_NODE_ISOLATE_PRE
keyBuffer));
} else if (obj->Get(str_type)->StrictEquals(str_put)) {
v8::Local<v8::Value> valueBuffer = obj->Get(str_value);
LD_CB_ERR_IF_NULL_OR_UNDEFINED(valueBuffer, value)
Expand All @@ -353,9 +359,13 @@ v8::Handle<v8::Value> Database::Batch (const v8::Arguments& args) {

batch->Put(key, value);
if (node::Buffer::HasInstance(keyBuffer->ToObject()))
references->push_back(v8::Persistent<v8::Value>::New(keyBuffer));
references->push_back(v8::Persistent<v8::Value>::New(
LD_NODE_ISOLATE_PRE
keyBuffer));
if (node::Buffer::HasInstance(valueBuffer->ToObject()))
references->push_back(v8::Persistent<v8::Value>::New(valueBuffer));
references->push_back(v8::Persistent<v8::Value>::New(
LD_NODE_ISOLATE_PRE
valueBuffer));
}
}

Expand Down Expand Up @@ -395,9 +405,9 @@ v8::Handle<v8::Value> Database::ApproximateSize (const v8::Arguments& args) {
LD_STRING_OR_BUFFER_TO_SLICE(end, endBufferV, end)

v8::Persistent<v8::Value> startBuffer =
v8::Persistent<v8::Value>::New(startBufferV);
v8::Persistent<v8::Value>::New(LD_NODE_ISOLATE_PRE startBufferV);
v8::Persistent<v8::Value> endBuffer =
v8::Persistent<v8::Value>::New(endBufferV);
v8::Persistent<v8::Value>::New(LD_NODE_ISOLATE_PRE endBufferV);

ApproximateSizeWorker* worker = new ApproximateSizeWorker(
database
Expand Down
12 changes: 6 additions & 6 deletions src/database_async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void CloseWorker::Execute () {
void CloseWorker::WorkComplete () {
v8::HandleScope scope;
HandleOKCallback();
callback.Dispose();
callback.Dispose(LD_NODE_ISOLATE);
}

/** IO WORKER (abstract) **/
Expand All @@ -77,7 +77,7 @@ IOWorker::~IOWorker () {}

void IOWorker::WorkComplete () {
AsyncWorker::WorkComplete();
keyPtr.Dispose();
keyPtr.Dispose(LD_NODE_ISOLATE);
}

/** READ WORKER **/
Expand Down Expand Up @@ -164,7 +164,7 @@ void WriteWorker::Execute () {

void WriteWorker::WorkComplete () {
IOWorker::WorkComplete();
valuePtr.Dispose();
valuePtr.Dispose(LD_NODE_ISOLATE);
}

/** BATCH WORKER **/
Expand All @@ -187,7 +187,7 @@ BatchWorker::~BatchWorker () {
for (std::vector< v8::Persistent<v8::Value> >::iterator it = references->begin()
; it != references->end()
; ) {
it->Dispose();
it->Dispose(LD_NODE_ISOLATE);
it = references->erase(it);
}
delete references;
Expand Down Expand Up @@ -221,8 +221,8 @@ void ApproximateSizeWorker::Execute () {

void ApproximateSizeWorker::WorkComplete() {
AsyncWorker::WorkComplete();
startPtr.Dispose();
endPtr.Dispose();
startPtr.Dispose(LD_NODE_ISOLATE);
endPtr.Dispose(LD_NODE_ISOLATE);
}

void ApproximateSizeWorker::HandleOKCallback () {
Expand Down
16 changes: 11 additions & 5 deletions src/iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Iterator::Iterator (

Iterator::~Iterator () {
delete options;
startPtr.Dispose();
startPtr.Dispose(LD_NODE_ISOLATE);
if (start != NULL)
delete start;
if (end != NULL)
Expand Down Expand Up @@ -130,7 +130,9 @@ v8::Handle<v8::Value> Iterator::Next (const v8::Arguments& args) {
}

v8::Persistent<v8::Function> callback =
v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[0]));
v8::Persistent<v8::Function>::New(
LD_NODE_ISOLATE_PRE
v8::Local<v8::Function>::Cast(args[0]));

NextWorker* worker = new NextWorker(
iterator
Expand All @@ -156,7 +158,9 @@ v8::Handle<v8::Value> Iterator::End (const v8::Arguments& args) {
}

v8::Persistent<v8::Function> callback =
v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[0]));
v8::Persistent<v8::Function>::New(
LD_NODE_ISOLATE_PRE
v8::Local<v8::Function>::Cast(args[0]));

EndWorker* worker = new EndWorker(
iterator
Expand Down Expand Up @@ -188,7 +192,9 @@ void Iterator::Init () {
v8::String::NewSymbol("end")
, v8::FunctionTemplate::New(End)->GetFunction()
);
constructor = v8::Persistent<v8::Function>::New(tpl->GetFunction());
constructor = v8::Persistent<v8::Function>::New(
LD_NODE_ISOLATE_PRE
tpl->GetFunction());
}

v8::Handle<v8::Value> Iterator::NewInstance (
Expand Down Expand Up @@ -271,7 +277,7 @@ v8::Handle<v8::Value> Iterator::New (const v8::Arguments& args) {
, fillCache
, keyAsBuffer
, valueAsBuffer
, v8::Persistent<v8::Value>::New(startBuffer)
, v8::Persistent<v8::Value>::New(LD_NODE_ISOLATE_PRE startBuffer)
);
iterator->Wrap(args.This());

Expand Down
16 changes: 15 additions & 1 deletion src/leveldown.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
#ifndef LD_LEVELDOWN_H
#define LD_LEVELDOWN_H

// node_isolate stuff introduced with V8 upgrade, see https://github.com/joyent/node/pull/5077
#if NODE_MODULE_VERSION > 0x000B
# define LD_NODE_ISOLATE node::node_isolate
# define LD_NODE_ISOLATE_PRE node::node_isolate,
# define LD_NODE_ISOLATE_POST , node::node_isolate
#else
# define LD_NODE_ISOLATE
# define LD_NODE_ISOLATE_PRE
# define LD_NODE_ISOLATE_POST
#endif

#define LD_SYMBOL(var, key) \
static const v8::Persistent<v8::String> var = \
v8::Persistent<v8::String>::New(v8::String::NewSymbol(#key));
v8::Persistent<v8::String>::New(LD_NODE_ISOLATE_PRE v8::String::NewSymbol(#key));

#define LD_V8_METHOD(name) \
static v8::Handle<v8::Value> name (const v8::Arguments& args);
Expand Down Expand Up @@ -105,17 +116,20 @@
v8::Persistent<v8::Function> callback; \
if (optionPos == -1 && args[callbackPos]->IsFunction()) { \
callback = v8::Persistent<v8::Function>::New( \
LD_NODE_ISOLATE_PRE \
v8::Local<v8::Function>::Cast(args[callbackPos]) \
); \
} else if (optionPos != -1 && args[callbackPos - 1]->IsFunction()) { \
callback = v8::Persistent<v8::Function>::New( \
LD_NODE_ISOLATE_PRE \
v8::Local<v8::Function>::Cast(args[callbackPos - 1]) \
); \
} else if (optionPos != -1 \
&& args[optionPos]->IsObject() \
&& args[callbackPos]->IsFunction()) { \
optionsObj = v8::Local<v8::Object>::Cast(args[optionPos]); \
callback = v8::Persistent<v8::Function>::New( \
LD_NODE_ISOLATE_PRE \
v8::Local<v8::Function>::Cast(args[callbackPos]) \
); \
} else { \
Expand Down

0 comments on commit cc48eef

Please sign in to comment.