readline: fix calling constructor without new#1385
Closed
rlidwka wants to merge 1 commit intonodejs:v1.xfrom
Closed
readline: fix calling constructor without new#1385rlidwka wants to merge 1 commit intonodejs:v1.xfrom
rlidwka wants to merge 1 commit intonodejs:v1.xfrom
Conversation
lib/readline.js
Outdated
Member
There was a problem hiding this comment.
Suggestion: use const to keep it lexically scoped.
Contributor
Author
There was a problem hiding this comment.
changed to const in the next commit
Member
|
LGTM with a suggestion. |
Previously, we detected options object based on amount of arguments supplied. But if we're calling readline without new operator, constructor gets re-called and will always have 4 arguments.
bnoordhuis
pushed a commit
that referenced
this pull request
Apr 10, 2015
Previously, we detected options object based on amount of arguments supplied. But if we're calling readline without new operator, constructor gets re-called and will always have 4 arguments. PR-URL: #1385 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This works:
$ iojs -e 'new (require("readline").Interface)({ input: process.stdin, output: process.stdout })'This doesn't:
The reason is that
optionobject detection here relies on a number of arguments passed to the constructor.But
instanceofguard here always makes it four arguments.So the issue happens when usual
instanceofcheck is combined with logic based onarguments.length.There are two places in
io.jscore when it matters. Second one is in buffer.js and it's already handled correctly.