Fri, 13 May 2016 18:38:15 +0200
8156714: Parsing issue with automatic semicolon insertion
Reviewed-by: jlaskey, sundar
1.1 --- a/src/jdk/nashorn/internal/parser/AbstractParser.java Mon Feb 29 09:49:46 2016 +0100 1.2 +++ b/src/jdk/nashorn/internal/parser/AbstractParser.java Fri May 13 18:38:15 2016 +0200 1.3 @@ -200,8 +200,10 @@ 1.4 * @return tokenType of next token. 1.5 */ 1.6 private TokenType nextToken() { 1.7 - // Capture last token tokenType. 1.8 - last = type; 1.9 + // Capture last token type, but ignore comments (which are irrelevant for the purpose of newline detection). 1.10 + if (type != COMMENT) { 1.11 + last = type; 1.12 + } 1.13 if (type != EOF) { 1.14 1.15 // Set up next token.
2.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Mon Feb 29 09:49:46 2016 +0100 2.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Fri May 13 18:38:15 2016 +0200 2.3 @@ -1135,7 +1135,7 @@ 2.4 2.5 /** 2.6 * ExpressionStatement : 2.7 - * Expression ; // [lookahead ~( or function )] 2.8 + * Expression ; // [lookahead ~({ or function )] 2.9 * 2.10 * See 12.4 2.11 *
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/script/basic/JDK-8156714.js Fri May 13 18:38:15 2016 +0200 3.3 @@ -0,0 +1,50 @@ 3.4 +/* 3.5 + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/** 3.28 + * JDK-8156714: Parsing issue with automatic semicolon insertion 3.29 + * 3.30 + * @test 3.31 + * @run 3.32 + */ 3.33 + 3.34 +a = function() { 3.35 +} 3.36 + 3.37 +/* */ function b() { 3.38 +} 3.39 + 3.40 +c = function() { 3.41 +} /* 3.42 + 3.43 +*/ function d() { 3.44 +} 3.45 + 3.46 +try { 3.47 + eval("x = function() {} /* */ function y() {}"); 3.48 + throw new Error("Error expected"); 3.49 +} catch (e) { 3.50 + if (!(e instanceof SyntaxError)) { 3.51 + throw new Error("Unexpected error: " + e); 3.52 + } 3.53 +}