@@ -319,24 +319,27 @@ NAN_METHOD(CreateTimer) {
319319 Nan::To<v8::Object>(info[1 ]).ToLocalChecked ());
320320 rcl_context_t * context =
321321 reinterpret_cast <rcl_context_t *>(context_handle->ptr ());
322- int64_t period_ms = Nan::To<int64_t >(info[2 ]).FromJust ();
323-
322+ if (!info[2 ]->IsBigInt ()) {
323+ Nan::ThrowTypeError (" Timer period must be a BigInt" );
324+ return ;
325+ }
326+ v8::Local<v8::BigInt> bigInt = info[2 ].As <v8::BigInt>();
327+ int64_t period_nsec = bigInt->Int64Value ();
324328 rcl_timer_t * timer =
325329 reinterpret_cast <rcl_timer_t *>(malloc (sizeof (rcl_timer_t )));
326330 *timer = rcl_get_zero_initialized_timer ();
327331
328332#if ROS_VERSION > 2305 // After Iron.
329333 THROW_ERROR_IF_NOT_EQUAL (
330334 RCL_RET_OK,
331- rcl_timer_init2 (timer, clock, context, RCL_MS_TO_NS (period_ms) , nullptr ,
335+ rcl_timer_init2 (timer, clock, context, period_nsec , nullptr ,
332336 rcl_get_default_allocator (), /* autostart=*/ true ),
333337 rcl_get_error_string ().str );
334338#else
335- THROW_ERROR_IF_NOT_EQUAL (
336- RCL_RET_OK,
337- rcl_timer_init (timer, clock, context, RCL_MS_TO_NS (period_ms), nullptr ,
338- rcl_get_default_allocator ()),
339- rcl_get_error_string ().str );
339+ THROW_ERROR_IF_NOT_EQUAL (RCL_RET_OK,
340+ rcl_timer_init (timer, clock, context, period_nsec,
341+ nullptr , rcl_get_default_allocator ()),
342+ rcl_get_error_string ().str );
340343#endif
341344
342345 auto js_obj = RclHandle::NewInstance (timer, clock_handle, [](void * ptr) {
@@ -410,9 +413,9 @@ NAN_METHOD(TimerGetTimeUntilNextCall) {
410413 RCL_RET_OK, rcl_timer_get_time_until_next_call (timer, &remaining_time),
411414 rcl_get_error_string ().str );
412415
413- info. GetReturnValue (). Set (
414- Nan:: New< v8::String>( std::to_string ( RCL_NS_TO_MS ( remaining_time)))
415- . ToLocalChecked () );
416+ v8::Local<v8::BigInt> bigInt =
417+ v8::BigInt:: New( v8::Isolate::GetCurrent (), remaining_time);
418+ info. GetReturnValue (). Set (bigInt );
416419}
417420
418421NAN_METHOD (TimerGetTimeSinceLastCall) {
@@ -425,9 +428,9 @@ NAN_METHOD(TimerGetTimeSinceLastCall) {
425428 RCL_RET_OK, rcl_timer_get_time_since_last_call (timer, &elapsed_time),
426429 rcl_get_error_string ().str );
427430
428- info. GetReturnValue (). Set (
429- Nan:: New< v8::String>( std::to_string ( RCL_NS_TO_MS ( elapsed_time)))
430- . ToLocalChecked () );
431+ v8::Local<v8::BigInt> bigInt =
432+ v8::BigInt:: New( v8::Isolate::GetCurrent (), elapsed_time);
433+ info. GetReturnValue (). Set (bigInt );
431434}
432435
433436NAN_METHOD (CreateTimePoint) {
0 commit comments