Commit 089e4fd3 authored by jwolfe's avatar jwolfe Committed by Commit bot

Change error messages for octal escape sequences

When an octal escape sequence is in a string in strict mode:
- Octal literals are not allowed in strict mode.
+ Octal escape sequences are not allowed in strict mode.

When an octal escape sequence is in a template string:
- Octal literals are not allowed in template strings.
+ Octal escape sequences are not allowed in template strings.

BUG=v8:4973
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2551633002
Cr-Commit-Position: refs/heads/master@{#41560}
parent 0a3c8fc3
......@@ -595,9 +595,11 @@ class ErrorUtils : public AllStatic {
"In strict mode code, functions can only be declared at top level or " \
"inside a block.") \
T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
T(StrictOctalEscape, \
"Octal escape sequences are not allowed in strict mode.") \
T(StrictWith, "Strict mode code may not include a with statement") \
T(TemplateOctalLiteral, \
"Octal literals are not allowed in template strings.") \
"Octal escape sequences are not allowed in template strings.") \
T(ThisFormalParameter, "'this' is not a valid formal parameter name") \
T(AwaitBindingIdentifier, \
"'await' is not a valid identifier name in an async function") \
......
......@@ -873,11 +873,14 @@ class ParserBase {
// Checks whether an octal literal was last seen between beg_pos and end_pos.
// If so, reports an error. Only called for strict mode and template strings.
void CheckOctalLiteral(int beg_pos, int end_pos,
MessageTemplate::Template message, bool* ok) {
void CheckOctalLiteral(int beg_pos, int end_pos, bool is_template, bool* ok) {
Scanner::Location octal = scanner()->octal_position();
if (octal.IsValid() && beg_pos <= octal.beg_pos &&
octal.end_pos <= end_pos) {
MessageTemplate::Template message =
is_template ? MessageTemplate::kTemplateOctalLiteral
: scanner()->octal_message();
DCHECK_NE(message, MessageTemplate::kNone);
impl()->ReportMessageAt(octal, message);
scanner()->clear_octal_position();
*ok = false;
......@@ -895,13 +898,11 @@ class ParserBase {
}
inline void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) {
CheckOctalLiteral(beg_pos, end_pos, MessageTemplate::kStrictOctalLiteral,
ok);
CheckOctalLiteral(beg_pos, end_pos, false, ok);
}
inline void CheckTemplateOctalLiteral(int beg_pos, int end_pos, bool* ok) {
CheckOctalLiteral(beg_pos, end_pos, MessageTemplate::kTemplateOctalLiteral,
ok);
CheckOctalLiteral(beg_pos, end_pos, true, ok);
}
void CheckDestructuringElement(ExpressionT element, int beg_pos, int end_pos);
......
......@@ -79,9 +79,8 @@ Scanner::Scanner(UnicodeCache* unicode_cache)
: unicode_cache_(unicode_cache),
octal_pos_(Location::invalid()),
decimal_with_leading_zero_pos_(Location::invalid()),
found_html_comment_(false) {
}
octal_message_(MessageTemplate::kNone),
found_html_comment_(false) {}
void Scanner::Initialize(Utf16CharacterStream* source) {
source_ = source;
......@@ -917,6 +916,7 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
// occur before the "use strict" directive.
if (c != '0' || i > 0) {
octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1);
octal_message_ = MessageTemplate::kStrictOctalEscape;
}
return x;
}
......@@ -1130,6 +1130,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
if (c0_ < '0' || '7' < c0_) {
// Octal literal finished.
octal_pos_ = Location(start_pos, source_pos());
octal_message_ = MessageTemplate::kStrictOctalLiteral;
break;
}
AddLiteralCharAdvance();
......
......@@ -274,7 +274,10 @@ class Scanner {
// Returns the location of the last seen octal literal.
Location octal_position() const { return octal_pos_; }
void clear_octal_position() { octal_pos_ = Location::invalid(); }
void clear_octal_position() {
octal_pos_ = Location::invalid();
octal_message_ = MessageTemplate::kNone;
}
// Returns the location of the last seen decimal literal with a leading zero.
Location decimal_with_leading_zero_position() const {
return decimal_with_leading_zero_pos_;
......@@ -282,6 +285,7 @@ class Scanner {
void clear_decimal_with_leading_zero_position() {
decimal_with_leading_zero_pos_ = Location::invalid();
}
MessageTemplate::Template octal_message() const { return octal_message_; }
// Returns the value of the last smi that was scanned.
uint32_t smi_value() const { return current_.smi_value_; }
......@@ -786,6 +790,7 @@ class Scanner {
// Last-seen positions of potentially problematic tokens.
Location octal_pos_;
Location decimal_with_leading_zero_pos_;
MessageTemplate::Template octal_message_;
// One Unicode character look-ahead; c0_ < 0 at the end of the input.
uc32 c0_;
......
*%(basename)s:32: SyntaxError: Octal literals are not allowed in strict mode.
*%(basename)s:32: SyntaxError: Octal escape sequences are not allowed in strict mode.
var x = "hello\040world";
^^
SyntaxError: Octal literals are not allowed in strict mode.
SyntaxError: Octal escape sequences are not allowed in strict mode.
*%(basename)s:33: SyntaxError: Octal literals are not allowed in strict mode.
*%(basename)s:33: SyntaxError: Octal escape sequences are not allowed in strict mode.
"use\040strict";
^^
SyntaxError: Octal literals are not allowed in strict mode.
SyntaxError: Octal escape sequences are not allowed in strict mode.
*%(basename)s:32: SyntaxError: Octal literals are not allowed in strict mode.
*%(basename)s:32: SyntaxError: Octal escape sequences are not allowed in strict mode.
"use\040strict";
^^
SyntaxError: Octal literals are not allowed in strict mode.
SyntaxError: Octal escape sequences are not allowed in strict mode.
......@@ -119,10 +119,10 @@ PASS 'use strict'; for(;;)continue missingLabel threw exception SyntaxError: Und
PASS (function (){'use strict'; for(;;)continue missingLabel}) threw exception SyntaxError: Undefined label 'missingLabel'.
PASS 'use strict'; 007; threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS (function (){'use strict'; 007;}) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS 'use strict'; '\007'; threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS (function (){'use strict'; '\007';}) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS '\007'; 'use strict'; threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS (function (){'\007'; 'use strict';}) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS 'use strict'; '\007'; threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS (function (){'use strict'; '\007';}) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS '\007'; 'use strict'; threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS (function (){'\007'; 'use strict';}) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS 'use strict'; delete aDeletableProperty; threw exception SyntaxError: Delete of an unqualified identifier in strict mode..
PASS (function (){'use strict'; delete aDeletableProperty;}) threw exception SyntaxError: Delete of an unqualified identifier in strict mode..
PASS 'use strict'; (function (){ delete someDeclaredGlobal;}) threw exception SyntaxError: Delete of an unqualified identifier in strict mode..
......
......@@ -29,37 +29,37 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) is strictResult
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
FAIL eval(stringLiteral) should throw an exception. Was 8.
PASS eval(stringLiteral) is nonStrictResult
FAIL eval(stringLiteral) should throw an exception. Was 9.
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal literals are not allowed in strict mode..
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
FAIL eval(stringLiteral) should throw an exception. Was 99.
PASS successfullyParsed is true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment