Skip to content

Commit 0ac82a0

Browse files
authored
Revert "perf: reuse TextDecoder instance (#2863)" (#2999)
This reverts commit 2091dcf.
1 parent bf8c671 commit 0ac82a0

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

lib/web/websocket/receiver.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ const { WebsocketFrameSend } = require('./frame')
1212
// Copyright (c) 2013 Arnout Kazemier and contributors
1313
// Copyright (c) 2016 Luigi Pinca and contributors
1414

15-
const textDecoder = new TextDecoder('utf-8', { fatal: true })
16-
1715
class ByteParser extends Writable {
1816
#buffers = []
1917
#byteOffset = 0
@@ -316,7 +314,8 @@ class ByteParser extends Writable {
316314
}
317315

318316
try {
319-
reason = textDecoder.decode(reason)
317+
// TODO: optimize this
318+
reason = new TextDecoder('utf-8', { fatal: true }).decode(reason)
320319
} catch {
321320
return null
322321
}

lib/web/websocket/util.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ function fireEvent (e, target, eventConstructor = Event, eventInitDict = {}) {
6868
target.dispatchEvent(event)
6969
}
7070

71-
const textDecoder = new TextDecoder('utf-8', { fatal: true })
72-
7371
/**
7472
* @see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
7573
* @param {import('./websocket').WebSocket} ws
@@ -89,7 +87,7 @@ function websocketMessageReceived (ws, type, data) {
8987
// -> type indicates that the data is Text
9088
// a new DOMString containing data
9189
try {
92-
dataForEvent = textDecoder.decode(data)
90+
dataForEvent = new TextDecoder('utf-8', { fatal: true }).decode(data)
9391
} catch {
9492
failWebsocketConnection(ws, 'Received invalid UTF-8 in text frame.')
9593
return

0 commit comments

Comments
 (0)