/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Implementation of <code>ScriptEngine</code> using the Mozilla Rhino
* interpreter.
*
* @author Mike Grogan
* @author A. Sundararajan
* @since 1.6
*/
implements Invocable, Compilable {
private static final boolean DEBUG = false;
/* Scope where standard JavaScript objects and our
* extensions to it are stored. Note that these are not
* user defined engine level global variables. These are
* variables have to be there on all compliant ECMAScript
* scopes. We put these standard objects in this top level.
*/
/* map used to store indexed properties in engine scope
* refer to comment on 'indexedProps' in ExternalScriptable.java.
*/
static {
/**
* Create new Context instance to be associated with the current thread.
*/
protected Context makeContext() {
return cx;
}
/**
* Execute top call to script or function. When the runtime is about to
* execute a script or function that will create the first stack frame
* with scriptable code, it calls this method to perform the real call.
* In this way execution of any script happens inside this function.
*/
if (globalProto instanceof RhinoTopLevel) {
}
}
}, accCtxt);
} else {
}
}
}
});
}
private static int getLanguageVersion() {
int version;
} else {
}
return version;
}
private static int getOptimizationLevel() {
int optLevel = -1;
// disable optimizer under security manager, for now.
}
return optLevel;
}
/**
* Creates a new instance of RhinoScriptEngine
*/
public RhinoScriptEngine() {
try {
} catch (AccessControlException ace) {
}
}
try {
} finally {
}
//construct object used to implement getInterface
implementor = new InterfaceImplementor(this) {
try {
}
// ignore methods of java.lang.Object class
continue;
}
return false;
}
}
return true;
} finally {
}
}
throws ScriptException {
return null;
} else {
}
}
};
}
throws ScriptException {
try {
} catch (RhinoException re) {
if (re instanceof JavaScriptException) {
} else {
}
throw se;
} catch (IOException ee) {
throw new ScriptException(ee);
} finally {
}
return unwrapReturnValue(ret);
}
throw new NullPointerException("null script");
}
}
return factory;
} else {
return new RhinoScriptEngineFactory();
}
}
return new SimpleBindings();
}
//Invocable methods
throws ScriptException, NoSuchMethodException {
}
throws ScriptException, NoSuchMethodException {
throw new IllegalArgumentException("script object can not be null");
}
}
throws ScriptException, NoSuchMethodException {
try {
throw new NullPointerException("method name is null");
}
}
}
scope = engineScope;
}
return unwrapReturnValue(result);
} catch (RhinoException re) {
throw se;
} finally {
}
}
try {
} catch (ScriptException e) {
return null;
}
}
throw new IllegalArgumentException("script object can not be null");
}
try {
} catch (ScriptException e) {
return null;
}
}
"function print(str, newline) { \n" +
" if (typeof(str) == 'undefined') { \n" +
" str = 'undefined'; \n" +
" } else if (str == null) { \n" +
" str = 'null'; \n" +
" } \n" +
" var out = context.getWriter(); \n" +
" if (!(out instanceof java.io.PrintWriter))\n" +
" out = new java.io.PrintWriter(out); \n" +
" out.print(String(str)); \n" +
" if (newline) out.print('\\n'); \n" +
" out.flush(); \n" +
"}\n" +
"function println(str) { \n" +
" print(str, true); \n" +
"}";
throw new NullPointerException("null script context");
}
// we create a scope for the given ScriptContext
// Set the prototype of newScope to be 'topLevel' so that
// JavaScript standard objects are visible from the scope.
// define "context" variable in the new scope
// define "print", "println" functions in the new scope
try {
} finally {
}
return newScope;
}
//Compilable methods
}
try {
fileName = "<Unknown Source>";
}
} catch (Exception e) {
if (DEBUG) e.printStackTrace();
throw new ScriptException(e);
} finally {
}
return ret;
}
//package-private helpers
// call this always so that initializer of this class runs
// and initializes custom wrap factory and class shutter.
}
}
return accCtxt;
}
}
}
return res;
}
}
}
/*
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("No file specified");
return;
}
InputStreamReader r = new InputStreamReader(new FileInputStream(args[0]));
ScriptEngine engine = new RhinoScriptEngine();
engine.put("x", "y");
engine.put(ScriptEngine.FILENAME, args[0]);
engine.eval(r);
System.out.println(engine.get("x"));
}
*/
}