Commit c19e57ee authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

Disallow \8 and \9 in strict mode and template literals

This reached consensus in the July 2020 TC39:
https://github.com/tc39/ecma262/pull/2054

Bug: v8:10769
Change-Id: Iecea1d9d9c9be5c2fbfb820aed2285719c4e6382
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2333350
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69206}
parent ccb6a3cf
......@@ -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") \
......
......@@ -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.
......
......@@ -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)
})();
......
......@@ -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
......
......@@ -25,7 +25,6 @@ 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
......@@ -33,9 +32,9 @@ 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 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
......@@ -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
......
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