Java Utililty Methods Javascript Mozilla Library

List of utility methods to do Javascript Mozilla Library

Description

The list of methods to do Javascript Mozilla Library are organized into topic(s).

Method

ListtoList(AstNode... nodes)
to List
List<AstNode> list = new ArrayList<AstNode>();
for (AstNode node : nodes) {
    list.add(node);
return list;
ScriptabletoRegExp(String source, String optionsString)
to Reg Exp
Context context = Context.getCurrentContext();
Scriptable scope = ScriptRuntime.getTopCallScope(context);
return context.newObject(scope, "RegExp", new Object[] { source, optionsString });
StringtoString(Object val)
to String
return ScriptRuntime.toString(val);
voidtrace(Object object)
trace
trace(object, "");
voidtraceHelper(Function function, Object... args)
Get a snapshot of the current JavaScript evaluation state by creating an Error object and invoke the function on it passing along any arguments.
Context cx = Context.getCurrentContext();
Scriptable scope = ScriptableObject.getTopLevelScope(function);
EcmaError error = ScriptRuntime.constructError("Trace", "");
WrapFactory wrapFactory = cx.getWrapFactory();
Scriptable thisObj = wrapFactory.wrapAsJavaObject(cx, scope, error, null);
for (int i = 0; i < args.length; i++) {
    args[i] = wrapFactory.wrap(cx, scope, args[i], null);
function.call(cx, scope, thisObj, args);
Objectunwrap(Object obj)
Unwrap a Rhino object (getting the raw java object) and convert undefined to null
if (obj instanceof Wrapper) {
    obj = ((Wrapper) obj).unwrap();
} else if (obj == Undefined.instance) {
    obj = null;
return obj;
ListunwrapNativeArray(final NativeArray na)
unwrap Native Array
return new ArrayList<Object>() {
        for (int i = 0; i < na.getLength(); ++i) {
            add(unwrapNative(na.get(i, null)));
};
ObjectwrapJavaObj(Object javaObj, Scriptable scope)
Wrap java object to javascript object
return Context.javaToJS(javaObj, scope);