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

repl: refine handling of illegal tokens #7104

Closed
wants to merge 2 commits into from
Closed

Conversation

Trott
Copy link
Member

@Trott Trott commented Jun 2, 2016

Checklist
  • a test and/or benchmark is included
  • tests and code linting passes
  • the commit message follows commit guidelines
Affected core subsystem(s)
Description of change

Illegal tokens are only recoverable in string literals, RegExp literals,
and block comments. If not in one of these constructs, immediately
return an error rather than giving the user false hope by giving them a
chance to try to recover.

Fixes: #3611

@Trott Trott added the repl Issues and PRs related to the REPL subsystem. label Jun 2, 2016
@Trott
Copy link
Member Author

Trott commented Jun 2, 2016

Before:

$ node
> a = 3.5e
... wha?
... ;
... Argh!
... 

After:

$ node
> a = 3.5e
SyntaxError: Unexpected token ILLEGAL
    at Object.exports.createScript (vm.js:24:10)
    at REPLServer.defaultEval (repl.js:236:25)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:441:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:188:7)
    at REPLServer.Interface._onLine (readline.js:223:10)
    at REPLServer.Interface._line (readline.js:565:8)
    at REPLServer.Interface._ttyWrite (readline.js:842:14)
> 

@Trott
Copy link
Member Author

Trott commented Jun 2, 2016

But this still works, as expected:

Before:

$ node
> 'come\
... on\
... fhqwhgads'
'comeonfhqwhgads'
>

After:

$ ./node
> 'come\
... on\
... fhqwhgads'
'comeonfhqwhgads'
>

(No change between the two.)

@bnoordhuis
Copy link
Member

LGTM although checking for ILLEGAL could break when we upgrade V8.

@Fishrock123
Copy link
Contributor

@bnoordhuis Seems fine, the test will catch it.

@@ -1154,6 +1154,9 @@ REPLServer.prototype.convertToContext = function(cmd) {
return cmd;
};

function bailOnIllegalToken(lp) {
return lp._literal === null && !lp.blockComment && !lp.regExpLiteral;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser rather than lp?

@Fishrock123
Copy link
Contributor

@Trott
Copy link
Member Author

Trott commented Jun 4, 2016

Is it possible to generate Unexpected token: ILLEGAL while in a block comment? Maybe I don't need to check for that? (And if I do need to check for it, there ought to be a test...)

EDIT: Yes, it is very very possible. /* foo on a line by itself will do it.

Illegal tokens are only recoverable in string literals, RegExp literals,
and block comments. If not in one of these constructs, immediately
return an error rather than giving the user false hope by giving them a
chance to try to recover.

Fixes: nodejs#3611
@Trott
Copy link
Member Author

Trott commented Jun 4, 2016

Nits addressed, re-running CI: https://ci.nodejs.org/job/node-test-pull-request/2919/

@Trott
Copy link
Member Author

Trott commented Jun 4, 2016

Only CI failure was a single build failure on a Raspberry Pi. Trying again because YOU CAN'T BE TOO CAREFUL!!!11!!! or something like that.

CI: https://ci.nodejs.org/job/node-test-pull-request/2920/

Trott added a commit to Trott/io.js that referenced this pull request Jun 4, 2016
Illegal tokens are only recoverable in string literals, RegExp literals,
and block comments. If not in one of these constructs, immediately
return an error rather than giving the user false hope by giving them a
chance to try to recover.

PR-URL: nodejs#7104
Fixes: nodejs#3611
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@Trott
Copy link
Member Author

Trott commented Jun 4, 2016

Landed in de0aa23

@Trott Trott closed this Jun 4, 2016
@targos targos mentioned this pull request Jun 8, 2016
2 tasks
evanlucas pushed a commit that referenced this pull request Jun 15, 2016
Illegal tokens are only recoverable in string literals, RegExp literals,
and block comments. If not in one of these constructs, immediately
return an error rather than giving the user false hope by giving them a
chance to try to recover.

PR-URL: #7104
Fixes: #3611
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@evanlucas evanlucas mentioned this pull request Jun 16, 2016
@MylesBorins
Copy link
Contributor

@Trott lts?

@Trott
Copy link
Member Author

Trott commented Jul 11, 2016

@thealphanerd If it lands cleanly, yes.

@MylesBorins
Copy link
Contributor

this one does not land cleanly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REPL should raise Exception immediately when it gets naturally invalid multi-line.
4 participants