From 8d7708bdefa8e7179aa5ff68d2619f6550d282a4 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 6 Nov 2020 18:49:07 +0100 Subject: [PATCH] child_process: refactor to use more primordials PR-URL: https://github.com/nodejs/node/pull/36003 Reviewed-By: Rich Trott --- lib/internal/child_process/serialization.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/internal/child_process/serialization.js b/lib/internal/child_process/serialization.js index df8a6ca67236c5..51c8efc1f21f45 100644 --- a/lib/internal/child_process/serialization.js +++ b/lib/internal/child_process/serialization.js @@ -3,7 +3,9 @@ const { JSONParse, JSONStringify, + StringPrototypeSplit, Symbol, + TypedArrayPrototypeSubarray, } = primordials; const { Buffer } = require('buffer'); const { StringDecoder } = require('string_decoder'); @@ -63,8 +65,8 @@ const advanced = { } const deserializer = new ChildProcessDeserializer( - messageBuffer.subarray(4, 4 + size)); - messageBuffer = messageBuffer.subarray(4 + size); + TypedArrayPrototypeSubarray(messageBuffer, 4, 4 + size)); + messageBuffer = TypedArrayPrototypeSubarray(messageBuffer, 4 + size); deserializer.readHeader(); yield deserializer.readValue(); @@ -98,7 +100,8 @@ const json = { if (channel[kStringDecoder] === undefined) channel[kStringDecoder] = new StringDecoder('utf8'); - const chunks = channel[kStringDecoder].write(readData).split('\n'); + const chunks = + StringPrototypeSplit(channel[kStringDecoder].write(readData), '\n'); const numCompleteChunks = chunks.length - 1; // Last line does not have trailing linebreak const incompleteChunk = chunks[numCompleteChunks];