Skip to content

Commit

Permalink
child_process: refactor to use more primordials
Browse files Browse the repository at this point in the history
PR-URL: #36003
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
aduh95 authored and targos committed May 16, 2021
1 parent ef7d3b1 commit b566802
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/internal/child_process/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
const {
JSONParse,
JSONStringify,
StringPrototypeSplit,
Symbol,
TypedArrayPrototypeSubarray,
} = primordials;
const { Buffer } = require('buffer');
const { StringDecoder } = require('string_decoder');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit b566802

Please sign in to comment.