Skip to content

Commit

Permalink
lib: replace spread operator with primordials function
Browse files Browse the repository at this point in the history
replaced the spread operator with ArrayPrototypeSlice to avoid reliance
on user-mutable methods and enhance the safety of array iteration

Refs:
https://github.com/nodejs/node/blob/main/doc/contributing/primordials.md#unsafe-array-iteration
PR-URL: #54053
Refs: https://github.com/nodejs/node/blob/main/doc/contributing/primordials.md#unsafe-array-iteration
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
  • Loading branch information
MCprotein authored and targos committed Aug 14, 2024
1 parent 18bfea5 commit 417120a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/internal/streams/compose.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

const {
ArrayPrototypeSlice,
} = primordials;

const { pipeline } = require('internal/streams/pipeline');
const Duplex = require('internal/streams/duplex');
const { destroyer } = require('internal/streams/destroy');
Expand Down Expand Up @@ -30,7 +34,7 @@ module.exports = function compose(...streams) {
return Duplex.from(streams[0]);
}

const orgStreams = [...streams];
const orgStreams = ArrayPrototypeSlice(streams);

if (typeof streams[0] === 'function') {
streams[0] = Duplex.from(streams[0]);
Expand Down

0 comments on commit 417120a

Please sign in to comment.