Remove compatibility and custom utility code#1479
Remove compatibility and custom utility code#1479minggangw merged 3 commits intoRobotWebTools:developfrom
Conversation
There was a problem hiding this comment.
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-providedAbortSignal.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'); | |||
|
|
|||
There was a problem hiding this comment.
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.
| 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; | |
| }; | |
| } |
| } | ||
| } | ||
| return cloned; | ||
| return structuredClone(this.#defaultsCache); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Changed Files
lib/client.js
AbortSignal.any()polyfill for older Node.js versions.AbortSignal.any()support from the runtime.lib/message_introspector.js
#deepClone()implementation withstructuredClone(this.#defaultsCache).lib/message_serialization.js
Object.prototype.hasOwnProperty.call(obj, key)withObject.hasOwn(obj, key)in two object-walk helpers.lib/action/uuid.js
.replace(/-/g, '')with.replaceAll('-', '').rosidl_gen/packages.js
.replace(/\\\\/g, '/')with.replaceAll('\\', '/')in two path-normalization helpers..substr(1)with.substring(1).rosidl_gen/templates/message-template.js
.indexOf(...) !== -1with.includes(...)inisPrimitivePackage()andisTypedArrayType().scripts/run_test.js
.substr(0, 5) === 'test-'with.startsWith('test-')..indexOf(test) === -1with!...includes(test).Overall Impact
AbortSignal.any()polyfill, custom#deepClone()).substr) and verbose patterns (regex.replace,indexOf,hasOwnProperty.call) with modern equivalents (substring,replaceAll,includes,startsWith,Object.hasOwn,structuredClone).Fix: #1458