diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-06-11 12:41:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 11:41:44 +0000 |
commit | 6a356aff1380e79d67738c5b43aa2b5fee76600d (patch) | |
tree | be4aadc62a523ff280820958a1a3829f1a18ca7d /ext/node/polyfills/_stream.mjs | |
parent | 3d41b486da7dcba49c8a18b45425e356c329d986 (diff) |
chore: sync up Node.js test files for v20.11.1 (#24066)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
Diffstat (limited to 'ext/node/polyfills/_stream.mjs')
-rw-r--r-- | ext/node/polyfills/_stream.mjs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/ext/node/polyfills/_stream.mjs b/ext/node/polyfills/_stream.mjs index 591f8bb51..075705e00 100644 --- a/ext/node/polyfills/_stream.mjs +++ b/ext/node/polyfills/_stream.mjs @@ -3754,7 +3754,14 @@ var require_writable = __commonJS({ this.destroyed = false; const noDecode = !!(options && options.decodeStrings === false); this.decodeStrings = !noDecode; - this.defaultEncoding = options && options.defaultEncoding || "utf8"; + const defaultEncoding = options?.defaultEncoding; + if (defaultEncoding == null) { + this.defaultEncoding = 'utf8'; + } else if (Buffer2.isEncoding(defaultEncoding)) { + this.defaultEncoding = defaultEncoding; + } else { + throw new ERR_UNKNOWN_ENCODING(defaultEncoding); + } this.length = 0; this.writing = false; this.corked = 0; @@ -3845,10 +3852,12 @@ var require_writable = __commonJS({ const state = stream._writableState; if (typeof encoding === "function") { cb = encoding; - encoding = state.defaultEncoding; + // Simulates https://github.com/nodejs/node/commit/dbed0319ac438dcbd6e92483f3280b1dc6767e00 + encoding = state.objectMode ? undefined : state.defaultEncoding; } else { if (!encoding) { - encoding = state.defaultEncoding; + // Simulates https://github.com/nodejs/node/commit/dbed0319ac438dcbd6e92483f3280b1dc6767e00 + encoding = state.objectMode ? undefined : state.defaultEncoding; } else if (encoding !== "buffer" && !Buffer2.isEncoding(encoding)) { throw new ERR_UNKNOWN_ENCODING(encoding); } @@ -4031,7 +4040,7 @@ var require_writable = __commonJS({ } while (count-- > 0) { state.pendingcb--; - cb(); + cb(null); } if (state.destroyed) { errorBuffer(state); @@ -4158,8 +4167,10 @@ var require_writable = __commonJS({ err = new ERR_STREAM_DESTROYED("end"); } if (typeof cb === "function") { - if (err || state.finished) { + if (err) { process.nextTick(cb, err); + } else if (state.finished) { + process.nextTick(cb, null); } else { state[kOnFinished].push(cb); } @@ -4246,7 +4257,7 @@ var require_writable = __commonJS({ state.finished = true; const onfinishCallbacks = state[kOnFinished].splice(0); for (let i = 0; i < onfinishCallbacks.length; i++) { - onfinishCallbacks[i](); + onfinishCallbacks[i](null); } stream.emit("finish"); if (state.autoDestroy) { |