1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- #include < nan .h>
15+ #include < node_api .h>
1616
1717#include " macros.hpp"
1818#include " rcl_action_bindings.hpp"
2323#include " rcutils/macros.h"
2424#include " shadow_node.hpp"
2525
26- bool IsRunningInElectronRenderer () {
27- auto global = Nan::GetCurrentContext ()->Global ();
28- auto process =
29- Nan::To<v8::Object>(Nan::Get (global, Nan::New (" process" ).ToLocalChecked ())
30- .ToLocalChecked ())
31- .ToLocalChecked ();
32- auto process_type =
33- Nan::Get (process, Nan::New (" type" ).ToLocalChecked ()).ToLocalChecked ();
34- return process_type->StrictEquals (Nan::New (" renderer" ).ToLocalChecked ());
26+ bool IsRunningInElectronRenderer (napi_env env) {
27+ napi_value global, process, process_type;
28+ napi_get_global (env, &global);
29+ napi_get_named_property (env, global, " process" , &process);
30+ napi_get_named_property (env, process, " type" , &process_type);
31+
32+ bool is_renderer;
33+ napi_value renderer_str;
34+ napi_create_string_utf8 (env, " renderer" , NAPI_AUTO_LENGTH, &renderer_str);
35+ napi_strict_equals (env, process_type, renderer_str, &is_renderer);
36+ return is_renderer;
3537}
3638
37- void InitModule (v8::Local<v8::Object> exports) {
39+ void InitModule (napi_env env, napi_value exports) {
3840// workaround process name mangling by chromium
3941//
4042// rcl logging uses `program_invocation_name` to determine the log file,
@@ -43,42 +45,33 @@ void InitModule(v8::Local<v8::Object> exports) {
4345// occurence of ' -' with the null terminator. see:
4446// https://unix.stackexchange.com/questions/432419/unexpected-non-null-encoding-of-proc-pid-cmdline
4547#if defined(__linux__) && defined(__GLIBC__)
46- if (IsRunningInElectronRenderer ()) {
48+ if (IsRunningInElectronRenderer (env )) {
4749 auto prog_name = program_invocation_name;
4850 auto end = strstr (prog_name, " -" );
4951 assert (end);
5052 prog_name[end - prog_name] = 0 ;
5153 }
5254#endif
5355
54- v8::Local<v8::Context> context = exports->GetIsolate ()->GetCurrentContext ();
56+ napi_value context;
57+ napi_get_value_string_utf8 (env, exports, " context" , &context, NULL , NULL );
5558
5659 for (uint32_t i = 0 ; i < rclnodejs::binding_methods.size (); i++) {
57- Nan::Set (
58- exports, Nan::New (rclnodejs::binding_methods[i].name ).ToLocalChecked (),
59- Nan::New<v8::FunctionTemplate>(rclnodejs::binding_methods[i].function )
60- ->GetFunction (context)
61- .ToLocalChecked ());
60+ napi_value func;
61+ napi_create_function (env, NULL , 0 , rclnodejs::binding_methods[i].function , NULL , &func);
62+ napi_set_named_property (env, exports, rclnodejs::binding_methods[i].name , func);
6263 }
6364
6465 for (uint32_t i = 0 ; i < rclnodejs::action_binding_methods.size (); i++) {
65- Nan::Set (
66- exports,
67- Nan::New (rclnodejs::action_binding_methods[i].name ).ToLocalChecked (),
68- Nan::New<v8::FunctionTemplate>(
69- rclnodejs::action_binding_methods[i].function )
70- ->GetFunction (context)
71- .ToLocalChecked ());
66+ napi_value func;
67+ napi_create_function (env, NULL , 0 , rclnodejs::action_binding_methods[i].function , NULL , &func);
68+ napi_set_named_property (env, exports, rclnodejs::action_binding_methods[i].name , func);
7269 }
7370
7471 for (uint32_t i = 0 ; i < rclnodejs::lifecycle_binding_methods.size (); i++) {
75- Nan::Set (
76- exports,
77- Nan::New (rclnodejs::lifecycle_binding_methods[i].name ).ToLocalChecked (),
78- Nan::New<v8::FunctionTemplate>(
79- rclnodejs::lifecycle_binding_methods[i].function )
80- ->GetFunction (context)
81- .ToLocalChecked ());
72+ napi_value func;
73+ napi_create_function (env, NULL , 0 , rclnodejs::lifecycle_binding_methods[i].function , NULL , &func);
74+ napi_set_named_property (env, exports, rclnodejs::lifecycle_binding_methods[i].name , func);
8275 }
8376
8477 rclnodejs::ShadowNode::Init (exports);
0 commit comments