1818#include < rcl/rcl.h>
1919
2020#include < cstdio>
21+ #include < rcpputils/scope_exit.hpp>
2122#include < string>
2223
2324#include " macros.h"
@@ -35,6 +36,15 @@ Napi::Value Init(const Napi::CallbackInfo& info) {
3536 rcl_init_options_init (&init_options, allocator),
3637 rcl_get_error_string ().str );
3738
39+ RCPPUTILS_SCOPE_EXIT ({
40+ rcl_ret_t fini_ret = rcl_init_options_fini (&init_options);
41+ if (RCL_RET_OK != fini_ret) {
42+ Napi::Error::New (env, rcl_get_error_string ().str )
43+ .ThrowAsJavaScriptException ();
44+ rcl_reset_error ();
45+ }
46+ });
47+
3848 // Preprocess Context
3949 RclHandle* context_handle = RclHandle::Unwrap (info[0 ].As <Napi::Object>());
4050 rcl_context_t * context =
@@ -54,6 +64,18 @@ Napi::Value Init(const Napi::CallbackInfo& info) {
5464 snprintf (argv[i], len, " %s" , arg.c_str ());
5565 }
5666 }
67+ // Set up the domain id.
68+ size_t domain_id = RCL_DEFAULT_DOMAIN_ID;
69+ if (info.Length () > 2 && info[2 ].IsBigInt ()) {
70+ bool lossless;
71+ domain_id = info[2 ].As <Napi::BigInt>().Uint64Value (&lossless);
72+ }
73+ rcl_ret_t ret = rcl_init_options_set_domain_id (&init_options, domain_id);
74+ if (RCL_RET_OK != ret) {
75+ Napi::Error::New (env, " failed to set domain id to init options" )
76+ .ThrowAsJavaScriptException ();
77+ return env.Undefined ();
78+ }
5779
5880 THROW_ERROR_IF_NOT_EQUAL (
5981 RCL_RET_OK,
@@ -141,7 +163,7 @@ Napi::Value GetDomainId(const Napi::CallbackInfo& info) {
141163 return env.Undefined ();
142164 }
143165
144- return Napi::Number ::New (env, domain_id);
166+ return Napi::BigInt ::New (env, domain_id);
145167}
146168
147169Napi::Object InitContextBindings (Napi::Env env, Napi::Object exports) {
0 commit comments