You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all, I've been working on a tool to identify instances of events registered to the wrong object in uses of some JavaScript event-driven APIs, as part of a research project.
The tool flagged line 200 in tests/locker-core-api-test.js, on the registration of the “end” event.
The reason I believe this is indicative of an error is as follows (from looking at the nodejs http API documentation).
The return of http.get is an http.ClientRequest. But, “end” is an event on a readable stream, and http.ClientRequest is a writable stream.
Since the argument to the callback passed into http.get is an http.IncomingMessage, which is a readable stream, then my guess is that the listener for “end” maybe should be registered on this variable instead.
Specifically, I would guess the code should instead be
http.get(options, function(res) {
setTimeout(function() {
fs.stat(lconfig.me + "/testURLCallback/result.json", function(err, stats) {
if (!err)
promise.emit("success", true);
else
promise.emit("error", err);
});
}, 1500);
res.on('data', function(chunk) { // this registration has been moved
})
}.on("error", function(e) {
promise.emit("error", e);
});
Thanks!
The text was updated successfully, but these errors were encountered:
Hi all, I've been working on a tool to identify instances of events registered to the wrong object in uses of some JavaScript event-driven APIs, as part of a research project.
The tool flagged line 200 in tests/locker-core-api-test.js, on the registration of the “end” event.
The reason I believe this is indicative of an error is as follows (from looking at the nodejs http API documentation).
The return of
http.get
is an http.ClientRequest. But, “end” is an event on a readable stream, and http.ClientRequest is a writable stream.Since the argument to the callback passed into
http.get
is an http.IncomingMessage, which is a readable stream, then my guess is that the listener for “end” maybe should be registered on this variable instead.Specifically, I would guess the code should instead be
Thanks!
The text was updated successfully, but these errors were encountered: