Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: replace spread operator with primordials function
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
  • Loading branch information
MCprotein committed Jul 26, 2024
commit d5eee65df12bdaecb80afee1a54e89dfb5fce419
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