15
15
*
16
16
*/
17
17
18
- #include < node .h>
18
+ #include < nan .h>
19
19
#include " GZNode.hh"
20
20
21
21
#include " GazeboInterface.hh"
@@ -47,120 +47,118 @@ GZNode::~GZNode()
47
47
};
48
48
49
49
// ///////////////////////////////////////////////
50
- void GZNode::Init ( Handle <Object> exports )
50
+ NAN_MODULE_INIT ( GZNode::Init)
51
51
{
52
- Isolate* isolate = exports->GetIsolate ();
53
52
// Prepare constructor template
54
- Local<FunctionTemplate> tpl = FunctionTemplate::New (isolate, New);
55
- tpl->SetClassName (String::NewFromUtf8 (isolate, " GZNode" ));
53
+ Local<String> class_name = Nan::New (" GZNode" ).ToLocalChecked ();
54
+
55
+ Local<FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(GZNode::New);
56
+
57
+ tpl->SetClassName (class_name);
56
58
tpl->InstanceTemplate ()->SetInternalFieldCount (1 );
57
59
// Prototype
58
- NODE_SET_PROTOTYPE_METHOD (tpl, " loadMaterialScripts" , LoadMaterialScripts);
60
+ Nan::SetPrototypeMethod (tpl, " loadMaterialScripts" , LoadMaterialScripts);
59
61
60
- NODE_SET_PROTOTYPE_METHOD (tpl, " setConnected" , SetConnected);
62
+ Nan::SetPrototypeMethod (tpl, " setConnected" , SetConnected);
61
63
62
- NODE_SET_PROTOTYPE_METHOD (tpl, " setPoseMsgFilterMinimumDistanceSquared" , SetPoseMsgFilterMinimumDistanceSquared);
63
- NODE_SET_PROTOTYPE_METHOD (tpl, " getPoseMsgFilterMinimumDistanceSquared" , GetPoseMsgFilterMinimumDistanceSquared);
64
- NODE_SET_PROTOTYPE_METHOD (tpl, " setPoseMsgFilterMinimumQuaternionSquared" , SetPoseMsgFilterMinimumQuaternionSquared);
65
- NODE_SET_PROTOTYPE_METHOD (tpl, " getPoseMsgFilterMinimumQuaternionSquared" , GetPoseMsgFilterMinimumQuaternionSquared);
64
+ Nan::SetPrototypeMethod (tpl, " setPoseMsgFilterMinimumDistanceSquared" , SetPoseMsgFilterMinimumDistanceSquared);
65
+ Nan::SetPrototypeMethod (tpl, " getPoseMsgFilterMinimumDistanceSquared" , GetPoseMsgFilterMinimumDistanceSquared);
66
+ Nan::SetPrototypeMethod (tpl, " setPoseMsgFilterMinimumQuaternionSquared" , SetPoseMsgFilterMinimumQuaternionSquared);
67
+ Nan::SetPrototypeMethod (tpl, " getPoseMsgFilterMinimumQuaternionSquared" , GetPoseMsgFilterMinimumQuaternionSquared);
66
68
67
- NODE_SET_PROTOTYPE_METHOD (tpl, " getPoseMsgFilterMinimumAge" ,
69
+ Nan::SetPrototypeMethod (tpl, " getPoseMsgFilterMinimumAge" ,
68
70
GetPoseMsgFilterMinimumAge);
69
71
70
- NODE_SET_PROTOTYPE_METHOD (tpl, " setPoseMsgFilterMinimumAge" ,
72
+ Nan::SetPrototypeMethod (tpl, " setPoseMsgFilterMinimumAge" ,
71
73
SetPoseMsgFilterMinimumAge);
72
74
73
- NODE_SET_PROTOTYPE_METHOD (tpl, " getMessages" , GetMessages);
75
+ Nan::SetPrototypeMethod (tpl, " getMessages" , GetMessages);
74
76
75
- NODE_SET_PROTOTYPE_METHOD (tpl, " request" , Request);
77
+ Nan::SetPrototypeMethod (tpl, " request" , Request);
76
78
77
- NODE_SET_PROTOTYPE_METHOD (tpl, " getIsGzServerConnected" ,
79
+ Nan::SetPrototypeMethod (tpl, " getIsGzServerConnected" ,
78
80
GetIsGzServerConnected);
79
81
80
- NODE_SET_PROTOTYPE_METHOD (tpl, " getMaterialScriptsMessage" ,
82
+ Nan::SetPrototypeMethod (tpl, " getMaterialScriptsMessage" ,
81
83
GetMaterialScriptsMessage);
82
84
83
- exports->Set (String::NewFromUtf8 (isolate, " GZNode" ),
84
- tpl->GetFunction ());
85
+ target->Set (Nan::GetCurrentContext (), class_name,
86
+ tpl->GetFunction (Nan::GetCurrentContext ()).ToLocalChecked ()
87
+ ).ToChecked ();
85
88
}
86
89
87
90
// ///////////////////////////////////////////////
88
- void GZNode::New ( const FunctionCallbackInfo<Value>& args )
91
+ NAN_METHOD ( GZNode::New)
89
92
{
90
- if (args .IsConstructCall ()) {
93
+ if (info .IsConstructCall ()) {
91
94
// Invoked as constructor: `new MyObject(...)`
92
95
GZNode* obj = new GZNode ();
93
- obj->Wrap (args.This ());
94
- args.GetReturnValue ().Set (args.This ());
96
+ obj->Wrap (info.This ());
97
+ info.GetReturnValue ().Set (info.This ());
98
+ }else {
99
+ return Nan::ThrowTypeError (" GZNode::New - called without new keyword" );
95
100
}
96
101
}
97
102
98
103
// ///////////////////////////////////////////////
99
- void GZNode::LoadMaterialScripts ( const FunctionCallbackInfo<Value>& args )
104
+ NAN_METHOD ( GZNode::LoadMaterialScripts)
100
105
{
101
- Isolate* isolate = args .GetIsolate ();
106
+ Isolate* isolate = info .GetIsolate ();
102
107
103
- if (args .Length () < 1 )
108
+ if (info .Length () < 1 )
104
109
{
105
- isolate->ThrowException (Exception::TypeError (
106
- String::NewFromUtf8 (isolate, " Wrong number of arguments" )));
107
- return ;
110
+ return Nan::ThrowTypeError (" GZNode::LoadMaterialScripts - Wrong number of arguments. One arg expected" );
108
111
}
109
112
110
- if (!args [0 ]->IsString ())
113
+ if (!info [0 ]->IsString ())
111
114
{
112
- isolate->ThrowException (Exception::TypeError (
113
- String::NewFromUtf8 (isolate, " Wrong argument type. String expected." )));
114
- return ;
115
+ return Nan::ThrowTypeError (" GZNode::LoadMaterialScripts - Wrong argument type. String expected." );
115
116
}
116
117
117
- GZNode* obj = ObjectWrap::Unwrap<GZNode>(args .This ());
118
+ GZNode* obj = ObjectWrap::Unwrap<GZNode>(info .This ());
118
119
119
- String::Utf8Value path (args [0 ]-> ToString () );
120
+ String::Utf8Value path (isolate, info [0 ]);
120
121
obj->gzIface ->LoadMaterialScripts (std::string (*path));
121
122
122
123
return ;
123
124
}
124
125
125
126
// ///////////////////////////////////////////////
126
- void GZNode::SetConnected ( const FunctionCallbackInfo<Value>& args )
127
+ NAN_METHOD ( GZNode::SetConnected)
127
128
{
128
- GZNode *obj = ObjectWrap::Unwrap<GZNode>(args.This ());
129
- bool value = args[0 ]->BooleanValue ();
129
+
130
+ GZNode *obj = ObjectWrap::Unwrap<GZNode>(info.This ());
131
+ bool value = Nan::To<bool >(info[0 ]).ToChecked ();
130
132
obj->gzIface ->SetConnected (value);
131
133
132
134
return ;
133
135
}
134
136
135
137
// ///////////////////////////////////////////////
136
- void GZNode::GetIsGzServerConnected ( const FunctionCallbackInfo<Value>& args )
138
+ NAN_METHOD ( GZNode::GetIsGzServerConnected)
137
139
{
138
- GZNode *obj = ObjectWrap::Unwrap<GZNode>(args .This ());
140
+ GZNode *obj = ObjectWrap::Unwrap<GZNode>(info .This ());
139
141
bool value = obj->isGzServerConnected ;
140
142
141
- args .GetReturnValue ().Set (value);
143
+ info .GetReturnValue ().Set (value);
142
144
}
143
145
144
146
// ///////////////////////////////////////////////
145
- void GZNode::GetMaterialScriptsMessage ( const FunctionCallbackInfo<Value>& args )
147
+ NAN_METHOD ( GZNode::GetMaterialScriptsMessage)
146
148
{
147
- Isolate* isolate = args .GetIsolate ();
149
+ Isolate* isolate = info .GetIsolate ();
148
150
149
- if (args .Length () < 1 )
151
+ if (info .Length () < 1 )
150
152
{
151
- isolate->ThrowException (Exception::TypeError (
152
- String::NewFromUtf8 (isolate, " Wrong number of arguments" )));
153
- return ;
153
+ return Nan::ThrowTypeError (" GZNode::GetMaterialScriptsMessage - Wrong number of arguments. One arg expected." );
154
154
}
155
155
156
- if (!args [0 ]->IsString ())
156
+ if (!info [0 ]->IsString ())
157
157
{
158
- isolate->ThrowException (Exception::TypeError (
159
- String::NewFromUtf8 (isolate, " Wrong argument type. String expected." )));
160
- return ;
158
+ return Nan::ThrowTypeError (" GZNode::GetMaterialScriptsMessage - Wrong argument type. String expected." );
161
159
}
162
160
163
- String::Utf8Value path (args [0 ]-> ToString () );
161
+ String::Utf8Value path (isolate, info [0 ]);
164
162
165
163
OgreMaterialParser materialParser;
166
164
materialParser.Load (std::string (*path));
@@ -171,122 +169,109 @@ void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo<Value>& args)
171
169
msg += materialJson;
172
170
msg += " }" ;
173
171
174
- args .GetReturnValue ().Set (String::NewFromUtf8 (isolate , msg.c_str ()));
172
+ info .GetReturnValue ().Set (Nan::New ( msg.c_str ()). ToLocalChecked ( ));
175
173
}
176
174
177
175
// ///////////////////////////////////////////////
178
- void GZNode::SetPoseMsgFilterMinimumDistanceSquared (const
179
- FunctionCallbackInfo<Value>& args)
176
+ NAN_METHOD (GZNode::SetPoseMsgFilterMinimumDistanceSquared)
180
177
{
181
- GZNode *obj = ObjectWrap::Unwrap<GZNode>(args .This ());
178
+ GZNode *obj = ObjectWrap::Unwrap<GZNode>(info .This ());
182
179
183
- Local<Number> v = Local <Number>:: Cast (args [0 ]);
180
+ Local<Number> v = Nan::To <Number>(info [0 ]). ToLocalChecked ( );
184
181
double value = v->Value ();
185
182
obj->gzIface ->SetPoseFilterMinimumDistanceSquared (value);
186
183
187
184
return ;
188
185
}
189
186
190
187
// ///////////////////////////////////////////////
191
- void GZNode::GetPoseMsgFilterMinimumDistanceSquared (const
192
- FunctionCallbackInfo<Value>& args)
188
+ NAN_METHOD (GZNode::GetPoseMsgFilterMinimumDistanceSquared)
193
189
{
194
- Isolate* isolate = args.GetIsolate ();
195
- GZNode *obj = ObjectWrap::Unwrap<GZNode>(args.This ());
190
+ GZNode *obj = ObjectWrap::Unwrap<GZNode>(info.This ());
196
191
double value = obj->gzIface ->GetPoseFilterMinimumDistanceSquared ();
197
- args .GetReturnValue ().Set (Number ::New(isolate , value));
192
+ info .GetReturnValue ().Set (Nan ::New<Number>( value));
198
193
}
199
194
200
195
// ///////////////////////////////////////////////////
201
- void GZNode::SetPoseMsgFilterMinimumQuaternionSquared (const
202
- FunctionCallbackInfo<Value>& args)
196
+ NAN_METHOD (GZNode::SetPoseMsgFilterMinimumQuaternionSquared)
203
197
{
204
- GZNode *obj = ObjectWrap::Unwrap<GZNode>(args .This ());
205
- Local<Number> v = Local <Number>:: Cast (args [0 ]);
198
+ GZNode *obj = ObjectWrap::Unwrap<GZNode>(info .This ());
199
+ Local<Number> v = Nan::To <Number>(info [0 ]). ToLocalChecked ( );
206
200
double value = v->Value ();
207
201
obj->gzIface ->SetPoseFilterMinimumQuaternionSquared (value);
208
202
209
203
return ;
210
204
}
211
205
212
206
// ///////////////////////////////////////////////
213
- void GZNode::GetPoseMsgFilterMinimumQuaternionSquared (const
214
- FunctionCallbackInfo<Value>& args)
207
+ NAN_METHOD (GZNode::GetPoseMsgFilterMinimumQuaternionSquared)
215
208
{
216
- Isolate* isolate = args.GetIsolate ();
217
- GZNode *obj = ObjectWrap::Unwrap<GZNode>(args.This ());
209
+ GZNode *obj = ObjectWrap::Unwrap<GZNode>(info.This ());
218
210
double value = obj->gzIface ->GetPoseFilterMinimumQuaternionSquared ();
219
- args .GetReturnValue ().Set (Number ::New(isolate , value));
211
+ info .GetReturnValue ().Set (Nan ::New<Number>( value));
220
212
}
221
213
222
214
// ///////////////////////////////////////////////
223
- void GZNode::GetMessages ( const FunctionCallbackInfo<Value>& args )
215
+ NAN_METHOD ( GZNode::GetMessages)
224
216
{
225
- Isolate* isolate = args.GetIsolate ();
226
217
227
- GZNode* obj = ObjectWrap::Unwrap<GZNode>(args .This ());
218
+ GZNode* obj = ObjectWrap::Unwrap<GZNode>(info .This ());
228
219
229
220
std::vector<std::string> msgs = obj->gzIface ->PopOutgoingMessages ();
230
- // args.GetReturnValue().Set(Number::New(isolate ,msgs.size()));
231
- Local<Array> arguments = Array::New (isolate, msgs.size ());
221
+ Local<Array> arguments = Nan::New<Array>(msgs.size ());
232
222
for (unsigned int i = 0 ; i < msgs.size (); ++i) {
233
- arguments->Set (i ,String::NewFromUtf8 (isolate, msgs[i].c_str ()));
223
+ Local<String> v8_msg = Nan::New<String>(msgs[i].c_str ()).ToLocalChecked ();
224
+ Nan::Set (arguments, i, v8_msg);
234
225
}
235
226
236
- args .GetReturnValue ().Set (arguments);
227
+ info .GetReturnValue ().Set (arguments);
237
228
}
238
229
239
230
240
231
// //////////////////////////////////////////////
241
- void GZNode::Request ( const FunctionCallbackInfo<Value>& args )
232
+ NAN_METHOD ( GZNode::Request)
242
233
{
243
- Isolate* isolate = args .GetIsolate ();
234
+ Isolate* isolate = info .GetIsolate ();
244
235
245
- if (args .Length () < 1 )
236
+ if (info .Length () < 1 )
246
237
{
247
- isolate->ThrowException (Exception::TypeError (
248
- String::NewFromUtf8 (isolate, " Wrong number of arguments" )));
249
- return ;
238
+ return Nan::ThrowTypeError (" GZNode::Request - Wrong number of arguments. One arg expected." );
250
239
}
251
240
252
- if (!args [0 ]->IsString ())
241
+ if (!info [0 ]->IsString ())
253
242
{
254
- isolate->ThrowException (Exception::TypeError (
255
- String::NewFromUtf8 (isolate, " Wrong argument type. String expected." )));
256
- return ;
243
+ return Nan::ThrowTypeError (" GZNode::Request - Wrong argument type. String expected." );
257
244
}
258
245
259
- GZNode* obj = ObjectWrap::Unwrap<GZNode>(args .This ());
246
+ GZNode* obj = ObjectWrap::Unwrap<GZNode>(info .This ());
260
247
261
- String::Utf8Value request (args [0 ]-> ToString () );
248
+ String::Utf8Value request (isolate, info [0 ]);
262
249
obj->gzIface ->PushRequest (std::string (*request));
263
250
264
251
return ;
265
252
}
266
253
267
254
// ///////////////////////////////////////////////
268
- void GZNode::SetPoseMsgFilterMinimumAge (const
269
- FunctionCallbackInfo<Value>& args)
255
+ NAN_METHOD (GZNode::SetPoseMsgFilterMinimumAge)
270
256
{
271
- GZNode* obj = ObjectWrap::Unwrap<GZNode>(args .This ());
272
- Local<Number> v = Local <Number>:: Cast (args [0 ]);
257
+ GZNode* obj = ObjectWrap::Unwrap<GZNode>(info .This ());
258
+ Local<Number> v = Nan::To <Number>(info [0 ]). ToLocalChecked ( );
273
259
double value = v->Value ();
274
260
obj->gzIface ->SetPoseFilterMinimumMsgAge (value);
275
261
276
262
return ;
277
263
}
278
264
279
265
// ///////////////////////////////////////////////
280
- void GZNode::GetPoseMsgFilterMinimumAge (const
281
- FunctionCallbackInfo<Value>& args)
266
+ NAN_METHOD (GZNode::GetPoseMsgFilterMinimumAge)
282
267
{
283
- GZNode* obj = ObjectWrap::Unwrap<GZNode>(args .This ());
268
+ GZNode* obj = ObjectWrap::Unwrap<GZNode>(info .This ());
284
269
double value = obj->gzIface ->GetPoseFilterMinimumMsgAge ();
285
- args .GetReturnValue ().Set (value);
270
+ info .GetReturnValue ().Set (value);
286
271
}
287
272
288
273
// ///////////////////////////////////////////////
289
- void InitAll (Handle <Object> exports)
274
+ void InitAll (Local <Object> exports, Local<Value> module, void * priv )
290
275
{
291
276
GZNode::Init (exports);
292
277
}
0 commit comments