From c1204331581da35c7ea239f5990d9073cc51b40c Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Fri, 10 Jul 2015 22:27:38 +0300 Subject: [PATCH] Fix handling of EOF in insert_semicolon. JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com --- jerry-core/parser/js/parser.cpp | 12 +++++------- tests/jerry/insert-semicolon.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 tests/jerry/insert-semicolon.js diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index 9ac3f5453..c445d7d87 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -2536,15 +2536,13 @@ insert_semicolon (void) { // We cannot use tok, since we may use lexer_save_token skip_token (); - if (token_is (TOK_NEWLINE) || lexer_prev_token ().type == TOK_NEWLINE) + + bool is_new_line_occured = (token_is (TOK_NEWLINE) || lexer_prev_token ().type == TOK_NEWLINE); + bool is_close_brace_or_eof = (token_is (TOK_CLOSE_BRACE) || token_is (TOK_EOF)); + + if (is_new_line_occured || is_close_brace_or_eof) { lexer_save_token (tok); - return; - } - if (token_is (TOK_CLOSE_BRACE)) - { - lexer_save_token (tok); - return; } else if (!token_is (TOK_SEMICOLON)) { diff --git a/tests/jerry/insert-semicolon.js b/tests/jerry/insert-semicolon.js new file mode 100644 index 000000000..33829b069 --- /dev/null +++ b/tests/jerry/insert-semicolon.js @@ -0,0 +1,15 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var f = new Function ('return a');