GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: fix duplicate logic in stream destroy · nodejs/node@88eb619

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams
    • destroy.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/destroy.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/destroy.js
+16-22Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ const { Symbol } = primordials;
88
const kDestroy = Symbol('kDestroy');
99
const kConstruct = Symbol('kConstruct');
1010

11+
function checkError(err, w, r) {
12+
if (err) {
13+
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
14+
err.stack;
15+
16+
if (w && !w.errored) {
17+
w.errored = err;
18+
}
19+
if (r && !r.errored) {
20+
r.errored = err;
21+
}
22+
}
23+
}
24+
1125
// Backwards compat. cb() is undocumented and unused in core but
1226
// unfortunately might be used by modules.
1327
function destroy(err, cb) {
@@ -24,20 +38,10 @@ function destroy(err, cb) {
2438
return this;
2539
}
2640

27-
if (err) {
28-
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
29-
err.stack;
30-
31-
if (w && !w.errored) {
32-
w.errored = err;
33-
}
34-
if (r && !r.errored) {
35-
r.errored = err;
36-
}
37-
}
3841

3942
// We set destroyed to true before firing error callbacks in order
4043
// to make it re-entrance safe in case destroy() is called within callbacks
44+
checkError(err, w, r);
4145

4246
if (w) {
4347
w.destroyed = true;
@@ -66,17 +70,7 @@ function _destroy(self, err, cb) {
6670

6771
called = true;
6872

69-
if (err) {
70-
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
71-
err.stack;
72-
73-
if (w && !w.errored) {
74-
w.errored = err;
75-
}
76-
if (r && !r.errored) {
77-
r.errored = err;
78-
}
79-
}
73+
checkError(err, w, r);
8074

8175
if (w) {
8276
w.closed = true;

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.