src/jdk/nashorn/internal/parser/Parser.java
Print this page
*** 678,688 ****
*
* Parse the top level script.
*/
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 int functionLine = line;
// Set up the script to append elements.
FunctionNode script = newFunctionNode(
functionToken,
--- 678,688 ----
*
* Parse the top level script.
*/
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, Token.descPosition(Token.withDelimiter(token)), source.getLength());
final int functionLine = line;
// Set up the script to append elements.
FunctionNode script = newFunctionNode(
functionToken,
*** 709,732 ****
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.
*
* @param stmt Statement to be checked
* @return Directive value if the given statement is a directive
*/
--- 709,718 ----