9
9
10
10
namespace leveldown {
11
11
12
- static v8 ::Persistent<v8::FunctionTemplate> batch_constructor;
12
+ static Nan ::Persistent<v8::FunctionTemplate> batch_constructor;
13
13
14
14
Batch::Batch (leveldown::Database* database, bool sync) : database(database) {
15
15
options = new leveldb::WriteOptions ();
@@ -28,45 +28,43 @@ leveldb::Status Batch::Write () {
28
28
}
29
29
30
30
void Batch::Init () {
31
- v8::Local<v8::FunctionTemplate> tpl = NanNew <v8::FunctionTemplate>(Batch::New);
32
- NanAssignPersistent ( batch_constructor, tpl);
33
- tpl->SetClassName (NanNew (" Batch" ));
31
+ v8::Local<v8::FunctionTemplate> tpl = Nan::New <v8::FunctionTemplate>(Batch::New);
32
+ batch_constructor. Reset ( tpl);
33
+ tpl->SetClassName (Nan::New (" Batch" ). ToLocalChecked ( ));
34
34
tpl->InstanceTemplate ()->SetInternalFieldCount (1 );
35
- NODE_SET_PROTOTYPE_METHOD (tpl, " put" , Batch::Put);
36
- NODE_SET_PROTOTYPE_METHOD (tpl, " del" , Batch::Del);
37
- NODE_SET_PROTOTYPE_METHOD (tpl, " clear" , Batch::Clear);
38
- NODE_SET_PROTOTYPE_METHOD (tpl, " write" , Batch::Write);
35
+ Nan::SetPrototypeMethod (tpl, " put" , Batch::Put);
36
+ Nan::SetPrototypeMethod (tpl, " del" , Batch::Del);
37
+ Nan::SetPrototypeMethod (tpl, " clear" , Batch::Clear);
38
+ Nan::SetPrototypeMethod (tpl, " write" , Batch::Write);
39
39
}
40
40
41
41
NAN_METHOD (Batch::New) {
42
- NanScope ();
43
-
44
- Database* database = node::ObjectWrap::Unwrap<Database>(args[0 ]->ToObject ());
42
+ Database* database = Nan::ObjectWrap::Unwrap<Database>(info[0 ]->ToObject ());
45
43
v8::Local<v8::Object> optionsObj;
46
44
47
- if (args .Length () > 1 && args [1 ]->IsObject ()) {
48
- optionsObj = v8::Local<v8::Object>::Cast (args [1 ]);
45
+ if (info .Length () > 1 && info [1 ]->IsObject ()) {
46
+ optionsObj = v8::Local<v8::Object>::Cast (info [1 ]);
49
47
}
50
48
51
49
bool sync = BooleanOptionValue (optionsObj, " sync" );
52
50
53
51
Batch* batch = new Batch (database, sync );
54
- batch->Wrap (args .This ());
52
+ batch->Wrap (info .This ());
55
53
56
- NanReturnValue (args .This ());
54
+ info. GetReturnValue (). Set (info .This ());
57
55
}
58
56
59
57
v8::Handle <v8::Value> Batch::NewInstance (
60
58
v8::Handle <v8::Object> database
61
59
, v8::Handle <v8::Object> optionsObj
62
60
) {
63
61
64
- NanEscapableScope () ;
62
+ Nan::EscapableHandleScope scope ;
65
63
66
64
v8::Local<v8::Object> instance;
67
65
68
66
v8::Local<v8::FunctionTemplate> constructorHandle =
69
- NanNew <v8::FunctionTemplate>(batch_constructor);
67
+ Nan::New <v8::FunctionTemplate>(batch_constructor);
70
68
71
69
if (optionsObj.IsEmpty ()) {
72
70
v8::Handle <v8::Value> argv[1 ] = { database };
@@ -76,17 +74,15 @@ v8::Handle<v8::Value> Batch::NewInstance (
76
74
instance = constructorHandle->GetFunction ()->NewInstance (2 , argv);
77
75
}
78
76
79
- return NanEscapeScope (instance);
77
+ return scope. Escape (instance);
80
78
}
81
79
82
80
NAN_METHOD (Batch::Put) {
83
- NanScope ();
84
-
85
- Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder ());
81
+ Batch* batch = ObjectWrap::Unwrap<Batch>(info.Holder ());
86
82
v8::Handle <v8::Function> callback; // purely for the error macros
87
83
88
- v8::Local<v8::Value> keyBuffer = args [0 ];
89
- v8::Local<v8::Value> valueBuffer = args [1 ];
84
+ v8::Local<v8::Value> keyBuffer = info [0 ];
85
+ v8::Local<v8::Value> valueBuffer = info [1 ];
90
86
LD_STRING_OR_BUFFER_TO_SLICE (key, keyBuffer, key)
91
87
LD_STRING_OR_BUFFER_TO_SLICE (value, valueBuffer, value)
92
88
@@ -97,17 +93,15 @@ NAN_METHOD(Batch::Put) {
97
93
DisposeStringOrBufferFromSlice (keyBuffer, key);
98
94
DisposeStringOrBufferFromSlice (valueBuffer, value);
99
95
100
- NanReturnValue (args .Holder ());
96
+ info. GetReturnValue (). Set (info .Holder ());
101
97
}
102
98
103
99
NAN_METHOD (Batch::Del) {
104
- NanScope ();
105
-
106
- Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder ());
100
+ Batch* batch = ObjectWrap::Unwrap<Batch>(info.Holder ());
107
101
108
102
v8::Handle <v8::Function> callback; // purely for the error macros
109
103
110
- v8::Local<v8::Value> keyBuffer = args [0 ];
104
+ v8::Local<v8::Value> keyBuffer = info [0 ];
111
105
LD_STRING_OR_BUFFER_TO_SLICE (key, keyBuffer, key)
112
106
113
107
batch->batch ->Delete (key);
@@ -116,38 +110,32 @@ NAN_METHOD(Batch::Del) {
116
110
117
111
DisposeStringOrBufferFromSlice (keyBuffer, key);
118
112
119
- NanReturnValue (args .Holder ());
113
+ info. GetReturnValue (). Set (info .Holder ());
120
114
}
121
115
122
116
NAN_METHOD (Batch::Clear) {
123
- NanScope ();
124
-
125
- Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder ());
117
+ Batch* batch = ObjectWrap::Unwrap<Batch>(info.Holder ());
126
118
127
119
batch->batch ->Clear ();
128
120
batch->hasData = false ;
129
121
130
- NanReturnValue (args .Holder ());
122
+ info. GetReturnValue (). Set (info .Holder ());
131
123
}
132
124
133
125
NAN_METHOD (Batch::Write) {
134
- NanScope ();
135
-
136
- Batch* batch = ObjectWrap::Unwrap<Batch>(args.Holder ());
126
+ Batch* batch = ObjectWrap::Unwrap<Batch>(info.Holder ());
137
127
138
128
if (batch->hasData ) {
139
- NanCallback *callback =
140
- new NanCallback (v8::Local<v8::Function>::Cast (args [0 ]));
129
+ Nan::Callback *callback =
130
+ new Nan::Callback (v8::Local<v8::Function>::Cast (info [0 ]));
141
131
BatchWriteWorker* worker = new BatchWriteWorker (batch, callback);
142
132
// persist to prevent accidental GC
143
- v8::Local<v8::Object> _this = args .This ();
133
+ v8::Local<v8::Object> _this = info .This ();
144
134
worker->SaveToPersistent (" batch" , _this);
145
- NanAsyncQueueWorker (worker);
135
+ Nan::AsyncQueueWorker (worker);
146
136
} else {
147
- LD_RUN_CALLBACK (v8::Local<v8::Function>::Cast (args [0 ]), 0 , NULL );
137
+ LD_RUN_CALLBACK (v8::Local<v8::Function>::Cast (info [0 ]), 0 , NULL );
148
138
}
149
-
150
- NanReturnUndefined ();
151
139
}
152
140
153
141
} // namespace leveldown
0 commit comments