本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptingFunctions类的典型用法代码示例。如果您正苦于以下问题:Java ScriptingFunctions类的具体用法?Java ScriptingFunctions怎么用?Java ScriptingFunctions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptingFunctions类属于jdk.nashorn.internal.runtime包,在下文中一共展示了ScriptingFunctions类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: execString
import jdk.nashorn.internal.runtime.ScriptingFunctions; //导入依赖的package包/类
/**
* Convert execString to a call to $EXEC.
*
* @param primaryToken Original string token.
* @return callNode to $EXEC.
*/
CallNode execString(final int primaryLine, final long primaryToken) {
// Synthesize an ident to call $EXEC.
final IdentNode execIdent = new IdentNode(primaryToken, finish, ScriptingFunctions.EXEC_NAME);
// Skip over EXECSTRING.
next();
// Set up argument list for call.
// Skip beginning of edit string expression.
expect(LBRACE);
// Add the following expression to arguments.
final List<Expression> arguments = Collections.singletonList(expression());
// Skip ending of edit string expression.
expect(RBRACE);
return new CallNode(primaryLine, primaryToken, finish, execIdent, arguments, false);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:Parser.java
示例2: execString
import jdk.nashorn.internal.runtime.ScriptingFunctions; //导入依赖的package包/类
/**
* Convert execString to a call to $EXEC.
*
* @param primaryToken Original string token.
* @return callNode to $EXEC.
*/
CallNode execString(final int primaryLine, final long primaryToken) {
// Synthesize an ident to call $EXEC.
final IdentNode execIdent = new IdentNode(primaryToken, finish, ScriptingFunctions.EXEC_NAME);
// Skip over EXECSTRING.
next();
// Set up argument list for call.
// Skip beginning of edit string expression.
expect(LBRACE);
// Add the following expression to arguments.
final List<Expression> arguments = Collections.singletonList(expression());
// Skip ending of edit string expression.
expect(RBRACE);
return new CallNode(primaryLine, primaryToken, finish, execIdent, arguments);
}
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:22,代码来源:Parser.java
示例3: initScripting
import jdk.nashorn.internal.runtime.ScriptingFunctions; //导入依赖的package包/类
private void initScripting(final ScriptEnvironment scriptEnv) {
Object value;
value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE);
addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value);
value = ScriptFunctionImpl.makeFunction("readFully", ScriptingFunctions.READFULLY);
addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value);
final String execName = ScriptingFunctions.EXEC_NAME;
value = ScriptFunctionImpl.makeFunction(execName, ScriptingFunctions.EXEC);
addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
// Nashorn extension: global.echo (scripting-mode-only)
// alias for "print"
value = get("print");
addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
// Nashorn extension: global.$OPTIONS (scripting-mode-only)
final ScriptObject options = newObject();
copyOptions(options, scriptEnv);
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
// Nashorn extension: global.$ENV (scripting-mode-only)
if (System.getSecurityManager() == null) {
// do not fill $ENV if we have a security manager around
// Retrieve current state of ENV variables.
final ScriptObject env = newObject();
env.putAll(System.getenv(), scriptEnv._strict);
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
} else {
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
// add other special properties for exec support
addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:Global.java
示例4: input
import jdk.nashorn.internal.runtime.ScriptingFunctions; //导入依赖的package包/类
/**
* Nashorn extension: global.input (shell-interactive-mode-only)
* Read one or more lines of input from the standard input till the
* given end marker is seen in standard input.
*
* @param self self reference
* @param endMarker String used as end marker for input
* @param prompt String used as input prompt
*
* @return line that was read
*
* @throws IOException if an exception occurs
*/
public static Object input(final Object self, final Object endMarker, final Object prompt) throws IOException {
final String endMarkerStr = (endMarker != UNDEFINED)? JSType.toString(endMarker) : "";
final String promptStr = (prompt != UNDEFINED)? JSType.toString(prompt) : ">> ";
final StringBuilder buf = new StringBuilder();
while (true) {
final String line = ScriptingFunctions.readLine(promptStr);
if (line == null || line.equals(endMarkerStr)) {
break;
}
buf.append(line);
buf.append('\n');
}
return buf.toString();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ShellFunctions.java
示例5: initScripting
import jdk.nashorn.internal.runtime.ScriptingFunctions; //导入依赖的package包/类
private void initScripting(final ScriptEnvironment scriptEnv) {
ScriptObject value;
value = ScriptFunction.createBuiltin("readLine", ScriptingFunctions.READLINE);
addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value);
value = ScriptFunction.createBuiltin("readFully", ScriptingFunctions.READFULLY);
addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value);
final String execName = ScriptingFunctions.EXEC_NAME;
value = ScriptFunction.createBuiltin(execName, ScriptingFunctions.EXEC);
addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
// Nashorn extension: global.echo (scripting-mode-only)
// alias for "print"
value = (ScriptObject)get("print");
addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
// Nashorn extension: global.$OPTIONS (scripting-mode-only)
final ScriptObject options = newObject();
copyOptions(options, scriptEnv);
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
// Nashorn extension: global.$ENV (scripting-mode-only)
final ScriptObject env = newObject();
if (System.getSecurityManager() == null) {
// do not fill $ENV if we have a security manager around
// Retrieve current state of ENV variables.
env.putAll(System.getenv(), scriptEnv._strict);
// Set the PWD variable to a value that is guaranteed to be understood
// by the underlying platform.
env.put(ScriptingFunctions.PWD_NAME, System.getProperty("user.dir"), scriptEnv._strict);
}
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
// add other special properties for exec support
addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
开发者ID:campolake,项目名称:openjdk9,代码行数:41,代码来源:Global.java
示例6: initScripting
import jdk.nashorn.internal.runtime.ScriptingFunctions; //导入依赖的package包/类
private void initScripting(final ScriptEnvironment scriptEnv) {
Object value;
value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE);
addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value);
value = ScriptFunctionImpl.makeFunction("readFully", ScriptingFunctions.READFULLY);
addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value);
final String execName = ScriptingFunctions.EXEC_NAME;
value = ScriptFunctionImpl.makeFunction(execName, ScriptingFunctions.EXEC);
addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
// Nashorn extension: global.echo (scripting-mode-only)
// alias for "print"
value = get("print");
addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
// Nashorn extension: global.$OPTIONS (scripting-mode-only)
final ScriptObject options = newObject();
copyOptions(options, scriptEnv);
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
// Nashorn extension: global.$ENV (scripting-mode-only)
if (System.getSecurityManager() == null) {
// do not fill $ENV if we have a security manager around
// Retrieve current state of ENV variables.
final ScriptObject env = newObject();
env.putAll(System.getenv(), scriptEnv._strict);
// Some platforms, e.g., Windows, do not define the PWD environment
// variable, so that the $ENV.PWD property needs to be explicitly
// set.
if (!env.containsKey(ScriptingFunctions.PWD_NAME)) {
env.put(ScriptingFunctions.PWD_NAME, System.getProperty("user.dir"), scriptEnv._strict);
}
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
} else {
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
// add other special properties for exec support
addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
开发者ID:malaporte,项目名称:kaziranga,代码行数:47,代码来源:Global.java
示例7: initScripting
import jdk.nashorn.internal.runtime.ScriptingFunctions; //导入依赖的package包/类
private void initScripting(final ScriptEnvironment scriptEnv) {
ScriptObject value;
value = ScriptFunction.createBuiltin("readLine", ScriptingFunctions.READLINE);
addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value);
value = ScriptFunction.createBuiltin("readFully", ScriptingFunctions.READFULLY);
addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value);
final String execName = ScriptingFunctions.EXEC_NAME;
value = ScriptFunction.createBuiltin(execName, ScriptingFunctions.EXEC);
value.addOwnProperty(ScriptingFunctions.THROW_ON_ERROR_NAME, Attribute.NOT_ENUMERABLE, false);
addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
// Nashorn extension: global.echo (scripting-mode-only)
// alias for "print"
value = (ScriptObject)get("print");
addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
// Nashorn extension: global.$OPTIONS (scripting-mode-only)
final ScriptObject options = newObject();
copyOptions(options, scriptEnv);
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
// Nashorn extension: global.$ENV (scripting-mode-only)
if (System.getSecurityManager() == null) {
// do not fill $ENV if we have a security manager around
// Retrieve current state of ENV variables.
final ScriptObject env = newObject();
env.putAll(System.getenv(), scriptEnv._strict);
// Some platforms, e.g., Windows, do not define the PWD environment
// variable, so that the $ENV.PWD property needs to be explicitly
// set.
if (!env.containsKey(ScriptingFunctions.PWD_NAME)) {
env.put(ScriptingFunctions.PWD_NAME, System.getProperty("user.dir"), scriptEnv._strict);
}
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
} else {
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
// add other special properties for exec support
addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:49,代码来源:Global.java
示例8: preprocessArgs
import jdk.nashorn.internal.runtime.ScriptingFunctions; //导入依赖的package包/类
/**
* Preprocess the command line arguments passed in by the shell. This method checks, for the first non-option
* argument, whether the file denoted by it begins with a shebang line. If so, it is assumed that execution in
* shebang mode is intended. The consequence of this is that the identified script file will be treated as the
* <em>only</em> script file, and all subsequent arguments will be regarded as arguments to the script.
* <p>
* This method canonicalizes the command line arguments to the form {@code <options> <script> -- <arguments>} if a
* shebang script is identified. On platforms that pass shebang arguments as single strings, the shebang arguments
* will be broken down into single arguments; whitespace is used as separator.
* <p>
* Shebang mode is entered regardless of whether the script is actually run directly from the shell, or indirectly
* via the {@code jjs} executable. It is the user's / script author's responsibility to ensure that the arguments
* given on the shebang line do not lead to a malformed argument sequence. In particular, the shebang arguments
* should not contain any whitespace for purposes other than separating arguments, as the different platforms deal
* with whitespace in different and incompatible ways.
* <p>
* @implNote Example:<ul>
* <li>Shebang line in {@code script.js}: {@code #!/path/to/jjs --language=es6}</li>
* <li>Command line: {@code ./script.js arg2}</li>
* <li>{@code args} array passed to Nashorn: {@code --language=es6,./script.js,arg}</li>
* <li>Required canonicalized arguments array: {@code --language=es6,./script.js,--,arg2}</li>
* </ul>
*
* @param args the command line arguments as passed into Nashorn.
* @return the passed and possibly canonicalized argument list
*/
private static String[] preprocessArgs(final String[] args) {
if (args.length == 0) {
return args;
}
final List<String> processedArgs = new ArrayList<>();
processedArgs.addAll(Arrays.asList(args));
// Nashorn supports passing multiple shebang arguments. On platforms that pass anything following the
// shebang interpreter notice as one argument, the first element of the argument array needs to be special-cased
// as it might actually contain several arguments. Mac OS X splits shebang arguments, other platforms don't.
// This special handling is also only necessary if the first argument actually starts with an option.
if (args[0].startsWith("-") && !System.getProperty("os.name", "generic").startsWith("Mac OS X")) {
processedArgs.addAll(0, ScriptingFunctions.tokenizeString(processedArgs.remove(0)));
}
int shebangFilePos = -1; // -1 signifies "none found"
// identify a shebang file and its position in the arguments array (if any)
for (int i = 0; i < processedArgs.size(); ++i) {
final String a = processedArgs.get(i);
if (!a.startsWith("-")) {
final Path p = Paths.get(a);
String l = "";
try (final BufferedReader r = Files.newBufferedReader(p)) {
l = r.readLine();
} catch (IOException ioe) {
// ignore
}
if (l.startsWith("#!")) {
shebangFilePos = i;
}
// We're only checking the first non-option argument. If it's not a shebang file, we're in normal
// execution mode.
break;
}
}
if (shebangFilePos != -1) {
// Insert the argument separator after the shebang script file.
processedArgs.add(shebangFilePos + 1, "--");
}
return processedArgs.toArray(new String[0]);
}
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:69,代码来源:Shell.java
注:本文中的jdk.nashorn.internal.runtime.ScriptingFunctions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论