List of utility methods to do Javascript Mozilla Library
List | toList(AstNode... nodes) to List List<AstNode> list = new ArrayList<AstNode>(); for (AstNode node : nodes) { list.add(node); return list; |
Scriptable | toRegExp(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 }); |
String | toString(Object val) to String return ScriptRuntime.toString(val); |
void | trace(Object object) trace trace(object, "");
|
void | traceHelper(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); |
Object | unwrap(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; |
List | unwrapNativeArray(final NativeArray na) unwrap Native Array return new ArrayList<Object>() { for (int i = 0; i < na.getLength(); ++i) { add(unwrapNative(na.get(i, null))); }; |
Object | wrapJavaObj(Object javaObj, Scriptable scope) Wrap java object to javascript object return Context.javaToJS(javaObj, scope);
|