Skip to content

Commit

Permalink
Disallow \8 and \9 in strict mode and template literals
Browse files Browse the repository at this point in the history
This reached consensus in the July 2020 TC39:
tc39/ecma262#2054

Bug: v8:10769
Change-Id: Iecea1d9d9c9be5c2fbfb820aed2285719c4e6382
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2333350
Commit-Queue: Shu-yu Guo <[email protected]>
Reviewed-by: Marja Hölttä <[email protected]>
Reviewed-by: Leszek Swirski <[email protected]>
Cr-Commit-Position: refs/heads/master@{#69206}
  • Loading branch information
syg authored and Commit Bot committed Aug 3, 2020
1 parent ccb6a3c commit c19e57e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/common/message-template.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,11 @@ namespace internal {
"Decimals with leading zeros are not allowed in strict mode.") \
T(StrictOctalEscape, \
"Octal escape sequences are not allowed in strict mode.") \
T(Strict8Or9Escape, "\\8 and \\9 are not allowed in strict mode.") \
T(StrictWith, "Strict mode code may not include a with statement") \
T(TemplateOctalLiteral, \
"Octal escape sequences are not allowed in template strings.") \
T(Template8Or9Escape, "\\8 and \\9 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") \
Expand Down
22 changes: 15 additions & 7 deletions src/parsing/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,24 @@ bool Scanner::ScanEscape() {
if (IsInvalid(c)) return false;
break;
}
case '0': // Fall through.
case '1': // fall through
case '2': // fall through
case '3': // fall through
case '4': // fall through
case '5': // fall through
case '6': // fall through
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
c = ScanOctalEscape<capture_raw>(c, 2);
break;
case '8':
case '9':
// '\8' and '\9' are disallowed in strict mode.
// Re-use the octal error state to propagate the error.
octal_pos_ = Location(source_pos() - 2, source_pos() - 1);
octal_message_ = capture_raw ? MessageTemplate::kTemplate8Or9Escape
: MessageTemplate::kStrict8Or9Escape;
break;
}

// Other escaped characters are interpreted as their non-escaped version.
Expand Down
6 changes: 3 additions & 3 deletions test/mjsunit/es6/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ var obj = {
})();


(function testValidNumericEscapes() {
assertEquals("8", `\8`);
assertEquals("9", `\9`);
(function testInvalidNumericEscapes() {
assertThrows(function() { eval("`\\8`"); }, SyntaxError)
assertThrows(function() { eval("`\\9`"); }, SyntaxError)
})();


Expand Down
4 changes: 0 additions & 4 deletions test/test262/test262.status
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,6 @@
'built-ins/Atomics/xor/bigint/non-shared-bufferdata': [FAIL],
'built-ins/Atomics/xor/non-shared-bufferdata': [FAIL],

# https://bugs.chromium.org/p/v8/issues/detail?id=10769
'language/expressions/template-literal/invalid-legacy-octal-escape-sequence-8': [FAIL],
'language/literals/string/legacy-non-octal-escape-sequence-8-strict': [FAIL],

######################## NEEDS INVESTIGATION ###########################

# https://bugs.chromium.org/p/v8/issues/detail?id=7833
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ Test numeric escapes in string literals - https://bugs.webkit.org/show_bug.cgi?i

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 escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
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) threw exception SyntaxError: \8 and \9 are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
FAIL eval(stringLiteral) should throw an exception. Was 9.
PASS eval(stringLiteral) threw exception SyntaxError: \8 and \9 are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are not allowed in strict mode..
PASS eval(stringLiteral) is nonStrictResult
Expand All @@ -61,7 +60,7 @@ PASS eval(stringLiteral) threw exception SyntaxError: Octal escape sequences are
PASS eval(stringLiteral) is nonStrictResult
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 eval(stringLiteral) threw exception SyntaxError: \8 and \9 are not allowed in strict mode..
PASS successfullyParsed is true

TEST COMPLETE
Expand Down

0 comments on commit c19e57e

Please sign in to comment.