Commit 92db073f authored by Mathias Bynens's avatar Mathias Bynens Committed by Commit Bot

[parser] Improve error message for unclosed function bodies

This patch changes the output from:

  function fn() {
                ^
  SyntaxError: Unexpected end of input

to:

  function fn() {
                ^
  SyntaxError: missing '}' after function body

Bug: v8:6513, v8:7321
Change-Id: I4ca8a40fa0be246da2a3ff776b3fb3c87b4ba4e0
Also-By: gsathya@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/c/1367448
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58116}
parent f3cfbd35
...@@ -113,6 +113,7 @@ namespace internal { ...@@ -113,6 +113,7 @@ namespace internal {
T(MethodInvokedOnNullOrUndefined, \ T(MethodInvokedOnNullOrUndefined, \
"Method invoked on undefined or null value.") \ "Method invoked on undefined or null value.") \
T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \ T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \
T(MissingBraceAfterFunctionBody, "missing '}' after function body") \
T(NoAccess, "no access") \ T(NoAccess, "no access") \
T(NonCallableInInstanceOfCheck, \ T(NonCallableInInstanceOfCheck, \
"Right-hand side of 'instanceof' is not callable") \ "Right-hand side of 'instanceof' is not callable") \
......
...@@ -4564,6 +4564,12 @@ ParserBase<Impl>::ParseStatementList(StatementListT* body, ...@@ -4564,6 +4564,12 @@ ParserBase<Impl>::ParseStatementList(StatementListT* body,
} }
while (peek() != end_token) { while (peek() != end_token) {
if (peek() == Token::EOS) {
DCHECK_EQ(end_token, Token::RBRACE);
ReportMessage(MessageTemplate::kMissingBraceAfterFunctionBody);
return kLazyParsingComplete;
}
StatementT stat = ParseStatementListItem(); StatementT stat = ParseStatementListItem();
if (impl()->IsNull(stat)) return kLazyParsingComplete; if (impl()->IsNull(stat)) return kLazyParsingComplete;
if (stat->IsEmptyStatement()) continue; if (stat->IsEmptyStatement()) continue;
......
...@@ -362,7 +362,7 @@ bytecodes: [ ...@@ -362,7 +362,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(18), B(Star), R(18),
B(LdaConstant), U8(14), B(LdaConstant), U8(14),
B(Star), R(19), B(Star), R(19),
......
...@@ -119,7 +119,7 @@ bytecodes: [ ...@@ -119,7 +119,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(15), B(Star), R(15),
B(LdaConstant), U8(11), B(LdaConstant), U8(11),
B(Star), R(16), B(Star), R(16),
...@@ -336,7 +336,7 @@ bytecodes: [ ...@@ -336,7 +336,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(15), B(Star), R(15),
B(LdaConstant), U8(11), B(LdaConstant), U8(11),
B(Star), R(16), B(Star), R(16),
...@@ -571,7 +571,7 @@ bytecodes: [ ...@@ -571,7 +571,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(15), B(Star), R(15),
B(LdaConstant), U8(11), B(LdaConstant), U8(11),
B(Star), R(16), B(Star), R(16),
...@@ -771,7 +771,7 @@ bytecodes: [ ...@@ -771,7 +771,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(13), B(Star), R(13),
B(LdaConstant), U8(9), B(LdaConstant), U8(9),
B(Star), R(14), B(Star), R(14),
......
...@@ -85,7 +85,7 @@ bytecodes: [ ...@@ -85,7 +85,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(12), B(Star), R(12),
B(LdaConstant), U8(7), B(LdaConstant), U8(7),
B(Star), R(13), B(Star), R(13),
...@@ -217,7 +217,7 @@ bytecodes: [ ...@@ -217,7 +217,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(13), B(Star), R(13),
B(LdaConstant), U8(7), B(LdaConstant), U8(7),
B(Star), R(14), B(Star), R(14),
...@@ -361,7 +361,7 @@ bytecodes: [ ...@@ -361,7 +361,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(12), B(Star), R(12),
B(LdaConstant), U8(7), B(LdaConstant), U8(7),
B(Star), R(13), B(Star), R(13),
...@@ -495,7 +495,7 @@ bytecodes: [ ...@@ -495,7 +495,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(11), B(Star), R(11),
B(LdaConstant), U8(9), B(LdaConstant), U8(9),
B(Star), R(12), B(Star), R(12),
......
...@@ -89,7 +89,7 @@ bytecodes: [ ...@@ -89,7 +89,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(14), B(Star), R(14),
B(LdaConstant), U8(6), B(LdaConstant), U8(6),
B(Star), R(15), B(Star), R(15),
...@@ -256,7 +256,7 @@ bytecodes: [ ...@@ -256,7 +256,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(14), B(Star), R(14),
B(LdaConstant), U8(11), B(LdaConstant), U8(11),
B(Star), R(15), B(Star), R(15),
...@@ -401,7 +401,7 @@ bytecodes: [ ...@@ -401,7 +401,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(12), B(Star), R(12),
B(LdaConstant), U8(8), B(LdaConstant), U8(8),
B(Star), R(13), B(Star), R(13),
...@@ -495,7 +495,7 @@ bytecodes: [ ...@@ -495,7 +495,7 @@ bytecodes: [
B(JumpIfUndefined), U8(6), B(JumpIfUndefined), U8(6),
B(Ldar), R(6), B(Ldar), R(6),
B(JumpIfNotNull), U8(16), B(JumpIfNotNull), U8(16),
B(LdaSmi), I8(81), B(LdaSmi), I8(82),
B(Star), R(18), B(Star), R(18),
B(LdaConstant), U8(4), B(LdaConstant), U8(4),
B(Star), R(19), B(Star), R(19),
...@@ -550,7 +550,7 @@ bytecodes: [ ...@@ -550,7 +550,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(17), B(Star), R(17),
B(LdaConstant), U8(8), B(LdaConstant), U8(8),
B(Star), R(18), B(Star), R(18),
...@@ -697,7 +697,7 @@ bytecodes: [ ...@@ -697,7 +697,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(15), B(Star), R(15),
B(LdaConstant), U8(9), B(LdaConstant), U8(9),
B(Star), R(16), B(Star), R(16),
...@@ -859,7 +859,7 @@ bytecodes: [ ...@@ -859,7 +859,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(14), B(Star), R(14),
B(LdaConstant), U8(12), B(LdaConstant), U8(12),
B(Star), R(15), B(Star), R(15),
...@@ -1008,7 +1008,7 @@ bytecodes: [ ...@@ -1008,7 +1008,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(16), B(Star), R(16),
B(LdaConstant), U8(6), B(LdaConstant), U8(6),
B(Star), R(17), B(Star), R(17),
...@@ -1184,7 +1184,7 @@ bytecodes: [ ...@@ -1184,7 +1184,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(15), B(Star), R(15),
B(LdaConstant), U8(7), B(LdaConstant), U8(7),
B(Star), R(16), B(Star), R(16),
......
...@@ -203,7 +203,7 @@ bytecodes: [ ...@@ -203,7 +203,7 @@ bytecodes: [
B(TestTypeOf), U8(6), B(TestTypeOf), U8(6),
B(JumpIfFalse), U8(4), B(JumpIfFalse), U8(4),
B(Jump), U8(18), B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(154), B(Wide), B(LdaSmi), I16(155),
B(Star), R(14), B(Star), R(14),
B(LdaConstant), U8(13), B(LdaConstant), U8(13),
B(Star), R(15), B(Star), R(15),
......
...@@ -228,7 +228,7 @@ bytecodes: [ ...@@ -228,7 +228,7 @@ bytecodes: [
B(JumpIfUndefined), U8(6), B(JumpIfUndefined), U8(6),
B(Ldar), R(3), B(Ldar), R(3),
B(JumpIfNotNull), U8(16), B(JumpIfNotNull), U8(16),
B(LdaSmi), I8(81), B(LdaSmi), I8(82),
B(Star), R(4), B(Star), R(4),
B(LdaConstant), U8(1), B(LdaConstant), U8(1),
B(Star), R(5), B(Star), R(5),
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const fn = () => {
const x = 42;
*%(basename)s:6: SyntaxError: missing '}' after function body
const x = 42;
^
SyntaxError: missing '}' after function body
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function fn() {
const x = 42;
*%(basename)s:6: SyntaxError: missing '}' after function body
const x = 42;
^
SyntaxError: missing '}' after function body
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
if (true) {
*%(basename)s:6: SyntaxError: Unexpected end of input
SyntaxError: Unexpected end of input
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const { a: b } = {
*%(basename)s:6: SyntaxError: Unexpected end of input
SyntaxError: Unexpected end of input
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
if (true
*%(basename)s:6: SyntaxError: Unexpected end of input
SyntaxError: Unexpected end of input
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function fn() {
const x = 42;
}()
*%(basename)s:8: SyntaxError: Unexpected end of input
SyntaxError: Unexpected end of input
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