< prev index next >
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptingFunctions.java
Print this page
*** 37,46 ****
--- 37,47 ----
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
+ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import jdk.nashorn.internal.objects.NativeArray;
/**
*** 53,63 ****
/** Handle to implementation of {@link ScriptingFunctions#readFully} - Nashorn extension */
public static final MethodHandle READFULLY = findOwnMH("readFully", Object.class, Object.class, Object.class);
/** Handle to implementation of {@link ScriptingFunctions#exec} - Nashorn extension */
! public static final MethodHandle EXEC = findOwnMH("exec", Object.class, Object.class, Object.class, Object.class, Object[].class);
/** EXEC name - special property used by $EXEC API. */
public static final String EXEC_NAME = "$EXEC";
/** OUT name - special property used by $EXEC API. */
--- 54,64 ----
/** Handle to implementation of {@link ScriptingFunctions#readFully} - Nashorn extension */
public static final MethodHandle READFULLY = findOwnMH("readFully", Object.class, Object.class, Object.class);
/** Handle to implementation of {@link ScriptingFunctions#exec} - Nashorn extension */
! public static final MethodHandle EXEC = findOwnMH("exec", Object.class, Object.class, Object[].class);
/** EXEC name - special property used by $EXEC API. */
public static final String EXEC_NAME = "$EXEC";
/** OUT name - special property used by $EXEC API. */
*** 125,149 ****
/**
* Nashorn extension: exec a string in a separate process.
*
* @param self self reference
! * @param string string to execute
! * @param input input
! * @param argv additional arguments, to be appended to {@code string}. Additional arguments can be passed as
* either one JavaScript array, whose elements will be converted to strings; or as a sequence of
* varargs, each of which will be converted to a string.
*
* @return output string from the request
*
* @throws IOException if any stream access fails
* @throws InterruptedException if execution is interrupted
*/
! public static Object exec(final Object self, final Object string, final Object input, final Object... argv) throws IOException, InterruptedException {
// Current global is need to fetch additional inputs and for additional results.
final ScriptObject global = Context.getGlobal();
!
// Assemble command line, process additional arguments.
final List<String> cmdLine = tokenizeString(JSType.toString(string));
final Object[] additionalArgs = argv.length == 1 && argv[0] instanceof NativeArray ?
((NativeArray) argv[0]).asObjectArray() :
argv;
--- 126,150 ----
/**
* Nashorn extension: exec a string in a separate process.
*
* @param self self reference
! * @param args string to execute, input and additional arguments, to be appended to {@code string}. Additional arguments can be passed as
* either one JavaScript array, whose elements will be converted to strings; or as a sequence of
* varargs, each of which will be converted to a string.
*
* @return output string from the request
*
* @throws IOException if any stream access fails
* @throws InterruptedException if execution is interrupted
*/
! public static Object exec(final Object self, final Object... args) throws IOException, InterruptedException {
// Current global is need to fetch additional inputs and for additional results.
final ScriptObject global = Context.getGlobal();
! final Object string = args.length > 0? args[0] : UNDEFINED;
! final Object input = args.length > 1? args[1] : UNDEFINED;
! final Object[] argv = (args.length > 2)? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.EMPTY_ARRAY;
// Assemble command line, process additional arguments.
final List<String> cmdLine = tokenizeString(JSType.toString(string));
final Object[] additionalArgs = argv.length == 1 && argv[0] instanceof NativeArray ?
((NativeArray) argv[0]).asObjectArray() :
argv;
< prev index next >