Skip to content

Remove compatibility and custom utility code#1479

Merged
minggangw merged 3 commits intoRobotWebTools:developfrom
minggangw:fix-1458-2
Apr 8, 2026
Merged

Remove compatibility and custom utility code#1479
minggangw merged 3 commits intoRobotWebTools:developfrom
minggangw:fix-1458-2

Conversation

@minggangw
Copy link
Copy Markdown
Member

@minggangw minggangw commented Apr 7, 2026

Changed Files

  • lib/client.js

    • Removed the AbortSignal.any() polyfill for older Node.js versions.
    • Net effect: the code now relies on native AbortSignal.any() support from the runtime.
  • lib/message_introspector.js

    • Replaced the custom private #deepClone() implementation with structuredClone(this.#defaultsCache).
    • Net effect: simpler default-message cloning logic with less handwritten recursion.
  • lib/message_serialization.js

    • Replaced Object.prototype.hasOwnProperty.call(obj, key) with Object.hasOwn(obj, key) in two object-walk helpers.
    • Net effect: minor modernization with no intended behavior change.
  • lib/action/uuid.js

    • Replaced .replace(/-/g, '') with .replaceAll('-', '').
  • rosidl_gen/packages.js

    • Replaced .replace(/\\\\/g, '/') with .replaceAll('\\', '/') in two path-normalization helpers.
    • Replaced deprecated .substr(1) with .substring(1).
  • rosidl_gen/templates/message-template.js

    • Replaced .indexOf(...) !== -1 with .includes(...) in isPrimitivePackage() and isTypedArrayType().
  • scripts/run_test.js

    • Replaced .substr(0, 5) === 'test-' with .startsWith('test-').
    • Replaced .indexOf(test) === -1 with !...includes(test).

Overall Impact

  • Removes legacy compatibility code (AbortSignal.any() polyfill, custom #deepClone()).
  • Replaces deprecated APIs (substr) and verbose patterns (regex .replace, indexOf, hasOwnProperty.call) with modern equivalents (substring, replaceAll, includes, startsWith, Object.hasOwn, structuredClone).
  • All replacements are safe, drop-in substitutions available since Node.js 16–20, well within the 20.20.2 minimum.

Fix: #1458

Copilot AI review requested due to automatic review settings April 7, 2026 10:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes older compatibility/custom utility code and adopts newer platform APIs for cloning and property ownership checks.

Changes:

  • Removes the AbortSignal.any() polyfill and relies on runtime-provided AbortSignal.any().
  • Replaces a custom deep-clone implementation with structuredClone() for cached default messages.
  • Modernizes ownership checks in serialization helpers by switching to Object.hasOwn().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/client.js Removes AbortSignal.any() polyfill code, leaving native AbortSignal.any() usage elsewhere in the file.
lib/message_introspector.js Uses structuredClone() to clone cached default message objects instead of a handwritten deep clone.
lib/message_serialization.js Replaces hasOwnProperty.call with Object.hasOwn in object-walk helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -25,51 +25,6 @@ const {
const { assertValidMessage } = require('./message_validation.js');
const debug = require('debug')('rclnodejs:client');

Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the AbortSignal.any() polyfill makes this module rely on a native AbortSignal.any implementation, but the code still calls AbortSignal.any later (e.g., in sendRequestAsync) without a guard. With the current repo metadata/CI still targeting Node 16.x (package.json engines and ARM64 workflow), this will throw at runtime. Either restore a local fallback for AbortSignal.any (only when missing) or update the supported Node.js floor + CI/prebuild targets/docs in the same PR so this file’s runtime requirements are consistent.

Suggested change
if (
typeof AbortSignal !== 'undefined' &&
typeof AbortSignal.any !== 'function'
) {
AbortSignal.any = function any(signals) {
if (!signals || typeof signals[Symbol.iterator] !== 'function') {
throw new TypeError(
"Failed to execute 'any' on 'AbortSignal': parameter 1 is not iterable."
);
}
const signalList = Array.from(signals);
const controller = new AbortController();
const listeners = new Map();
const cleanup = function cleanup() {
for (const signal of signalList) {
const listener = listeners.get(signal);
if (listener) {
signal.removeEventListener('abort', listener);
}
}
listeners.clear();
};
for (const signal of signalList) {
if (signal.aborted) {
controller.abort(signal.reason);
return controller.signal;
}
}
for (const signal of signalList) {
const listener = function listener() {
cleanup();
controller.abort(signal.reason);
};
listeners.set(signal, listener);
signal.addEventListener('abort', listener, { once: true });
}
return controller.signal;
};
}

Copilot uses AI. Check for mistakes.
}
}
return cloned;
return structuredClone(this.#defaultsCache);
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

structuredClone is used unconditionally here. If this package still supports Node 16.x (per package.json engines / docs), global structuredClone may be undefined and this getter will throw. Consider feature-detecting structuredClone and falling back to the previous deep-clone logic (or a compatible clone helper), or raise the minimum supported Node.js version and update the repo metadata/CI accordingly.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 8, 2026

Coverage Status

No base build to compare — minggangw:fix-1458-2 into RobotWebTools:develop

@minggangw minggangw merged commit 79ce8fc into RobotWebTools:develop Apr 8, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Roadmap: Prepare rclnodejs for ROS 2 Lyrical Luth

3 participants