Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: replace this with the object that it refers to
In `test/parallel/test-http-write-empty-string.js`, the callback passed
to `http.createServer` contains a reference to `this`. Since the object
referenced by `this` doesn't pre-exist, revert the arrow function to an
anonymous closure function as a callback.

Similarly, the callback passed to `server.listen` too contains a
reference to `this`. However, in this case, `this` resolves to a
pre-existing object `server`. Therefore, it is safe to use an arrow
function as a callback as long as `this` is replaced with `server`.
  • Loading branch information
sagirk committed Nov 20, 2018
commit bffdf1d60a222a596f0dc95984ace0a677bd397a
4 changes: 2 additions & 2 deletions test/parallel/test-http-write-empty-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const assert = require('assert');

const http = require('http');

const server = http.createServer((request, response) => {
const server = http.createServer(function (request, response) {
console.log(`responding to ${request.url}`);

response.writeHead(200, { 'Content-Type': 'text/plain' });
Expand All @@ -39,7 +39,7 @@ const server = http.createServer((request, response) => {
});

server.listen(0, common.mustCall(() => {
http.get({ port: this.address().port }, common.mustCall((res) => {
http.get({ port: server.address().port }, common.mustCall((res) => {
let response = '';

assert.strictEqual(res.statusCode, 200);
Expand Down