Tue, 21 May 2013 10:17:09 -0300
8014827: readLine should accept a prompt as an argument
Reviewed-by: sundar, hannesw
Contributed-by: james.laskey@oracle.com
src/jdk/nashorn/internal/runtime/ScriptingFunctions.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Tue May 21 13:40:12 2013 +0200 1.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Tue May 21 10:17:09 2013 -0300 1.3 @@ -46,7 +46,7 @@ 1.4 public final class ScriptingFunctions { 1.5 1.6 /** Handle to implementation of {@link ScriptingFunctions#readLine} - Nashorn extension */ 1.7 - public static final MethodHandle READLINE = findOwnMH("readLine", Object.class, Object.class); 1.8 + public static final MethodHandle READLINE = findOwnMH("readLine", Object.class, Object.class, Object.class); 1.9 1.10 /** Handle to implementation of {@link ScriptingFunctions#readFully} - Nashorn extension */ 1.11 public static final MethodHandle READFULLY = findOwnMH("readFully", Object.class, Object.class, Object.class); 1.12 @@ -78,13 +78,17 @@ 1.13 * Nashorn extension: global.readLine (scripting-mode-only) 1.14 * Read one line of input from the standard input. 1.15 * 1.16 - * @param self self reference 1.17 + * @param self self reference 1.18 + * @param prompt String used as input prompt 1.19 * 1.20 * @return line that was read 1.21 * 1.22 * @throws IOException if an exception occurs 1.23 */ 1.24 - public static Object readLine(final Object self) throws IOException { 1.25 + public static Object readLine(final Object self, final Object prompt) throws IOException { 1.26 + if (prompt != UNDEFINED) { 1.27 + System.out.print(JSType.toString(prompt)); 1.28 + } 1.29 final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 1.30 return reader.readLine(); 1.31 }