From 879b617b19201c18c0351afb732aab10803da651 Mon Sep 17 00:00:00 2001 From: yangguo Date: Wed, 2 Mar 2016 06:20:21 -0800 Subject: [PATCH] Change syntax error message for illegal token. It used to say "Unexpected token ILLEGAL", now it says "Invalid or unexpected token". R=jkummerow@chromium.org BUG=chromium:257405 LOG=N Review URL: https://codereview.chromium.org/1758663002 Cr-Commit-Position: refs/heads/master@{#34431} --- src/messages.h | 1 + src/parsing/parser-base.h | 12 ++++-------- test/mjsunit/messages.js | 5 +++++ .../fast/js/basic-strict-mode-expected.txt | 16 ++++++++-------- test/webkit/fast/js/kde/parse-expected.txt | 8 ++++---- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/messages.h b/src/messages.h index c090888c21..7b12850f06 100644 --- a/src/messages.h +++ b/src/messages.h @@ -395,6 +395,7 @@ class CallSite { T(InvalidLhsInPrefixOp, \ "Invalid left-hand side expression in prefix operation") \ T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \ + T(InvalidOrUnexpectedToken, "Invalid or unexpected token") \ T(JsonParseUnexpectedEOS, "Unexpected end of JSON input") \ T(JsonParseUnexpectedToken, "Unexpected token % in JSON at position %") \ T(JsonParseUnexpectedTokenNumber, "Unexpected number in JSON at position %") \ diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h index 86e4826ddf..2c8a62ef83 100644 --- a/src/parsing/parser-base.h +++ b/src/parsing/parser-base.h @@ -992,27 +992,23 @@ template void ParserBase::GetUnexpectedTokenMessage( Token::Value token, MessageTemplate::Template* message, const char** arg, MessageTemplate::Template default_) { + *arg = nullptr; switch (token) { case Token::EOS: *message = MessageTemplate::kUnexpectedEOS; - *arg = nullptr; break; case Token::SMI: case Token::NUMBER: *message = MessageTemplate::kUnexpectedTokenNumber; - *arg = nullptr; break; case Token::STRING: *message = MessageTemplate::kUnexpectedTokenString; - *arg = nullptr; break; case Token::IDENTIFIER: *message = MessageTemplate::kUnexpectedTokenIdentifier; - *arg = nullptr; break; case Token::FUTURE_RESERVED_WORD: *message = MessageTemplate::kUnexpectedReserved; - *arg = nullptr; break; case Token::LET: case Token::STATIC: @@ -1021,17 +1017,17 @@ void ParserBase::GetUnexpectedTokenMessage( *message = is_strict(language_mode()) ? MessageTemplate::kUnexpectedStrictReserved : MessageTemplate::kUnexpectedTokenIdentifier; - *arg = nullptr; break; case Token::TEMPLATE_SPAN: case Token::TEMPLATE_TAIL: *message = MessageTemplate::kUnexpectedTemplateString; - *arg = nullptr; break; case Token::ESCAPED_STRICT_RESERVED_WORD: case Token::ESCAPED_KEYWORD: *message = MessageTemplate::kInvalidEscapedReservedWord; - *arg = nullptr; + break; + case Token::ILLEGAL: + *message = MessageTemplate::kInvalidOrUnexpectedToken; break; default: const char* name = Token::String(token); diff --git a/test/mjsunit/messages.js b/test/mjsunit/messages.js index 7deef02615..16cf99037f 100644 --- a/test/mjsunit/messages.js +++ b/test/mjsunit/messages.js @@ -339,6 +339,11 @@ test(function() { eval("/a/x.test(\"a\");"); }, "Invalid regular expression flags", SyntaxError); +// kInvalidOrUnexpectedToken +test(function() { + eval("'\n'"); +}, "Invalid or unexpected token", SyntaxError); + //kJsonParseUnexpectedEOS test(function() { JSON.parse("{") diff --git a/test/webkit/fast/js/basic-strict-mode-expected.txt b/test/webkit/fast/js/basic-strict-mode-expected.txt index 4bda2b173a..a7a29606ed 100644 --- a/test/webkit/fast/js/basic-strict-mode-expected.txt +++ b/test/webkit/fast/js/basic-strict-mode-expected.txt @@ -206,14 +206,14 @@ PASS (function f(arg){'use strict'; var descriptor = Object.getOwnPropertyDescri PASS (function f(arg){'use strict'; var descriptor = Object.getOwnPropertyDescriptor(f.__proto__, 'caller'); return descriptor.get === descriptor.set; })() is true PASS (function f(arg){'use strict'; var descriptor = Object.getOwnPropertyDescriptor(f.__proto__, 'arguments'); return descriptor.get === descriptor.set; })() is true PASS 'use strict'; (function f() { for(var i in this); })(); true; is true -PASS 'use strict'̻ threw exception SyntaxError: Unexpected token ILLEGAL. -PASS (function(){'use strict'̻}) threw exception SyntaxError: Unexpected token ILLEGAL. -PASS 'use strict'5.f threw exception SyntaxError: Unexpected token ILLEGAL. -PASS (function(){'use strict'5.f}) threw exception SyntaxError: Unexpected token ILLEGAL. -PASS 'use strict';̻ threw exception SyntaxError: Unexpected token ILLEGAL. -PASS (function(){'use strict';̻}) threw exception SyntaxError: Unexpected token ILLEGAL. -PASS 'use strict';5.f threw exception SyntaxError: Unexpected token ILLEGAL. -PASS (function(){'use strict';5.f}) threw exception SyntaxError: Unexpected token ILLEGAL. +PASS 'use strict'̻ threw exception SyntaxError: Invalid or unexpected token. +PASS (function(){'use strict'̻}) threw exception SyntaxError: Invalid or unexpected token. +PASS 'use strict'5.f threw exception SyntaxError: Invalid or unexpected token. +PASS (function(){'use strict'5.f}) threw exception SyntaxError: Invalid or unexpected token. +PASS 'use strict';̻ threw exception SyntaxError: Invalid or unexpected token. +PASS (function(){'use strict';̻}) threw exception SyntaxError: Invalid or unexpected token. +PASS 'use strict';5.f threw exception SyntaxError: Invalid or unexpected token. +PASS (function(){'use strict';5.f}) threw exception SyntaxError: Invalid or unexpected token. PASS 'use strict';1-(eval=1); threw exception SyntaxError: Unexpected eval or arguments in strict mode. PASS (function(){'use strict';1-(eval=1);}) threw exception SyntaxError: Unexpected eval or arguments in strict mode. PASS 'use strict';arguments=1; threw exception SyntaxError: Unexpected eval or arguments in strict mode. diff --git a/test/webkit/fast/js/kde/parse-expected.txt b/test/webkit/fast/js/kde/parse-expected.txt index 5caefd1ef0..d1a9afe7af 100644 --- a/test/webkit/fast/js/kde/parse-expected.txt +++ b/test/webkit/fast/js/kde/parse-expected.txt @@ -39,13 +39,13 @@ PASS function test() { return 0 } lab: 1 is 1 PASS function test() { while(0) break lab } lab: 1 threw exception SyntaxError: Undefined label 'lab'. PASS function test() { while(0) continue lab } lab: 1 threw exception SyntaxError: Undefined label 'lab'. PASS var éĀʯΈᢨ = 101; éĀʯΈᢨ; is 101 -PASS var f÷; threw exception SyntaxError: Unexpected token ILLEGAL. +PASS var f÷; threw exception SyntaxError: Invalid or unexpected token. PASS var \u0061 = 102; a is 102 PASS var f\u0030 = 103; f0 is 103 PASS var \u00E9\u0100\u02AF\u0388\u18A8 = 104; \u00E9\u0100\u02AF\u0388\u18A8; is 104 -PASS var f\u00F7; threw exception SyntaxError: Unexpected token ILLEGAL. -PASS var \u0030; threw exception SyntaxError: Unexpected token ILLEGAL. -PASS var test = { }; test.i= 0; test.i\u002b= 1; test.i; threw exception SyntaxError: Unexpected token ILLEGAL. +PASS var f\u00F7; threw exception SyntaxError: Invalid or unexpected token. +PASS var \u0030; threw exception SyntaxError: Invalid or unexpected token. +PASS var test = { }; test.i= 0; test.i\u002b= 1; test.i; threw exception SyntaxError: Invalid or unexpected token. PASS var test = { }; test.i= 0; test.i+= 1; test.i; is 1 PASS successfullyParsed is true