From d5eee65df12bdaecb80afee1a54e89dfb5fce419 Mon Sep 17 00:00:00 2001 From: MCprotein Date: Fri, 26 Jul 2024 21:59:40 +0900 Subject: [PATCH] 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 --- lib/internal/streams/compose.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/internal/streams/compose.js b/lib/internal/streams/compose.js index 1b04a0f70a1e62..276ae6276071f6 100644 --- a/lib/internal/streams/compose.js +++ b/lib/internal/streams/compose.js @@ -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'); @@ -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]);