Skip to content

Commit 2065c40

Browse files
committed
Remove compatibility and custom utility code
1 parent 53a5855 commit 2065c40

3 files changed

Lines changed: 3 additions & 76 deletions

File tree

lib/client.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,6 @@ const {
2525
const { assertValidMessage } = require('./message_validation.js');
2626
const debug = require('debug')('rclnodejs:client');
2727

28-
// Polyfill for AbortSignal.any() for Node.js <= 20.3.0
29-
// AbortSignal.any() was added in Node.js 20.3.0
30-
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static
31-
if (!AbortSignal.any) {
32-
AbortSignal.any = function (signals) {
33-
// Filter out null/undefined values and validate inputs
34-
const validSignals = Array.isArray(signals)
35-
? signals.filter((signal) => signal != null)
36-
: [];
37-
38-
// If no valid signals, return a never-aborting signal
39-
if (validSignals.length === 0) {
40-
return new AbortController().signal;
41-
}
42-
43-
const controller = new AbortController();
44-
const listeners = [];
45-
46-
// Cleanup function to remove all event listeners
47-
const cleanup = () => {
48-
listeners.forEach(({ signal, listener }) => {
49-
signal.removeEventListener('abort', listener);
50-
});
51-
};
52-
53-
for (const signal of validSignals) {
54-
if (signal.aborted) {
55-
cleanup();
56-
controller.abort(signal.reason);
57-
return controller.signal;
58-
}
59-
60-
const listener = () => {
61-
cleanup();
62-
controller.abort(signal.reason);
63-
};
64-
65-
signal.addEventListener('abort', listener);
66-
listeners.push({ signal, listener });
67-
}
68-
69-
return controller.signal;
70-
};
71-
}
72-
7328
/**
7429
* @class - Class representing a Client in ROS
7530
* @hideconstructor

lib/message_introspector.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,7 @@ class MessageIntrospector {
8888
const instance = new this.#typeClass();
8989
this.#defaultsCache = toPlainObject(instance);
9090
}
91-
return this.#deepClone(this.#defaultsCache);
92-
}
93-
94-
/**
95-
* Deep clone an object.
96-
* @param {any} obj - Object to clone
97-
* @returns {any} Cloned object
98-
* @private
99-
*/
100-
#deepClone(obj) {
101-
if (obj === null || typeof obj !== 'object') {
102-
return obj;
103-
}
104-
105-
if (Array.isArray(obj)) {
106-
return obj.map((item) => this.#deepClone(item));
107-
}
108-
109-
if (ArrayBuffer.isView(obj) && !(obj instanceof DataView)) {
110-
return obj.slice();
111-
}
112-
113-
const cloned = {};
114-
for (const key in obj) {
115-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
116-
cloned[key] = this.#deepClone(obj[key]);
117-
}
118-
}
119-
return cloned;
91+
return structuredClone(this.#defaultsCache);
12092
}
12193
}
12294

lib/message_serialization.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function toPlainArrays(obj) {
6262
if (typeof obj === 'object' && obj !== null) {
6363
const result = {};
6464
for (const key in obj) {
65-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
65+
if (Object.hasOwn(obj, key)) {
6666
result[key] = toPlainArrays(obj[key]);
6767
}
6868
}
@@ -105,7 +105,7 @@ function toJSONSafe(obj) {
105105
if (typeof obj === 'object' && obj !== null) {
106106
const result = {};
107107
for (const key in obj) {
108-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
108+
if (Object.hasOwn(obj, key)) {
109109
result[key] = toJSONSafe(obj[key]);
110110
}
111111
}

0 commit comments

Comments
 (0)