∟Global Properties and Functions Provided by "jrunscript"
This section provides a quick description of all extra global properties and functions provided by the 'jrunscript' host environment.
In addition to global properties and functions defined in the ECMAScript specification,
each JavaScript implementation may add its own global properties and functions
into the invisible "Global" object.
Here is a tutorial example script that lists all global properties and functions provided
by the JavaScript implemenation:
// Global_Object_Properties_jrunscript.html
// Copyright (c) 2008 by Dr. Herong Yang, http://www.herongyang.com/
println("\nList of global properties:");
for (item in this) {
println(" "+item+": "+this[item]);
}
If you run this script with "jrunscript", you will get a list of 59 properties and functions.
Statement bodies of global functions are also listed in the output.
Here are some exmaples:
List of global properties:
...
javax.script.filename: Global_Object_Properties_jrunscript.js
months: Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
cp:
function cp(from, to) {
if (from == to) {
println("file " + from + " cannot be copied onto itself!");
return;
}
var inp = inStream(from);
var out = outStream(to);
var binp = new BufferedInputStream(inp);
var bout = new BufferedOutputStream(out);
var buff = javaByteArray(1024);
var len;
while ((len = binp.read(buff)) > 0) {
bout.write(buff, 0, len);
}
bout.flush();
streamClose(inp);
streamClose(out);
}
read:
function read(prompt, multiline) {
if (!prompt) {
prompt = ">";
}
var inp = java.lang.System["in"];
var reader = new BufferedReader(new InputStreamReader(inp));
if (multiline) {
var line = "";
while (true) {
java.lang.System.err.print(prompt);
java.lang.System.err.flush();
var tmp = reader.readLine();
if (tmp == "" || tmp == null) {
break;
}
line += tmp + "\n";
}
return line;
} else {
java.lang.System.err.print(prompt);
java.lang.System.err.flush();
return reader.readLine();
}
}
print:
function print(str, newline) {
if (typeof (str) == "undefined") {
str = "undefined";
} else {
if (str == null) {
str = "null";
}
}
var out = context.getWriter();
out.print(String(str));
if (newline) {
out.print("\n");
}
out.flush();
}
println:
function println(str) {
print(str, true);
}
...
Now we know how the "println()" is implemented in "jrunscript".