List of utility methods to do Javascript Mozilla Library
NativeArray | createNativeArray(int length, Scriptable scope) create Native Array NativeArray array = new NativeArray(length); ScriptRuntime.setObjectProtoAndParent(array, scope); return array; |
SecurityController | createSecurityController() create Security Controller return new PolicySecurityController(); |
Scriptable | ensureValid(Object obj) Return the object, or null if it is "not found" or undefined. if ((obj == null) || Scriptable.NOT_FOUND.equals(obj) || Context.getUndefinedValue().equals(obj)) { return null; return (Scriptable) obj; |
Context | enterContext() Associate a context with the current thread. Context cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_1_8);
return cx;
|
boolean | evaluateJSExpression(String expr, Context cx, Scriptable scope) evaluate JS Expression boolean evalResult = true; if ((null == expr) || (expr.isEmpty())) { return evalResult; try { Object result = cx.evaluateString(scope, expr, "policyExpression", 1, null); if (result != null && Context.toString(result).equals("true")) { evalResult = true; ... |
Object | from(Scriptable scriptable) from String className = scriptable.getClassName(); if (className.equals("Date")) { Object time = ScriptableObject.callMethod(scriptable, "getTime", null); if (time instanceof Number) return new Date(((Number) time).longValue()); } else if (className.equals("String")) { return scriptable.toString(); return null; |
Function | functionArg(Object[] args, int pos, boolean required) Return the argument at "pos" as a Function, and throw an exception if "required" and the list is too short. if (required) { ensureArg(args, pos); if (pos < args.length) { if (args[pos] instanceof Function) { return (Function) args[pos]; } else { if (required) { ... |
Object[] | getArray(Scriptable scope, NativeArray array) get Array Object[] v = new Object[(int) array.getLength()]; for (int i = 0; i < v.length; i++) v[i] = array.get(i, array); return v; |
Scriptable | getClassOrObjectProto(Scriptable scope, String className) Return a class prototype, or the object prototype if the class is not defined. Scriptable proto = ScriptableObject.getClassPrototype(scope, className); if (proto == null) { proto = ScriptableObject.getObjectPrototype(scope); return proto; |
boolean | getDirectColRefExpr(Node refNode, boolean mode) if the Node is row Node, return true assert (refNode.getType() == Token.GETPROP || refNode.getType() == Token.GETELEM); Node rowName = refNode.getFirstChild(); assert (rowName != null); if (rowName.getType() != Token.NAME) return false; String str = rowName.getString(); assert (str != null); if (mode && !str.equals(STRING_ROW)) ... |