Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output result different from document in mjs example of Events #49537

Closed
pluris opened this issue Sep 7, 2023 · 2 comments · Fixed by #49548
Closed

Output result different from document in mjs example of Events #49537

pluris opened this issue Sep 7, 2023 · 2 comments · Fixed by #49548
Labels
doc Issues and PRs related to the documentations.

Comments

@pluris
Copy link
Contributor

pluris commented Sep 7, 2023

Version

v20.5.1

Platform

ubuntu 20.04, Microsoft Windows NT 10.0.19045.0 x64

Subsystem

No response

What steps will reproduce the bug?

When performing the document example for event, the results are different.

node/doc/api/events.md

Lines 102 to 111 in e0fb3f7

```mjs
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
myEmitter.on('event', (a, b) => {
console.log(a, b, this);
// Prints: a b {}
});
myEmitter.emit('event', 'a', 'b');
```

Even if you print console.log(this); in the part where the callback is called in another mjs example, it is the same.

node/doc/api/http.md

Lines 484 to 537 in e0fb3f7

```mjs
import { createServer, request } from 'node:http';
import { connect } from 'node:net';
import { URL } from 'node:url';
// Create an HTTP tunneling proxy
const proxy = createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('okay');
});
proxy.on('connect', (req, clientSocket, head) => {
// Connect to an origin server
const { port, hostname } = new URL(`http://${req.url}`);
const serverSocket = connect(port || 80, hostname, () => {
clientSocket.write('HTTP/1.1 200 Connection Established\r\n' +
'Proxy-agent: Node.js-Proxy\r\n' +
'\r\n');
serverSocket.write(head);
serverSocket.pipe(clientSocket);
clientSocket.pipe(serverSocket);
});
});
// Now that proxy is running
proxy.listen(1337, '127.0.0.1', () => {
// Make a request to a tunneling proxy
const options = {
port: 1337,
host: '127.0.0.1',
method: 'CONNECT',
path: 'www.google.com:80',
};
const req = request(options);
req.end();
req.on('connect', (res, socket, head) => {
console.log('got connected!');
// Make a request over an HTTP tunnel
socket.write('GET / HTTP/1.1\r\n' +
'Host: www.google.com:80\r\n' +
'Connection: close\r\n' +
'\r\n');
socket.on('data', (chunk) => {
console.log(chunk.toString());
});
socket.on('end', () => {
proxy.close();
});
});
});
```

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

// Prints: a b {}

What do you see instead?

// Prints: a b undefined

Additional information

In cjs examples, this is output as {}, while in mjs examples, this is output as undefined. It is necessary to check whether the output as undefined is a problem or normal, and if not, the document needs to be modified.

@VoltrexKeyva VoltrexKeyva added the doc Issues and PRs related to the documentations. label Sep 9, 2023
@vishal6557
Copy link

Hello, Can I work on this issue?

nodejs-github-bot pushed a commit that referenced this issue Sep 19, 2023
PR-URL: #49548
Refs: #49537
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
@atlowChemi atlowChemi linked a pull request Sep 19, 2023 that will close this issue
@atlowChemi
Copy link
Member

Fixed by #49548 which seems to not have been linked

ruyadorno pushed a commit that referenced this issue Sep 28, 2023
PR-URL: #49548
Refs: #49537
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
alexfernandez pushed a commit to alexfernandez/node that referenced this issue Nov 1, 2023
PR-URL: nodejs#49548
Refs: nodejs#49537
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants