From 7e80934c51999f04a2e9a5666d7faf7f63793131 Mon Sep 17 00:00:00 2001 From: rubikscraft Date: Mon, 2 May 2022 11:38:53 +0200 Subject: [PATCH] child_process: use primordials Suggested by @Himself65 and @anonrig --- lib/internal/child_process/serialization.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/child_process/serialization.js b/lib/internal/child_process/serialization.js index 26facbcd47ae1c..f8b919ba300179 100644 --- a/lib/internal/child_process/serialization.js +++ b/lib/internal/child_process/serialization.js @@ -4,6 +4,8 @@ const { JSONParse, JSONStringify, StringPrototypeSplit, + ArrayPrototypePush, + ReflectApply, Symbol, TypedArrayPrototypeSubarray, } = primordials; @@ -13,6 +15,7 @@ const v8 = require('v8'); const { isArrayBufferView } = require('internal/util/types'); const assert = require('internal/assert'); const { streamBaseState, kLastWriteWasAsync } = internalBinding('stream_wrap'); +const { readUInt32BE } = require('internal/buffer'); const kMessageBuffer = Symbol('kMessageBuffer'); const kMessageBufferSize = Symbol('kMessageBufferSize'); @@ -60,7 +63,7 @@ const advanced = { *parseChannelMessages(channel, readData) { if (readData.length === 0) return; - channel[kMessageBuffer].push(readData); + ArrayPrototypePush(channel[kMessageBuffer], readData); channel[kMessageBufferSize] += readData.length; // Index 0 should always be present because we just pushed data into it. @@ -68,7 +71,7 @@ const advanced = { while (messageBufferHead.length >= 4) { // We call `readUInt32BE` manually here, because this is faster than first converting // it to a buffer and using `readUInt32BE` on that. - const fullMessageSize = Buffer.prototype.readUInt32BE.call(messageBufferHead, 0) + 4; + const fullMessageSize = ReflectApply(readUInt32BE, messageBufferHead, [0]) + 4; if (channel[kMessageBufferSize] < fullMessageSize) break;