Skip to content

Commit 879b617

Browse files
hashseedCommit bot
authored andcommitted
Change syntax error message for illegal token.
It used to say "Unexpected token ILLEGAL", now it says "Invalid or unexpected token". [email protected] BUG=chromium:257405 LOG=N Review URL: https://codereview.chromium.org/1758663002 Cr-Commit-Position: refs/heads/master@{#34431}
1 parent 6eb483f commit 879b617

5 files changed

Lines changed: 22 additions & 20 deletions

File tree

src/messages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ class CallSite {
395395
T(InvalidLhsInPrefixOp, \
396396
"Invalid left-hand side expression in prefix operation") \
397397
T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \
398+
T(InvalidOrUnexpectedToken, "Invalid or unexpected token") \
398399
T(JsonParseUnexpectedEOS, "Unexpected end of JSON input") \
399400
T(JsonParseUnexpectedToken, "Unexpected token % in JSON at position %") \
400401
T(JsonParseUnexpectedTokenNumber, "Unexpected number in JSON at position %") \

src/parsing/parser-base.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -992,27 +992,23 @@ template <class Traits>
992992
void ParserBase<Traits>::GetUnexpectedTokenMessage(
993993
Token::Value token, MessageTemplate::Template* message, const char** arg,
994994
MessageTemplate::Template default_) {
995+
*arg = nullptr;
995996
switch (token) {
996997
case Token::EOS:
997998
*message = MessageTemplate::kUnexpectedEOS;
998-
*arg = nullptr;
999999
break;
10001000
case Token::SMI:
10011001
case Token::NUMBER:
10021002
*message = MessageTemplate::kUnexpectedTokenNumber;
1003-
*arg = nullptr;
10041003
break;
10051004
case Token::STRING:
10061005
*message = MessageTemplate::kUnexpectedTokenString;
1007-
*arg = nullptr;
10081006
break;
10091007
case Token::IDENTIFIER:
10101008
*message = MessageTemplate::kUnexpectedTokenIdentifier;
1011-
*arg = nullptr;
10121009
break;
10131010
case Token::FUTURE_RESERVED_WORD:
10141011
*message = MessageTemplate::kUnexpectedReserved;
1015-
*arg = nullptr;
10161012
break;
10171013
case Token::LET:
10181014
case Token::STATIC:
@@ -1021,17 +1017,17 @@ void ParserBase<Traits>::GetUnexpectedTokenMessage(
10211017
*message = is_strict(language_mode())
10221018
? MessageTemplate::kUnexpectedStrictReserved
10231019
: MessageTemplate::kUnexpectedTokenIdentifier;
1024-
*arg = nullptr;
10251020
break;
10261021
case Token::TEMPLATE_SPAN:
10271022
case Token::TEMPLATE_TAIL:
10281023
*message = MessageTemplate::kUnexpectedTemplateString;
1029-
*arg = nullptr;
10301024
break;
10311025
case Token::ESCAPED_STRICT_RESERVED_WORD:
10321026
case Token::ESCAPED_KEYWORD:
10331027
*message = MessageTemplate::kInvalidEscapedReservedWord;
1034-
*arg = nullptr;
1028+
break;
1029+
case Token::ILLEGAL:
1030+
*message = MessageTemplate::kInvalidOrUnexpectedToken;
10351031
break;
10361032
default:
10371033
const char* name = Token::String(token);

test/mjsunit/messages.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ test(function() {
339339
eval("/a/x.test(\"a\");");
340340
}, "Invalid regular expression flags", SyntaxError);
341341

342+
// kInvalidOrUnexpectedToken
343+
test(function() {
344+
eval("'\n'");
345+
}, "Invalid or unexpected token", SyntaxError);
346+
342347
//kJsonParseUnexpectedEOS
343348
test(function() {
344349
JSON.parse("{")

test/webkit/fast/js/basic-strict-mode-expected.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ PASS (function f(arg){'use strict'; var descriptor = Object.getOwnPropertyDescri
206206
PASS (function f(arg){'use strict'; var descriptor = Object.getOwnPropertyDescriptor(f.__proto__, 'caller'); return descriptor.get === descriptor.set; })() is true
207207
PASS (function f(arg){'use strict'; var descriptor = Object.getOwnPropertyDescriptor(f.__proto__, 'arguments'); return descriptor.get === descriptor.set; })() is true
208208
PASS 'use strict'; (function f() { for(var i in this); })(); true; is true
209-
PASS 'use strict'̻ threw exception SyntaxError: Unexpected token ILLEGAL.
210-
PASS (function(){'use strict'̻}) threw exception SyntaxError: Unexpected token ILLEGAL.
211-
PASS 'use strict'5.f threw exception SyntaxError: Unexpected token ILLEGAL.
212-
PASS (function(){'use strict'5.f}) threw exception SyntaxError: Unexpected token ILLEGAL.
213-
PASS 'use strict';̻ threw exception SyntaxError: Unexpected token ILLEGAL.
214-
PASS (function(){'use strict';̻}) threw exception SyntaxError: Unexpected token ILLEGAL.
215-
PASS 'use strict';5.f threw exception SyntaxError: Unexpected token ILLEGAL.
216-
PASS (function(){'use strict';5.f}) threw exception SyntaxError: Unexpected token ILLEGAL.
209+
PASS 'use strict'̻ threw exception SyntaxError: Invalid or unexpected token.
210+
PASS (function(){'use strict'̻}) threw exception SyntaxError: Invalid or unexpected token.
211+
PASS 'use strict'5.f threw exception SyntaxError: Invalid or unexpected token.
212+
PASS (function(){'use strict'5.f}) threw exception SyntaxError: Invalid or unexpected token.
213+
PASS 'use strict';̻ threw exception SyntaxError: Invalid or unexpected token.
214+
PASS (function(){'use strict';̻}) threw exception SyntaxError: Invalid or unexpected token.
215+
PASS 'use strict';5.f threw exception SyntaxError: Invalid or unexpected token.
216+
PASS (function(){'use strict';5.f}) threw exception SyntaxError: Invalid or unexpected token.
217217
PASS 'use strict';1-(eval=1); threw exception SyntaxError: Unexpected eval or arguments in strict mode.
218218
PASS (function(){'use strict';1-(eval=1);}) threw exception SyntaxError: Unexpected eval or arguments in strict mode.
219219
PASS 'use strict';arguments=1; threw exception SyntaxError: Unexpected eval or arguments in strict mode.

test/webkit/fast/js/kde/parse-expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ PASS function test() { return 0 } lab: 1 is 1
3939
PASS function test() { while(0) break lab } lab: 1 threw exception SyntaxError: Undefined label 'lab'.
4040
PASS function test() { while(0) continue lab } lab: 1 threw exception SyntaxError: Undefined label 'lab'.
4141
PASS var éĀʯΈᢨ = 101; éĀʯΈᢨ; is 101
42-
PASS var f÷; threw exception SyntaxError: Unexpected token ILLEGAL.
42+
PASS var f÷; threw exception SyntaxError: Invalid or unexpected token.
4343
PASS var \u0061 = 102; a is 102
4444
PASS var f\u0030 = 103; f0 is 103
4545
PASS var \u00E9\u0100\u02AF\u0388\u18A8 = 104; \u00E9\u0100\u02AF\u0388\u18A8; is 104
46-
PASS var f\u00F7; threw exception SyntaxError: Unexpected token ILLEGAL.
47-
PASS var \u0030; threw exception SyntaxError: Unexpected token ILLEGAL.
48-
PASS var test = { }; test.i= 0; test.i\u002b= 1; test.i; threw exception SyntaxError: Unexpected token ILLEGAL.
46+
PASS var f\u00F7; threw exception SyntaxError: Invalid or unexpected token.
47+
PASS var \u0030; threw exception SyntaxError: Invalid or unexpected token.
48+
PASS var test = { }; test.i= 0; test.i\u002b= 1; test.i; threw exception SyntaxError: Invalid or unexpected token.
4949
PASS var test = { }; test.i= 0; test.i+= 1; test.i; is 1
5050
PASS successfullyParsed is true
5151

0 commit comments

Comments
 (0)