Skip to content

Commit a70653c

Browse files
committed
Address comments
1 parent a5ede31 commit a70653c

File tree

7 files changed

+27
-46
lines changed

7 files changed

+27
-46
lines changed

lib/logging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class Logging {
173173
severity,
174174
message,
175175
caller.functionName,
176-
parseInt(caller.lineNumber),
176+
parseInt(caller.lineNumber, 10),
177177
caller.fileName
178178
);
179179
}

src/addon.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
// limitations under the License.
1414

1515
#include <node_api.h>
16+
#include <rcutils/logging.h>
1617

1718
#include "macros.hpp"
1819
#include "rcl_action_bindings.hpp"
1920
#include "rcl_bindings.hpp"
2021
#include "rcl_handle.hpp"
2122
#include "rcl_lifecycle_bindings.hpp"
22-
#include "rcutils/logging.h"
23-
#include "rcutils/macros.h"
23+
#include "rcl_utilities.hpp"
2424
#include "shadow_node.hpp"
2525

2626
bool IsRunningInElectronRenderer(const Napi::Env& env) {
@@ -46,6 +46,8 @@ Napi::Object InitModule(Napi::Env env, Napi::Object exports) {
4646
prog_name[end - prog_name] = 0;
4747
}
4848
#endif
49+
50+
// Init the C++ bindings.
4951
rclnodejs::StoreEnv(env);
5052
rclnodejs::InitBindings(env, exports);
5153
rclnodejs::InitAction(env, exports);

src/macros.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@
1919

2020
#include "rcutils/logging_macros.h"
2121

22-
namespace rclnodejs {
23-
// Store a reference to the environment that can be used for error reporting
24-
inline Napi::Env& GetEnv() {
25-
static thread_local Napi::Env env = nullptr;
26-
return env;
27-
}
28-
29-
// Call this at the beginning of each function that may throw errors
30-
inline void StoreEnv(Napi::Env current_env) { GetEnv() = current_env; }
31-
} // namespace rclnodejs
32-
3322
#define CHECK_OP_AND_THROW_ERROR_IF_NOT_TRUE(op, lhs, rhs, message) \
3423
{ \
3524
if (lhs op rhs) { \

src/rcl_bindings.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,15 +1502,8 @@ Napi::Value CreateArrayBufferFromAddress(const Napi::CallbackInfo& info) {
15021502
memcpy(array_buffer.Data(), addr, length);
15031503
free(addr);
15041504
#else
1505-
// For nodejs > 12 or electron < 21, we will create a new `BackingStore` and
1506-
// take over the ownership of `addr`.
1507-
// std::unique_ptr<v8::BackingStore> backing =
1508-
// v8::ArrayBuffer::NewBackingStore(
1509-
// addr, length,
1510-
// [](void* data, size_t length, void* deleter_data) { free(data); },
1511-
// nullptr);
1512-
// auto array_buffer =
1513-
// Napi::ArrayBuffer::New(env, std::move(backing));
1505+
// For nodejs > 12 or electron < 21, we will take over the ownership of
1506+
// `addr`.
15141507
auto array_buffer = Napi::ArrayBuffer::New(
15151508
env, addr, length, [](Napi::Env /*env*/, void* data) { free(data); });
15161509
#endif
@@ -1880,16 +1873,11 @@ Napi::Value PublishRawMessage(const Napi::CallbackInfo& info) {
18801873
rcl_publisher_t* publisher = reinterpret_cast<rcl_publisher_t*>(
18811874
RclHandle::Unwrap(info[0].As<Napi::Object>())->ptr());
18821875

1883-
// auto object = (info[1].As<v8::Object>()).ToLocalChecked();
18841876
auto object = info[1].As<Napi::Buffer<char>>();
1885-
// v8::Local<v8::Object> object = napiBuffer;
18861877
rcl_serialized_message_t serialized_msg =
18871878
rmw_get_zero_initialized_serialized_message();
1888-
// serialized_msg.buffer_capacity = node::Buffer::Length(object);;
18891879
serialized_msg.buffer_capacity = object.Length();
18901880
serialized_msg.buffer_length = serialized_msg.buffer_capacity;
1891-
// serialized_msg.buffer =
1892-
// reinterpret_cast<uint8_t*>(node::Buffer::Data(object));
18931881
serialized_msg.buffer = reinterpret_cast<uint8_t*>(object.Data());
18941882

18951883
THROW_ERROR_IF_NOT_EQUAL(

src/rcl_handle.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <iostream>
2121

22-
#include "macros.hpp"
22+
#include "rcl_utilities.hpp"
2323

2424
namespace rclnodejs {
2525

@@ -59,12 +59,8 @@ void RclHandle::SyncProperties() {
5959
}
6060

6161
Napi::Value RclHandle::PropertiesGetter(const Napi::CallbackInfo& info) {
62-
Napi::Env env = info.Env();
63-
64-
if (!properties_obj_.IsEmpty())
65-
return properties_obj_.Value();
66-
else
67-
return env.Undefined();
62+
return !properties_obj_.IsEmpty() ? properties_obj_.Value()
63+
: info.Env().Undefined();
6864
}
6965

7066
Napi::Value RclHandle::Release(const Napi::CallbackInfo& info) {

src/rcl_handle.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class RclHandle : public Napi::ObjectWrap<RclHandle> {
3131
RclHandle* parent,
3232
std::function<void(void*)> deleter);
3333

34+
explicit RclHandle(const Napi::CallbackInfo& info);
35+
~RclHandle();
36+
3437
void set_deleter(std::function<void(void*)> deleter) { deleter_ = deleter; }
3538

3639
RclHandle* parent() { return parent_; }
@@ -42,23 +45,16 @@ class RclHandle : public Napi::ObjectWrap<RclHandle> {
4245
void Reset();
4346
void AddChild(RclHandle* child) { children_.insert(child); }
4447
void RemoveChild(RclHandle* child) { children_.erase(child); }
48+
void SetBoolProperty(const std::string& name, bool value) {
49+
properties_[name] = value;
50+
}
4551
void SyncProperties();
4652

47-
explicit RclHandle(const Napi::CallbackInfo& info);
48-
~RclHandle();
49-
50-
public:
51-
// Methods
53+
private:
5254
Napi::Value Release(const Napi::CallbackInfo& info);
5355
Napi::Value Dismiss(const Napi::CallbackInfo& info);
54-
55-
// Property getter
5656
Napi::Value PropertiesGetter(const Napi::CallbackInfo& info);
5757

58-
void SetBoolProperty(const std::string& name, bool value) {
59-
properties_[name] = value;
60-
}
61-
6258
private:
6359
void* pointer_;
6460
RclHandle* parent_;

src/rcl_utilities.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#ifndef SRC_RCL_UTILITIES_HPP_
1616
#define SRC_RCL_UTILITIES_HPP_
1717

18+
#include <napi.h>
19+
1820
#include <string>
1921

2022
struct rosidl_message_type_support_t;
@@ -35,6 +37,14 @@ const rosidl_action_type_support_t* GetActionTypeSupport(
3537

3638
std::string GetErrorMessageAndClear();
3739

40+
// Store a reference to the environment that can be used for error reporting.
41+
inline Napi::Env& GetEnv() {
42+
static thread_local Napi::Env env = nullptr;
43+
return env;
44+
}
45+
46+
inline void StoreEnv(Napi::Env current_env) { GetEnv() = current_env; }
47+
3848
} // namespace rclnodejs
3949

4050
#endif // SRC_RCL_UTILITIES_HPP_

0 commit comments

Comments
 (0)