mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-26 18:20:28 +00:00
8047035: (function() "hello")() crashes in Lexer with jdk9
Reviewed-by: lagergren, hannesw, attila
This commit is contained in:
parent
ede81f43f7
commit
ff164ddca5
@ -680,7 +680,7 @@ loop:
|
||||
*/
|
||||
private FunctionNode program(final String scriptName, final boolean allowPropertyFunction) {
|
||||
// Make a pseudo-token for the script holding its start and length.
|
||||
final long functionToken = Token.toDesc(FUNCTION, getProgramStartPosition(token), source.getLength());
|
||||
final long functionToken = Token.toDesc(FUNCTION, Token.descPosition(Token.withDelimiter(token)), source.getLength());
|
||||
final int functionLine = line;
|
||||
// Set up the script to append elements.
|
||||
|
||||
@ -710,20 +710,6 @@ loop:
|
||||
return script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the start position of the program based on its first token. Normally returns the position of the token
|
||||
* itself, except in case of string tokens which report their position past their opening delimiter and thus need
|
||||
* to have one subtracted from their position.
|
||||
* @param firstToken the first token of the program
|
||||
* @return the start position of the program
|
||||
*/
|
||||
private static int getProgramStartPosition(final long firstToken) {
|
||||
final int start = Token.descPosition(firstToken);
|
||||
switch(Token.descType(firstToken)) {
|
||||
case STRING: case ESCSTRING: case EXECSTRING: return start - 1;
|
||||
default: return start;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Directive value or null if statement is not a directive.
|
||||
*
|
||||
|
||||
@ -60,6 +60,28 @@ public class Token {
|
||||
return (int)(token >>> 32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normally returns the token itself, except in case of string tokens
|
||||
* which report their position past their opening delimiter and thus
|
||||
* need to have position and length adjusted.
|
||||
*
|
||||
* @param token Token descriptor.
|
||||
* @return same or adjusted token.
|
||||
*/
|
||||
public static long withDelimiter(final long token) {
|
||||
final TokenType tokenType = Token.descType(token);
|
||||
switch(tokenType) {
|
||||
case STRING: case ESCSTRING: case EXECSTRING: {
|
||||
final int start = Token.descPosition(token) - 1;
|
||||
final int len = Token.descLength(token) + 2;
|
||||
return toDesc(tokenType, start, len);
|
||||
}
|
||||
default: {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract token length from a token descriptor.
|
||||
* @param token Token descriptor.
|
||||
|
||||
@ -294,7 +294,7 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData imp
|
||||
|
||||
private static long tokenFor(final FunctionNode fn) {
|
||||
final int position = Token.descPosition(fn.getFirstToken());
|
||||
final long lastToken = fn.getLastToken();
|
||||
final long lastToken = Token.withDelimiter(fn.getLastToken());
|
||||
// EOL uses length field to store the line number
|
||||
final int length = Token.descPosition(lastToken) - position + (Token.descType(lastToken) == TokenType.EOL ? 0 : Token.descLength(lastToken));
|
||||
|
||||
|
||||
37
nashorn/test/script/basic/JDK-8047035.js
Normal file
37
nashorn/test/script/basic/JDK-8047035.js
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JDK-8047035: (function() "hello")() crashes in Lexer with jdk9
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
// should not print ")" at the end
|
||||
print(function() "hello");
|
||||
print(function() '');
|
||||
|
||||
// The following should not crash inside lexer
|
||||
print((function() '')());
|
||||
print((function() "hello")());
|
||||
4
nashorn/test/script/basic/JDK-8047035.js.EXPECTED
Normal file
4
nashorn/test/script/basic/JDK-8047035.js.EXPECTED
Normal file
@ -0,0 +1,4 @@
|
||||
function() "hello"
|
||||
function() ''
|
||||
|
||||
hello
|
||||
Loading…
x
Reference in New Issue
Block a user